Java Spring Security 2用户详细信息服务问题上的自定义身份验证提供程序
我在我的webApp上安装了springsecurity2.0.5,使用默认的提供者。现在需求已经改变,我需要一个CustomAuthenticationProvider来改变身份验证方式 这是我的AuthenticationProviderJava Spring Security 2用户详细信息服务问题上的自定义身份验证提供程序,java,spring,tomcat,spring-security,Java,Spring,Tomcat,Spring Security,我在我的webApp上安装了springsecurity2.0.5,使用默认的提供者。现在需求已经改变,我需要一个CustomAuthenticationProvider来改变身份验证方式 这是我的AuthenticationProvider public class CustomAuthenticationProvider implements AuthenticationProvider { @Autowired private ParamsProperties paramsPropert
public class CustomAuthenticationProvider implements AuthenticationProvider {
@Autowired
private ParamsProperties paramsProperties;
@SuppressWarnings("unchecked")
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
//Check username and passwd
String user = (String) authentication.getPrincipal();
String pass = (String) authentication.getCredentials();
if(StringUtils.isBlank(user) || StringUtils.isBlank(pass) ){
throw new BadCredentialsException("Incorrect username/password");
}
//Create SSO
SingleSignOnService service = new SingleSignOnService(paramsProperties.getServicesServer());
try {
//Check logged
service.setUsername(authentication.getName());
service.setPassword(authentication.getCredentials().toString());
ClientResponse response = service.call();
String result = response.getEntity(String.class);
ObjectMapper mapper = new ObjectMapper();
Map<String,Object> map = mapper.readValue(result, new TypeReference<Map<String,Object>>() {} );
//Read code
String code = (String)map.get("code");
log.debug(" ** [Authenticate] Result: " + code );
for (String s : (List<String>)map.get( "messages" ) ) {
log.debug(" [Authenticate] Message: " + s );
}
if ( code.equals( "SESSION_CREATED" ) || code.equals( "SESSION_UPDATED" ) || code.equals( "SESSION_VERIFIED" ) ) {
UsernamePasswordAuthenticationToken tokenSSO = LoginHelper.getuserSringTokenFromAuthService(map);
return tokenSSO;
} else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
throw new AuthenticationServiceException( e.getMessage() );
}
}
public boolean supports(Class authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
有人能帮忙吗?您将
authenticationProvider
bean称为用户服务,但它不是
<authentication-provider user-service-ref='authenticationProvider'>
不用说,强烈建议升级,如果没有其他原因,那么只是为了更容易获得支持。Oops!我试过使用
,这确实有效。非常感谢你,这让我很开心。
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy112 implementing org.springframework.security.providers.AuthenticationProvider,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.security.userdetails.UserDetailsService] for property 'userDetailsService': no matching editors or conversion strategy found
<authentication-provider user-service-ref='authenticationProvider'>