Tag: spring security

Spring @ExceptionHandler不捕获AccessDeniedException

我有一个使用以下代码设置的exception处理程序 @ExceptionHandler(Throwable.class) public @ResponseBody CustomResponse handleException(Throwable throwable){ // handles exception, returns a JSON } 我使用的是Spring Security 3.1。 当我尝试在没有身份validation的情况下执行操作时,应用程序会抛出AccessDeniedException。 它永远不会出现在这种方法中。 但与其他例外情况一起工作正常 这是应该工作的方式吗? 或者我的代码有问题吗? 这看起来像一个解决方案。 但如果我能在一个点上处理exception会更好。 这是我的配置文件 //intercept urls UPDATE 这里用户未经过身份validation(ROLE_ANONYMOUS)。 当我尝试访问受保护的页面时,它会将我重定向到登录URL。 我的问题在于,我进行了一次AJAX调用。 因此,重定向到返回ModelAndView的方法不起作用。 这附近有工作吗?

Spring-Security-Oauth2:默认登录成功url

是否可以为Spring Oauth2 Sso服务设置默认登录成功? 继szenario之后 浏览器reqeuests index.html sso服务:不受保护==>返回index.html index.html包含manifest属性==>浏览器请求清单 sso服务:Manifest受保护==>返回401 客户端重定向到${sso.host}/login sso服务重定向到auth服务器 authentication ==>使用query-String中的代码重定向回${sso.host}/login sso服务:请求令牌并重定向到清单文件 有没有办法不重定向到受保护的最后一个请求的资源,但默认情况下重定向到’index.html’? 即使没有办法实现这一点,请告诉我

如何在Spring Boot应用程序上启用Bearer身份validation?

我想要实现的是: 存储在通过jdbc访问的数据库(即MySQL)中的用户,权限,客户端和访问令牌 API公开了端点,让您问“我可以拥有OAuth2不记名令牌吗?我知道客户端ID和密码” 如果您在请求标头中提供Bearer令牌,则API允许您访问MVC端点 我对此非常了解 – 前两点正在发挥作用。 我无法为我的Spring Boot应用程序使用完全默认的OAuth2设置,因为标准表名已经在我的数据库中使用(例如,我已经有一个“用户”表)。 我手动构建了自己的JdbcTokenStore,JdbcClientDetailsS​​ervice和JdbcAuthorizationCodeServices实例,将它们配置为使用我的数据库中的自定义表名,并设置我的应用程序以使用这些实例。 所以,这就是我到目前为止所拥有的。 我可以要求持票人令牌: # The `-u` switch provides the client ID & secret over HTTP Basic Auth curl -u8fc9d384-619a-11e7-9fe6-246798c61721:9397ce6c-619a-11e7-9fe6-246798c61721 \ ‘http://localhost:8080/oauth/token’ \ -d grant_type=password \ -d username=bob \ -d password=tom 我收到回复; 太好了! {“access_token”:”1ee9b381-e71a-4e2f-8782-54ab1ce4d140″,”token_type”:”bearer”,”refresh_token”:”8db897c7-03c6-4fc3-bf13-8b0296b41776″,”expires_in”:26321,”scope”:”read write”} 现在我尝试使用该令牌: curl ‘http://localhost:8080/test’ \ -H “Authorization: Bearer 1ee9b381-e71a-4e2f-8782-54ab1ce4d140” 唉: { “timestamp”:1499452163373, “status”:401, […]

Spring安全角色层次结构无法使用Java Config

首先,我是Java Spring Framework的新手。 如果我没有提供足够的信息,请原谅我。 我试图将RoleHierarchy添加到我的应用程序中,但它不起作用。 以下是我尝试过的代码。 SecurityConfig.java // These config is try to set up a user Role Hierarchy @Bean public RoleHierarchy roleHierarchy() { System.out.println(“arrive public RoleHierarchy roleHierarchy()”); RoleHierarchyImpl r = new RoleHierarchyImpl(); r.setHierarchy(“ROLE_ADMIN > ROLE_STAFF”); r.setHierarchy(“ROLE_STAFF > ROLE_USER”); r.setHierarchy(“ROLE_DEVELOPER > ROLE_USER”); r.setHierarchy(“ROLE_USER > ROLE_GUEST”); return r; } @Bean public AffirmativeBased defaultAccessDecisionManager(RoleHierarchy roleHierarchy){ System.out.println(“arrive public […]

Spring Security – 白名单IP范围

我查看过的很多资源和stackoverflow问题都提供了使用.xml文件的答案: 使用Spring Security的IPfilter Spring Security 4 Method security using @PreAuthorize,@PostAuthorize, @Secured, EL http://docs.spring.io/spring-security/site/docs/3.0.x/reference/appendix-namespace.html#nsa-gms 我想知道的是,如果可以在不使用XML配置的情况下使用Spring Security将IP地址范围列入白名单? 以下是我的控制器中的一个简单方法: @RequestMapping(value = “/makeit”, method = RequestMethod.GET) @ResponseBody //@PreAuthorize(“hasIpAddress(‘192.168.0.0/16’)”) public String requestData() { return “youve made it”; } 我已经为安全配置创建了一个单独的类,但它没有太多,我只是为EnableGlobalMethodSecurity注释创建它 – 这样我就可以使用@PreAuthorize注释(来自这里的答案: @PreAuthorize注释不工作弹簧安全性 )。 @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class SpringConfiguration extends WebSecurityConfigurerAdapter { @Override public void configure(HttpSecurity http) throws […]

使用JavaConfig示例的Spring Security Digest Auth

如何使用javaconfig(无XML)专门为摘要式身份validation配置Spring 4.0和Spring Security(3.2.0)? 我使用下面的配置类,但所有请求都被HTTP 401拒绝,“Nonce应该产生两个令牌,但是(…消息就在那里停止)”。 @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfigurationDigest extends WebSecurityConfigurerAdapter { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication().withUser(“user”).password(“password”).roles(“USER”); } @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers(“/**”).authenticated().and().addFilter(digestAuthenticationFilter(digestEntryPoint())); } @Override @Bean public UserDetailsService userDetailsServiceBean() throws Exception { return super.userDetailsServiceBean(); } public DigestAuthenticationFilter digestAuthenticationFilter(DigestAuthenticationEntryPoint digestAuthenticationEntryPoint) throws Exception { DigestAuthenticationFilter […]

使用Spnego / Kerberos进行Spring启动 – 配置问题 – 需要ServletContext来配置默认的servlet处理

让spring-security-kerberos-web与Spring Boot应用程序一起工作,我似乎已经达到了一个死胡同。 我的项目中有一个@Configuration类,如下所示 package com.co.dept.bsc.configuration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.FileSystemResource; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider; import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider; import org.springframework.security.kerberos.authentication.sun.GlobalSunJaasKerberosConfig; import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient; import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator; import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter; import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint; import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; import com.co.dept.bsc.service.DummyUserDetailsService; @Configuration @EnableWebSecurity public class AuthProviderConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(final HttpSecurity http) throws Exception […]

Spring Security hasAnyRole无法正常工作

我正在开发一个带有Spring安全认证和MongoDB的应用程序。 身份validation方法工作正常,但只能使用ROLE_ADMIN 。 我需要身份validation的所有方法都注释为: @PreAuthorize(“hasAnyRole(‘ROLE_ADMIN’, ‘ROLE_USER’)”) 当我尝试与具有ROLE_USER的用户进行身份validation时,我始终会获得访问拒绝错误。 我的spring安全配置是: 如果我使用: 我对ROLE_ADMIN和ROLE_USER都拒绝访问。 如果我使用: 我可以使用ROLE_ADMIN用户登录,但我无法使用ROLE_USER 。 在我的LoginService我有: public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { boolean enabled = true; boolean accountNonExpired = true; boolean credentialsNonExpired = true; boolean accountNonLocked = true; User user = getUserDetail(email); userdetails = new org.springframework.security.core.userdetails.User( user.getEmail(), user.getPwd(), enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, getAuthorities(user.getIsAdmin())); return userdetails; } […]

如何使用Spring Security自动注销

我有一个spring web应用程序,我使用Spring安全性进行了用户身份validation。 一切都很好。 登录并注销完美! 现在,我想实现以便自动注销。 例如,如果用户打开窗口大约30分钟并且什么也不做(例如,会话已过期)系统应该自动注销。 我该如何实现呢? 它可能由客户端实现(我每1分钟发送一次请求并检查会话是否结束)。 但我不能自动从Spring那里做到这一点吗? 我有这个配置: 并在web.xml中 1 1分钟后,我看到会话被破坏了。 1分钟后杀死会话。 但是页面没有重定向到/ login?logout

在解密Saml令牌时获取错误

我在解密saml令牌时遇到错误。 但是,重新启动服务器后,此问题不一致。 它工作正常,直到昨晚:( DEBUG Decrypter:631 – Attempt to decrypt EncryptedKey using credential from KEK KeyInfo resolver failed: org.opensaml.xml.encryption.DecryptionException: Probable runtime exception on decryption:unknown parameter type. at org.opensaml.xml.encryption.Decrypter.decryptKey(Decrypter.java:705) at org.opensaml.xml.encryption.Decrypter.decryptKey(Decrypter.java:628) at org.opensaml.xml.encryption.Decrypter.decryptUsingResolvedEncryptedKey(Decrypter.java:783) at org.opensaml.xml.encryption.Decrypter.decryptDataToDOM(Decrypter.java:524) at org.opensaml.xml.encryption.Decrypter.decryptDataToList(Decrypter.java:442) at org.opensaml.xml.encryption.Decrypter.decryptData(Decrypter.java:403) at org.opensaml.saml2.encryption.Decrypter.decryptData(Decrypter.java:141) at org.opensaml.saml2.encryption.Decrypter.decrypt(Decrypter.java:69) at org.springframework.security.saml.websso.WebSSOProfileConsumerImpl.processAuthenticationResponse(WebSSOProfileConsumerImpl.java:199) at org.springframework.security.saml.SAMLAuthenticationProvider.authenticate(SAMLAuthenticationProvider.java:82) at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:156) at org.springframework.security.saml.SAMLProcessingFilter.attemptAuthentication(SAMLProcessingFilter.java:84) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:195) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) […]