Tag: spring security

Spring AuthenticationFailureHandler和WebSecurityConfigurerAdapter loginPage()

编辑:解决了。 在这篇文章后看到我的评论 我目前正在使用Spring-Security实现Web应用程序。 我已经实现了一个自定义AuthenticationFailureHandler ,它检查用户是否经常尝试使用错误的凭据登录(并阻止他几分钟)。 但正常的登录失败应该将用户重定向到登录页面,参数错误( /login?error )。 此页面显示错误消息,例如“您输入的密码错误” AutenticationFailureHandler看起来像这样(没有无代码的代码) public class CustomAuthenticationHandler implements AuthenticationFailureHandler { // Some variables @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { // some logic here.. request.setAttribute(“param”, “error”); response.sendRedirect(“/login?error”); } 我的WebApplicationSecurity类如下所示: @Configuration @EnableWebMvcSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired CustomAuthenticationHandler customAuthenticationHandler; @Override protected void […]

如何结合Spring Security和js sockjs-client

我想通过sockjs-client创建一个Spring Server和一个Broswer javascript客户端连接。 应通过Spring Security确保连接。 我有以下两难困境: Spring Security似乎假设websocket握手是通过经过身份validation的http会话发生的(例如,JSESSIONID cookie设置,登录发生)。 然而,sockjs-client似乎对开发人员施加限制,即必须使用未经过身份validation的http会话(请参阅https://github.com/sockjs/sockjs-client/issues/196 ),以任何方式强制执行此操作。 我对这种困境的评价是否正确,是否有任何明显的解决方案来实现带有websockets的弹簧服务器的安全性,以便sockjs-client可以安全地连接? 如果用于创建经过身份validation的HttpSession,建议的在GET / info请求中传递任何身份validation令牌的解决方案看起来像是无法绕过SockJS安全限制。 这似乎是几个人问题的基础,例如: 在使用sockjs和stomp的/ info请求期间没有cookie Spring Websocket + SockJS的身份validation模型,并按用户发送消息 如何从Spring 4 stomp websocket方法获取/设置主体和会话属性 https://stackoverflow.com/questions/33156282 Spring Websockets @SendToUser没有登录? Spring Session Basic Auth令牌作为Spring-Websocket中的查询参数传递 Spring安全websocket和HTTP身份validation/授权 Spring Session,Websocket Security集成流程 Spring安全/ Spring会话/ Web套接字 Spring Boot,Websockets无法从Session获取用户(即java.security.Principal) Spring 4 WebSockect over STOMP Authentication http://sunitkatkar.blogspot.de/2014/01/spring-4-websockets-with-sockjs-stomp.html 我看到3种可选方式: 不要使用SockJs,而只使用本机Websockets 通过query-param Token在经过身份validation的Http Session上使用SockJS,并牺牲一些安全性 […]

OAuth2 – 在Spring Security中处理密码更改

我在Spring安全模块的帮助下为我的REST服务(密码授权类型)实现了OAuth2。 我’使用postgreSQL作为我的令牌存储。 一切正常,但我需要添加更改用户密码的可能性。 如果用户更改了密码,则应删除/忘记旧令牌。 我使用JdbcTokenStore Spring服务实现此function: public void updatePassword(User user, String newPassword) { … // Update password in database clearUserTokens(user.getUsername()); } private void clearUserTokens(String userName) { Collection tokens = jdbcTokenStore.findTokensByUserName(userName); tokens.stream().forEach(jdbcTokenStore::removeAccessToken); } 这种方法是否正确? 处理这种情况有什么标准方法吗?

如何使用弹簧安全性保护混合Spring MVC + Flex应用程序

我试过在Spring论坛上问这个问题( http://forum.springsource.org/showthread.php?109948-Problem-configuring-spring-security-3.1-with-hybrid-Spring-MVC-Flex-application )但是没有得到回应。 我正在开发一个Web应用程序,它具有内置Flex的(最终用户)用户界面和使用Spring MVC构建的管理用户界面。 我正在尝试保护两个接口,并且可以让每个接口单独工作,但不能一起工作。 我正在使用带有Spring Security 3.1RC1和Spring 3.1M1的spring-flex-core 1.5.0的快照构建 如果我只包含没有pattern属性的第一个http标记,则flex UI似乎使用Spring安全性成功进行身份validation。 但是,如果我包含所有标签,那么根据我是否使用,我会得到两个错误之一 这使 SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: The filter chain map already contains this request matcher [Root bean: class [org.springframework.security.web.util.AnyRequestMatcher]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]. If […]

使用Java中的Spring Properties和CrossOrigin Annotation或Spring-Config XML

我在Spring中使用CrossOrigin注释。 现在我想将一个Property作为值注入注释。 我不打算这个工作。 现在我像这样访问我的财产: @Value(“${settings.cors_origin}”) String cors_origin; 我想将此属性注入CrossOrigin注释: …. @CrossOrigin(origins = cors_origin) @RequestMapping(value=”/request”, method= RequestMethod.GET, produces = “application/json”) public ResponseEntity getMethod() { … 我尝试过这样的事: @CrossOrigin(origins = “${settings.cors_origin}”) 编辑1: 现在我尝试在我的spring配置中全局设置CORS-Header: 此设置也无效! 允许的原点与属性文件中指定的原点不同。 我认为它不会将变量转换为值? 当我在spring config allowed-origin中手动设置IP地址时,它正在工作。 设置有问题…… appsettings.properties: test=http://192.168.1.200 编辑2: 解决了 经过一段时间的故障排除后,我现在为我解决了这个问题:-)现在我再次使用注释@CrossOrigin。 我不得不将RequestMethod选项添加到Spring RequestMapping: @RestController @CrossOrigin(origins = {“${settings.cors_origin}”}) @RequestMapping(“/api/v1″) public class MainController { @RequestMapping(value=”/request”, method = […]

Spring Security:取决于实体的不同身份validation方法

先发帖在这里,希望我做得对。 在一个项目中,我们有一个场景,我们有一个包含多个实体的Web应用程序。 目前,登录是通过默认的JDBC Spring Security提供程序管理的,工作正常。 对于新的需求,我们需要每个实体都有自己的登录方法(目前有两种方法可用,JDBC方法是当前方法,第二种方法是通过SAML进行身份validation,每个实体都定义自己的方法IdP,但这是另一个故事) 我需要一些关于如何实现这一目标的指导,我已经做了一些搜索,我找到了不同URL的提供程序等等……但是对于同一个应用程序和url没有不同的登录方法,具体取决于用户类型或实体。 有一个自定义单一入口点是一个很好的方法,我们可以检查实体用户,然后使用合适的身份validation提供程序? 亲切的问候, 亚历克斯

如何检查方法级弹簧安全性

我已经在控制器方法中实现了spring security。 下面是我的spring security.xml – > 下面是我的控制器 @Secured({“ROLE_ADMIN”}) @RequestMapping(value = “/common/admin/addAdmin”, method = RequestMethod.GET) public String add(ModelMap map) { map.addAttribute(new Administrator()); return “/common/admin/addAdmin”; } @Secured({“ROLE_ADMIN”}) @RequestMapping(value = “/common/admin/addAdmin”, method = RequestMethod.POST) public String processadd( @ModelAttribute(“administrator”) Administrator administrator) { this.administratorManager.addAdmin(administrator); return “/common/admin/success”; } 我允许管理员和用户角色使用url / common / admin / **。 但我在管理员控制器中做了一些限制。 当用户作为用户角色进入/ common / admin / […]

Spring Security匿名用户可以访问每个URL

我正在开发gwt应用程序,我希望使用spring-security来保护它。 我在数据库中有用户数据,UserService负责获取特定用户。 我已经按照本教程 的AuthenticationProvider: public class CustomAuthenticationProvider implements AuthenticationProvider { @Autowired UserService userService; @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = (String) authentication.getPrincipal(); String password = (String) authentication.getCredentials(); User user = userService.findByUserName(username); if (user == null) { throw new UsernameNotFoundException(“User not found”); } String storedPass = user.getPassword(); if (!storedPass.equals(password)) { throw new […]

用Spring Boot 2代替403而不是403

使用Spring Boot 1.5.6.RELEASE我能够发送HTTP状态代码401而不是403 ,如下所示: 如果请求uri未经身份validation , Spring Spring 安全响应未经授权(http 401代码) ,通过这样做: public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { //… http.exceptionHandling() .authenticationEntryPoint(new Http401AuthenticationEntryPoint(“myHeader”)); //… } } 使用org.springframework.boot.autoconfigure.security.Http401AuthenticationEntryPoint类。 我刚刚升级到Spring Boot 2.0.0.RELEASE ,发现不再有这样的类了(至少在那个包中)。 问: Spring Boot中是否存在此类( Http401AuthenticationEntryPoint )? 如果不是,那么在现有项目中保持相同行为以保持与依赖于此状态代码( 401 )而不是403其他实现的一致性的403什么?

Spring java.lang.IllegalStateException:在提交响应后无法创建会话

我在我的spring应用程序中遇到会话管理问题,这是方案。 当用户打开我的应用程序URL时,它会要求提供凭据并登录。用户进入后,如果他打开一个新选项卡并粘贴我的应用程序URL,它将再次请求凭据并且用户登录。 现在,如果用户在tab1中注销,并且如果用户想要在第二个选项卡中执行任何操作,则用户会在下面的堆栈跟踪中收到错误并注销。 Oct 10, 2014 3:11:27 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [CollPortal] in context with path [/CollPortal] threw exception java.lang.IllegalStateException: Cannot create a session after the response has been committed at org.apache.catalina.connector.Request.doGetSession(Request.java:2886) at org.apache.catalina.connector.Request.getSession(Request.java:2316) at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:898) at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:910) at com.dc.core.common.FlashRecyclingFilter.doFilterInternal(FlashRecyclingFilter.java:22) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.dc.core.common.StripJSessionIdFilter.doFilter(StripJSessionIdFilter.java:101) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) […]