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

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

Introduction

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

Prototype

public UsernameNotFoundException(String msg) 

Source Link

Document

Constructs a UsernameNotFoundException with the specified message.

Usage

From source file:com.lattelearning.web.SpringAuthenticator.java

public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {

    User details = userManager.getUser(username);
    System.out.println(details);//w w w.  j ava  2 s .c o m

    if (details == null) {
        throw new UsernameNotFoundException("Unknown user: " + username);
    }
    return (UserDetails) details;

}

From source file:demo.domain.service.MyUserDetailsService.java

@Override
@Transactional(readOnly = true)//from  ww w .ja  va2s.  com
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

    Account account = Optional.ofNullable(accountService.selectFindOne(username))
            .orElseThrow(() -> new UsernameNotFoundException("?????"));

    List<UserProjectRoleAuthority> userProjectRoleAuthority = Optional
            .ofNullable(userProjectRoleAuthorityService.selectFindByUserId(account.getUserId()))
            .orElseThrow(() -> new UsernameNotFoundException("??????"));

    List<GrantedAuthority> authorities = new ArrayList<>();
    userProjectRoleAuthority.forEach((UserProjectRoleAuthority upra) -> {
        StringBuilder sb = new StringBuilder();
        sb.append(upra.getProjectId());
        sb.append(".");
        sb.append(upra.getRoleId());
        sb.append(".");
        sb.append(upra.getAuthorityId());
        authorities.add(new SimpleGrantedAuthority(sb.toString()));
    });

    return new MyUserDetails(account, authorities);
}

From source file:com.gtp.tradeapp.service.CustomUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    User user = userRepository.findByUsername(username).orElseThrow(
            () -> new UsernameNotFoundException(String.format("User %s does not exist!", username)));

    return new UserRepositoryUserDetails(user);
}

From source file:com.what2p.security.CustomUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    User user = userRepository.findByLoginName(username);
    if (user == null) {
        throw new UsernameNotFoundException(String.format("User %s does not exist!", username));
    }//from   w ww. jav  a2 s .c o m
    return new UserRepositoryUserDetails(user);
}

From source file:com.cletogadelha.sevice.CustomUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    User user = userRepository.findByLogin(username);
    if (user == null) {
        throw new UsernameNotFoundException(String.format("User %s does not exist!", username));
    }//from  w ww.  j a v a 2  s.co  m
    return new UserRepositoryUserDetails(user);
}

From source file:security.RepositoryUserDetailsService.java

/**
 * {@inheritDoc}/*  w  w  w. j a  va2  s .  c o m*/
 */
@Override
public UserDetails loadUserByUsername(String arg0) throws UsernameNotFoundException {
    for (UserDetails details : users) {
        if (details.getUsername().equals(arg0))
            return details;
    }
    throw new UsernameNotFoundException("no user with this pseudo");

}

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 {//  w  w  w .jav 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:shiver.me.timbers.security.web.spring.RepositoryUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

    final User user = userRepository.findByUsername(username);

    if (user != null) {
        return new shiver.me.timbers.security.web.spring.UserDetails(user);
    }/*from  ww  w.j a v a2 s.  c  om*/

    throw new UsernameNotFoundException("No user found for username: " + username);
}

From source file:technology.tikal.gae.system.security.dao.objectify.SystemUserDaoOfy.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    try {/*from   w w  w  .ja  v a 2  s  . c o m*/
        if (!StringUtils.isEmpty(username)) {
            return consultar(username);
        } else {
            throw new UsernameNotFoundException("UserNotFound");
        }
    } catch (NotFoundException e) {
        throw new UsernameNotFoundException("UserNotFound");
    }
}

From source file:seava.j4e.security.DefaultAuthenticationSystemUserService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

    SystemAdministratorUser u = this.repository.findByUserName(username);
    if (u == null) {
        throw new UsernameNotFoundException("Bad credentials");
    }//from ww  w .  j  a  v a 2 s.c  om
    ILoginParams lp = LoginParamsHolder.params.get();

    IClient client = new AppClient(null, null, null);
    IUserSettings settings;
    try {
        settings = AppUserSettings.newInstance(this.settings);
    } catch (InvalidConfiguration e) {
        throw new UsernameNotFoundException(e.getMessage());
    }
    IUserProfile profile = new AppUserProfile(true, u.getRoles(), false, false, false);

    String workspacePath = this.getSettings().get(Constants.PROP_WORKSPACE);

    IWorkspace ws = new AppWorkspace(workspacePath);

    IUser user = new AppUser(u.getCode(), u.getName(), u.getLoginName(), u.getPassword(), null, null, client,
            settings, profile, ws, true);

    ISessionUser su = new SessionUser(user, lp.getUserAgent(), new Date(), lp.getRemoteHost(),
            lp.getRemoteIp());
    return su;
}