Search in sources :

Example 1 with Role

use of ai.elimu.model.enums.Role in project webapp by elimu-ai.

the class CustomAuthenticationManager method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    logger.info("authenticate");
    logger.info("authentication.getName(): " + authentication.getName());
    Contributor contributor = (Contributor) authentication.getPrincipal();
    logger.info("contributor: " + contributor);
    logger.info("contributor.getRoles(): " + contributor.getRoles());
    for (Role role : contributor.getRoles()) {
        AUTHORITIES.add(new SimpleGrantedAuthority("ROLE_" + role.toString()));
    }
    return new UsernamePasswordAuthenticationToken(authentication.getName(), authentication.getCredentials(), AUTHORITIES);
}
Also used : Role(ai.elimu.model.enums.Role) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Contributor(ai.elimu.model.Contributor) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Aggregations

Contributor (ai.elimu.model.Contributor)1 Role (ai.elimu.model.enums.Role)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1