Example usage for org.springframework.security.core.userdetails User User

List of usage examples for org.springframework.security.core.userdetails User User

Introduction

In this page you can find the example usage for org.springframework.security.core.userdetails User User.

Prototype

public User(String username, String password, boolean enabled, boolean accountNonExpired,
        boolean credentialsNonExpired, boolean accountNonLocked,
        Collection<? extends GrantedAuthority> authorities) 

Source Link

Document

Construct the User with the details required by org.springframework.security.authentication.dao.DaoAuthenticationProvider .

Usage

From source file:com.itn.services.CustomUserDetailsService.java

@Transactional(readOnly = true)

@Override// ww w .j  a va  2s. co m
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
    Users user = userService.findByUserName(userName);
    System.out.println("User : " + user);
    if (user == null) {
        System.out.println("User not found");
        throw new UsernameNotFoundException("Username not found");
    }
    // This new User is default class made my spring, not to be confused with entity name "Users"
    return new User(user.getUserName(), user.getPassword(), user.getState().equals("Active"), true, true, true,
            getGrantedAuthorities(user));
}

From source file:com.healthcit.analytics.service.LdapManager.java

public UserDetails mapUserFromContext(DirContextOperations ctx, String username,
        Collection<GrantedAuthority> authority) {

    userService.setAuthType("ldap");
    UserDetails originalUser = super.mapUserFromContext(ctx, username, authority);

    // Current authorities come from LDAP groups
    Collection<GrantedAuthority> newAuthorities = originalUser.getAuthorities();

    List<GrantedAuthority> grantedAuthorityList = new ArrayList<GrantedAuthority>();
    if (newAuthorities != null && !newAuthorities.isEmpty()) {

        for (GrantedAuthority currentUserRoles : newAuthorities) {
            grantedAuthorityList.add(new GrantedAuthorityImpl(currentUserRoles.getAuthority()));
        }//from   w w w  . j a  v a  2s .c o  m
    }

    UserDetails res = new User(originalUser.getUsername(), originalUser.getPassword(), true, true, true, true,
            grantedAuthorityList);

    return res;
}

From source file:jp.pigumer.sso.SAMLUserDetailsServiceImpl.java

@Override
public Object loadUserBySAML(SAMLCredential credential) throws UsernameNotFoundException {

    String userID = credential.getNameID().getValue();

    LOG.info(userID + " is logged in");
    List<GrantedAuthority> authorities = new ArrayList<>();
    GrantedAuthority authority = new SimpleGrantedAuthority("ROLE_USER");
    authorities.add(authority);// w w w  .  j  ava 2 s . c  o  m

    return new User(userID, "<abc123>", true, true, true, true, authorities);
}

From source file:bookmarks.WebSecurityConfiguration.java

@Bean
UserDetailsService userDetailsService() {
    return (username) -> accountRepository.findByUsername(username)
            .map(a -> new User(a.username, a.password, true, true, true, true,
                    AuthorityUtils.createAuthorityList("USER", "write")))
            .orElseThrow(() -> new UsernameNotFoundException("could not find the user '" + username + "'"));
}

From source file:cz.PA165.vozovyPark.service.impl.UserLoginServiceImpl.java

@Override
@Transactional(readOnly = true)//from w w w  .  j av a2  s.c  o  m
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    List<cz.PA165.vozovyPark.entities.User> myUserList = userDao.getByUsername(username);
    if (myUserList.size() == 1) {
        cz.PA165.vozovyPark.entities.User myUser = myUserList.get(0);
        List<SimpleGrantedAuthority> auths = new java.util.ArrayList<SimpleGrantedAuthority>();
        if (myUser.getIsAdmin()) {
            auths.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
        } else {
            auths.add(new SimpleGrantedAuthority("ROLE_USER"));
        }
        User userDetails = new User(username, myUser.getPassword(), myUser.getEnabled(), true, true, true,
                auths);
        return userDetails;
    } else {
        throw new UsernameNotFoundException("User with username" + username + " not found");
    }
}

From source file:org.apigw.authserver.svc.decrypted.DecryptedAutorizationCodeService.java

@Override
public String createAuthorizationCode(AuthorizationRequestHolder authentication) {

    final UserDetails encryptedUser = (UserDetails) authentication.getUserAuthentication().getPrincipal();
    final String encryptedUsername = encryptedUser.getUsername();
    final String decryptedUsername = decrypter.decrypt(encryptedUsername);

    final User decryptedUser = new User(decryptedUsername, encryptedUser.getPassword(),
            encryptedUser.isEnabled(), encryptedUser.isAccountNonExpired(),
            encryptedUser.isCredentialsNonExpired(), encryptedUser.isAccountNonLocked(),
            encryptedUser.getAuthorities());

    final SimpleAuthentication decryptedAuthentication = new SimpleAuthentication(decryptedUser);
    final AuthorizationRequestHolder decryptedAuthorization = new AuthorizationRequestHolder(
            authentication.getAuthenticationRequest(), decryptedAuthentication);

    return getAuthorizationCodeServices().createAuthorizationCode(decryptedAuthorization);

}

From source file:co.edu.utb.softeng.springtodos.service.security.MyUserDetailsService.java

private User buildSpringUser(co.edu.utb.softeng.springtodos.entity.security.User user,
        List<GrantedAuthority> authorities) {
    return new User(user.getUsername(), user.getPassword(), user.isEnabled(), true, true, true, authorities);
}

From source file:org.datacite.mds.service.userdetails.BaseMasterUserDetailsService.java

@Override
final public UserDetails loadUserByUsername(String username)
        throws UsernameNotFoundException, DataAccessException {
    String mastername = getMasterUsername(username);
    log4j.debug("building master user '" + mastername + "' for user '" + username + "'");

    UserDetails user = userDetailsService.loadUserByUsername(username);
    UserDetails master = userDetailsService.loadUserByUsername(mastername);

    return new User(user.getUsername(), //
            master.getPassword(), //
            master.isEnabled(), //
            master.isAccountNonExpired(), //
            master.isCredentialsNonExpired(), //
            master.isAccountNonLocked(), //
            user.getAuthorities());//from  w w w  . j a  v  a 2 s.c  o m
}

From source file:com.gsr.myschool.server.security.StatelessUserDetailService.java

@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
    com.gsr.myschool.server.business.User user = userRepos.findByEmail(email);
    if (user == null) {
        throw new UsernameNotFoundException("Bad credentials");
    } else {/*from ww  w.  j a  v a  2  s .c o  m*/
        List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
        authorities.add(new SimpleGrantedAuthority(user.getAuthority().name()));
        return new User(user.getEmail(), user.getPassword(), user.getStatus() == UserStatus.ACTIVE, true, true,
                true, authorities);
    }
}

From source file:pdl.web.service.UserManagementService.java

@Override
public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException, DataAccessException {
    UserDetails user = null;/*from   ww w  . j a va 2s.c o  m*/
    try {
        UserService pdlUserService = new UserService();
        pdl.cloud.model.User pdlUser = pdlUserService.getUserById(userId);

        if (pdlUser != null) {
            user = new User(pdlUser.getUserId(), pdlUser.getUserpass(), true, true, true, true,
                    getAuthorities(pdlUser.getAdmin()));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return user;
}