Tag: spring security

org.springframework.security.core.userdetails.User无法强制转换为MyUserDetails

当我实现Spring安全性的User类时,我得到了类转换exception。 我想在MyUserDetails(id)中添加一些额外的细节,但我无法得到结果。 这个问题在这里得到了回答,但后来我得到了两个错误,不知道我在哪里失踪。 以下是我的代码: SecurityConfig.java: @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired @Qualifier(“authenticationProvider”) AuthenticationProvider authenticationProvider; @Autowired DataSource dataSource; @Autowired public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception { auth.jdbcAuthentication() .dataSource(dataSource) .passwordEncoder(passwordEncoder()) .usersByUsernameQuery( “select username,password, enabled from users where username=?”) .authoritiesByUsernameQuery( “select username, role from user_roles where username=?”); } @Bean public PasswordEncoder passwordEncoder() { PasswordEncoder encoder […]

如何使用spring-social-security SocialAuthenticationFilter指定OAuth2范围?

我正在使用Spring Social和Spring Security对用户进行身份validation,并在我的Web应用程序上自动创建本地帐户。 如何提供OAuth2 scope以进行身份​​validation? 在春季社交样本中 ,我看不出scope应该去哪里。 scope的特定用例是让用户通过Facebook进行身份validation,然后获取用户的Facebook电子邮件( scope=”email” )以创建本地帐户。

没有使用Spring安全性找到AuthenticationProvider

我一直在尝试使用他们的x509证书通过LDAP对用户进行身份validation,但似乎无法使用它。 我声明了一个身份validation提供程序,但我仍然收到一个错误,说没有提供程序。 这是我的调试输出: INFO: Initiating Jersey application, version ‘Jersey: 1.12 02/15/2012 04:51 PM’ DEBUG: ossecurity.web.FilterChainProxy – /x509 at position 1 of 8 in additional filter chain; firing Filter: ‘SecurityContextPersistenceFilter’ DEBUG: osswcHttpSessionSecurityContextRepository – No HttpSession currently exists DEBUG: osswcHttpSessionSecurityContextRepository – No SecurityContext was available from the HttpSession: null. A new one will be created. DEBUG: ossecurity.web.FilterChainProxy […]

如何在TokenEndPoint Spring oAuth2中注入WebResponseExceptionTranslator

我试图自定义Spring Security oAuth TokenEndpoint类处理exception的方式。 我想返回一个比DefaultWebResponseExceptionTranslator当前更自定义的JSON响应。 我无法弄清楚如何通过XML注入自定义转换器。 这是我的代码片段: 弹簧security.xml文件 这是AbstractServerBeanDefinitionParser的相关代码部分 BeanDefinitionBuilder tokenEndpointBean = BeanDefinitionBuilder.rootBeanDefinition(TokenEndpoint.class); tokenEndpointBean.addPropertyReference(“clientDetailsService”, clientDetailsRef); tokenEndpointBean.addPropertyReference(“tokenGranter”, tokenGranterRef); authorizationEndpointBean.addPropertyReference(“oAuth2RequestValidator”, oAuth2RequestValidatorRef); parserContext.getRegistry() .registerBeanDefinition(“oauth2TokenEndpoint”, tokenEndpointBean.getBeanDefinition()); if (StringUtils.hasText(oAuth2RequestFactoryRef)) { tokenEndpointBean.addPropertyReference(“oAuth2RequestFactory”, oAuth2RequestFactoryRef); } if (StringUtils.hasText(oAuth2RequestValidatorRef)) { tokenEndpointBean.addPropertyReference(“oAuth2RequestValidator”, oAuth2RequestValidatorRef); } TokenEndpoint扩展了AbstractEndpoint,它是定义转换器的地方。 @FrameworkEndpoint public class TokenEndpoint extends AbstractEndpoint { @ExceptionHandler(Exception.class) public ResponseEntity handleException(Exception e) throws Exception { logger.info(“Handling error: ” + e.getClass().getSimpleName() […]

Spring Security:我知道用户何时登录?

我正在使用带有基于URL的拦截器的spring security来保护我的应用程序。 在用户登录后,我可以在哪些类/哪个点进行自定义处理? 我特别想保存用户最后登录的日期,但我无法弄清楚如何实现这一点。 非常感谢你的帮助。

Spring安全性:期望只为类型接口找到一个bean org.springframework.security.authentication.AuthenticationManager

我在Myconfig类中有以下代码,它扩展了WebSecurityConfigurerAdapter 。 由于以下原因,我得到了statcktrace: java.lang.IllegalArgumentException:期望只查找类型为interfacorg.springframework.security.authentication.AuthenticationManager的单个bean,但找到[authenticationManagerBean,providerManager]。 @Bean(name=”preAuthFilter”) public SSOCookieFilter preAuthFilter() throws Exception { SSOCookieFilter cookieFilter= new SSOCookieFilter(); cookieFilter.setAuthenticationManager(authenticationManagerBean()); return cookieFilter; } @Bean(name = “preAuthProvider”) public PreAuthenticatedAuthenticationProvider getPreAuthProvider() { PreAuthenticatedAuthenticationProvider preAuthenticatedAuthenticationProvider = new PreAuthenticatedAuthenticationProvider(); preAuthenticatedAuthenticationProvider.setPreAuthenticatedUserDetailsService(new PreAuthenticatedGrantedAuthoritiesUserDetailsService()); return preAuthenticatedAuthenticationProvider; } @Bean @Override public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); } 我已经尝试了一些来自stackoverflow的链接,它建议使用@qualifier但是我的错误它不起作用(逻辑上它应该用作方法名称被认为是bean id)。 请帮忙。 提前致谢

ossoprovider.endpoint.TokenEndpoint:处理错误:InvalidGrantException,错误的凭据

我正在开发Spring Cloud授权服务器 ,启动服务器时没有收到任何错误,但是当我尝试访问http:// localhost:9000 / services / oauth / token时 ,我收到以下错误。 你能指导一下这个问题吗? 虽然grant_type是正确的,但我想知道为什么说无效补助金? PluralsightSpringcloudM4SecureauthserverApplication @SpringBootApplication @EnableAuthorizationServer @EnableResourceServer @RestController public class PluralsightSpringcloudM4SecureauthserverApplication { public static void main(String[] args) { SpringApplication.run(PluralsightSpringcloudM4SecureauthserverApplication.class, args); } @RequestMapping(“/user”) public Principal user(Principal user) { return user; } } ServiceConfig @Configuration public class ServiceConfig extends GlobalAuthenticationConfigurerAdapter { @Override public void init(AuthenticationManagerBuilder auth) throws […]

Spring安全认证 – 有关文档的问题

我在Spring Security JavaDoc中查看此页面: http://static.springsource.org/spring-security/site/docs/3.1.x/apidocs/org/springframework/security/web/authentication/AbstractAuthenticationProcessingFilter.html#attemptAuthentication(javax.servlet.http.HttpServletRequest,%20javax .servlet.http.HttpServletResponse ) 这条线是什么意思? 返回null,表示身份validation过程仍在进行中。 在返回之前,实现应该执行完成该过程所需的任何其他工作。 我正在开发一个允许用户登录并收集其他数据的表单。 我不想使用默认的UsernamePasswordAuthenticationFilter,因为我将丢失表单中填写的所有其他数据。

忘记密码function弹簧(密码撤销)

我正在构建一个涉及用户注册和登录的Web应用程序。我正在尝试实现一项function,使用户能够在其注册的电子邮件地址中检索密码。 因此,将发送一条消息以重新输入密码或仅在该电子邮件中提供密码。 我正在使用spring,是否有任何教程/文章有人展示了这个实现的一个例子? 所有答案将不胜感激。 谢谢

Spring MVC – 动态更改安全设置

我正在研究Java Spring MVC应用程序,我正在使用基于Java的Spring Security配置。 我需要动态更改一些Spring Security设置(在用户活动期间) 。 这是我的代码的一部分: @Override protected void configure(HttpSecurity http) throws Exception { http .anyRequest().authenticated() .and() .formLogin() .loginPage(“/admin/login”) … } 我需要在用户活动期间将/admin/login url更改为customer/login 。