Search in sources :

Example 96 with UserDetails

use of org.springframework.security.core.userdetails.UserDetails in project dhis2-core by dhis2.

the class GhostAutomaticAccessProvider method initialise.

// -------------------------------------------------------------------------
// AdminAccessManager implementation
// -------------------------------------------------------------------------
@Override
public void initialise() {
    String username = "ghost_admin";
    String password = "";
    UserDetails user = new User(username, password, true, true, true, true, getGrantedAuthorities());
    authentication = new UsernamePasswordAuthenticationToken(user, user.getPassword(), user.getAuthorities());
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) User(org.springframework.security.core.userdetails.User) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 97 with UserDetails

use of org.springframework.security.core.userdetails.UserDetails in project dhis2-core by dhis2.

the class DefaultCurrentUserService method getCurrentUserInfo.

@Override
public UserInfo getCurrentUserInfo() {
    UserDetails userDetails = getCurrentUserDetails();
    if (userDetails == null) {
        return null;
    }
    Integer userId = USERNAME_ID_CACHE.get(userDetails.getUsername(), un -> getUserId(un));
    if (userId == null) {
        return null;
    }
    Set<String> authorities = userDetails.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toSet());
    return new UserInfo(userId, userDetails.getUsername(), authorities);
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails)

Aggregations

UserDetails (org.springframework.security.core.userdetails.UserDetails)97 Test (org.junit.Test)37 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)32 Authentication (org.springframework.security.core.Authentication)30 GrantedAuthority (org.springframework.security.core.GrantedAuthority)16 User (org.springframework.security.core.userdetails.User)14 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)14 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)9 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)8 LdapUserDetailsService (org.springframework.security.ldap.userdetails.LdapUserDetailsService)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)6 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)6 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)6 User (org.apache.atlas.web.model.User)4 User (org.hisp.dhis.user.User)4 IOException (java.io.IOException)3 Date (java.util.Date)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)3