-
I am unable to paste my code in so there may be some typos.
CustomProviderAuthentication
Code:
public class CustomAuthenticationProvider implements AuthenticationProvider {
@Resource DataSource dataSource;
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
UsernamePasswordAuthenticationToken auth = (UsernamePasswordAuthenticationToken) authentication;
String username = String.valueOf(auth.getPrincipal());
String password = String.valueOf(auth.getCredentials());
Connection conn = null;
try{
//In this call I use the username and password and pass them to my oracle proxy connection and then try to connect to the database
conn = dataSourceAdapter.doGetConnection(username, password);
}
catch(SQLException sqle) {
throw new BadCredentialsException(LoginException.handleLoginErrors(sqle));
}
//I use the same connection to get the granted authorities, user's role and user's id
return new UsernamePasswordAuthenticationToken(username, password,new GrantedAuthority[] {new GrantedAuthorityImpl(userRole)});
}
It works well for testing the database connection.
-
Is it possible to post your userDetailsService related java implementation classes, please?
Thanks.
-
do you have implmentation for grants?
new GrantedAuthorityImpl(userRole)
Thanks.
-
Hi rhart,
as you mentioned in the code of class UserDetailsServiceImpl
Code:
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
try {
User user = userApplicationService.findUserByUsername(username);
return assembler.buildAuthenticatedUserDTOFromUser(user);
} catch (NoResultException e) {
throw new UsernameNotFoundException(e.getLocalizedMessage());
}
}
this method must return UserDetais object, I am not sure how can i do that....
Please help me as i am new to this.
Thanks in advance
-
modify the password
Is what possible to modify the password before the authentication.
-
security.xml
I've created a extended class of 创DaoAuthenticationProvider创 and initialized in security.xml:
<bean id="myAuthenticationProvider" class="es.gva.cit.terceros.security.provider.MyAut henticationProvider">
<security:custom-authentication-provider />
</bean>
But the definition of bean can't be accessible because of:
SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'
What can I do to declare the bean element in the 创security.xml创 file?
Where I have to declare the new bean? And if i have to add this new bean to a 创authenticationManager创 bean and declare it too.