标签: spring-security

Spring安全性:css在Web浏览器中丢失或未加载

我正在使用spring security 3.0.在spring-security.xml中,显示登录页面时出现1个问题.Web浏览器中没有加载或丢失CSS的login.jsp.所以请解决这个问题..任何帮助,我感谢你.

我的spring-security.xml代码如下:

     <beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">

  <http auto-config="true"  use-expressions="true">
    <intercept-url pattern="/login.html" access="permitAll" />
     <intercept-url pattern="/logout" access="permitAll" />

   <intercept-url pattern="/accessdenied" access="permitAll"  />
    <intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
   <form-login login-page="/login.html" default-target-url="/firstwelcome.html"  />
    <logout logout-success-url="/logout" /> 
  </http>


  <authentication-manager  alias="authenticationManager">  
      <authentication-provider>  
        <password-encoder hash="md5"/>
        <jdbc-user-service data-source-ref="dataSource"
              users-by-username-query="
              SELECT strUSERNAME, strPASSWORD, CASE blENABLED WHEN 1 THEN 'true' ELSE             'false' END 'ENABLED' 
      FROM TBLUSERS 
      WHERE strUSERNAME=?;"

    authorities-by-username-query="
     SELECT strUSERNAME, strROLENAME 
     FROM TBLUSERS
     WHERE strUSERNAME=?;"

     />
  </authentication-provider>  
  </authentication-manager>  



 </beans:beans>
Run Code Online (Sandbox Code Playgroud)

我的login.jsp的标题如下

           <link rel="stylesheet" type="text/css" …
Run Code Online (Sandbox Code Playgroud)

resources spring jsp loading spring-security

0
推荐指数
1
解决办法
5317
查看次数

spring-security ACL教程

我需要在项目中添加角色和权限以及访问列表.我找到了这个,但我发现它有点过于基本和具体.

在实施之前是否有更好的教程/文章/示例我应该阅读或遵循?

permissions spring acl spring-security

0
推荐指数
1
解决办法
4147
查看次数

如何避免两次弹簧初始化?

我正在开发一个Spring mvc应用程序,并且最近注意到所有servlet在启动时都注册了两次.

你们有谁知道为什么?如果是这样,我如何在保持所有功能的同时避免这种情况?

Spring配置:

<?xml version="1.0" encoding="UTF-8"?>  <beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"  
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans  
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
http://www.springframework.org/schema/context  
http://www.springframework.org/schema/context/spring-context-3.1.xsd   
http://www.springframework.org/schema/util 
http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/cache 
http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd">  

<!-- SPRING MVC -->  
<mvc:annotation-driven />
<context:annotation-config/> 

<!-- Activates @Scheduled and @Async annotations for scheduling -->
<task:annotation-driven />

<import resource="spring-security.xml"/>

<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/js/**" location="/js/" /> 
<mvc:resources mapping="/images/**" location="/images/" />
<mvc:resources mapping="/robots.txt" location="robots.txt" />

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="messages"/>
</bean> 

<mvc:interceptors> 
     <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang" />
    </bean> …
Run Code Online (Sandbox Code Playgroud)

spring tomcat web.xml spring-mvc spring-security

0
推荐指数
1
解决办法
3338
查看次数

如何配置Spring Security以在multipart/form-data(POST)请求中处理CSRF令牌?

脚本

  • 使用HTTP API进行客户端 - 服务器通信的单页(AngluarJS)Web应用程序
  • Spring Security配置为使用CSRF保护(通过XML)
  • CSRF令牌通常在请求标头中发送(工作正常)
  • 应用程序需要支持IE9中的文件上传

问题

通过multipart/form-data POST请求实现文件上载.通常这是使用客户端AJAX完成的,但IE9不支持FileAPI(http://www.w3.org/TR/FileAPI/).

IE9的解决方法是在隐藏的iframe中创建表单,然后提交表单.CSRF令牌通过将其添加为表单输入而添加到请求正文中 - 原因是我无法操纵请求标头以在表单提交之前添加CSRF标头.

Spring Security的org.springframework.security.web.csrf.CsrfFilter首先尝试从头部获取CSRF令牌,如果没有找到,则尝试从参数中获取它(通过HttpServletRequest.getParameter())

这对于在主体中具有CSRF令牌的多部分请求不起作用 - getParameter()将始终返回null.

(顺便说一下,这个对getParameter()的调用也会将请求InputStream读取到最后,所以我们被迫在它到达CsrfFilter之前将请求换行,以便请求InputStream被'缓存')

我想创建一个调用getPart()的CsrfFilter,但是仍然使用nice + clean Spring Security XML命名空间元素时不能这样做.

原因是在配置中没有包含自定义CSRF过滤器的地方 - 并且CsrfConfigurer被硬编码为使用org.springframework.security.web.csrf.CsrfFilter,因此无法注入.

我可以将代码添加到我的请求包装器类的重写的getParameter()方法中,以尝试从多部分请求中解析参数 - 但实际上这是非常棘手的,并且宁愿避免这样的维护成本.

TL; DR

  • 我们无法添加CSRF令牌来请求头,需要添加到请求体
  • 请求是multipart/form-data
  • Spring Security CSRF过滤器不可配置为从多部分请求解析CSRF令牌

任何帮助 - 无论是在客户端还是服务器端修复建议 - 都是受欢迎的!

TIA

spring-security

0
推荐指数
1
解决办法
8370
查看次数

如果用户未经授权,Spring Security如何重定向到登录页面

  • 春季安全授权的内部机制是什么?
  • /Login如果用户没有输入有效凭据,它如何重定向URL ?
  • 谁对此行动负责?
  • 项目的内部流程是什么?

spring-security

0
推荐指数
1
解决办法
3676
查看次数

更改当前用户密码时应该验证什么?

我正在开发一个使用spring-security进行身份验证的spring-mvc项目.我也使用加密来编码密码并存储在数据库中.

现在我正在尝试更改密码功能.通常我们有old password和new password.

所以我有一些问题.

  1. 用户只能在登录后更改密码.那么是否有必要old password再次验证?

  2. 如果我们必须验证我们怎样才能在春天old password进行编码?

我正在使用BCryptPasswordEncoder密码编码.

java spring spring-security

0
推荐指数
1
解决办法
574
查看次数

使用Java中的SHA-256算法,Spring安全性,使用相同的盐比较两个散列密码?

我需要一些指导,我需要检查来自UI表单(即Authentication对象)的密码,我需要使用SHA-256 + constant salt(在进行比较之前)进行哈希处理,密码来自DB(DB也有密码+盐)使用Spring安全.

我想比较使用相同的SALT值生成的这两个不同的散列值.我们如何在java中做到这一点?有人可以分享一下示例代码吗?

java spring-security sha256

0
推荐指数
1
解决办法
8367
查看次数

Why does UserDetailsService return null in Spring Boot app?

A simple spring boot app has a custom UserDetailsService. The Spring Boot Controller is called by an AngularJS app, and authentication requests from the AngularJS app are made to the backend at the /user url pattern. But login requests are causing the controller logs to indicate that the controller is not finding the /user url pattern, and that the UserDetailsService is thus returning null. What specific changes need to be made to the code below in order to enable client …

java spring spring-mvc spring-security spring-boot

0
推荐指数
1
解决办法
8762
查看次数

使用spring security从jsp访问userName

如果他登录我想输出userName.来自@Controller我有权访问:

@RequestMapping("/success")
    public String success(Model model) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName(); //get logged in username
        model.addAttribute("name", name);
        return "success";
    }
Run Code Online (Sandbox Code Playgroud)

它工作如果我在jsp上使用名称,我看到键入的名称.

但如果在这个jsp我写

 <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
    <sec:authentication property="principal.username"/>
Run Code Online (Sandbox Code Playgroud)

我得到stackTrace:

 INFO : com.epam.hhsystem.util.CustomAuthentificationProvider - User with name 'Nikolay_Tkachev' log in
07.08.2013 17:00:57 org.apache.jasper.compiler.TldLocationsCache tldScanJar
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were …
Run Code Online (Sandbox Code Playgroud)

exception spring-security

-1
推荐指数
1
解决办法
4515
查看次数

自动发布的问题/找不到bean

我正在尝试实现Spring Boot并设置我的用户服务.我无法找到无法找到UserService bean的错误.任何建议或方向将不胜感激.

UserController的

@RestController
public class UserController {

    private final IUserService userService;

    @Inject
    public UserController(final IUserService userService) {
        this.userService = userService;
    }

    @RequestMapping(value = "/user", method = RequestMethod.POST)
    public FBUser createUser(@RequestBody @Valid final FBUser fBUser) {
        return userService.save(fBUser);
    }
}
Run Code Online (Sandbox Code Playgroud)

IUserService

public interface IUserService {

    FBUser save(FBUser fBUser);
}
Run Code Online (Sandbox Code Playgroud)

UserService

public class UserService implements IUserService {

    private final IUserRepository repository;

    @Inject
    public UserService(final IUserRepository repository) {
         this.repository = repository;
    }

    @Override
    @Transactional
    public FBUser save(final FBUser fBUser) {
        return …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security spring-boot

-1
推荐指数
1
解决办法
785
查看次数