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:io.github.arven.rs.services.example.UserService.java

public UserDetails loadUserByUsername(String string) throws UsernameNotFoundException {
    Person data = blogService.getUser(string);
    if (data != null) {
        return new User(data.getId(), data.getPassword(), Arrays.asList(new SimpleGrantedAuthority("User")));
    } else {//from  ww w  . j a v  a 2  s  .c om
        throw new UsernameNotFoundException("Name not found!");
    }
}

From source file:programacaovi.spring.security.FakeUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    Pessoa person = personRepository.findByNome(username);
    if (person == null) {
        throw new UsernameNotFoundException("Username " + username + " no encontrado");
    }//from w  w  w . j  a v  a  2s .com
    return new User(username, "password", getGrantedAuthorities(username));
}

From source file:th.co.geniustree.intenship.advisor.service.MyUserDetailService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    Optional<Account> findByEmail = accountRepo.findByEmail(username);
    return findByEmail.orElseThrow(() -> new UsernameNotFoundException("not found user."));
}

From source file:com.utilaider.solarsense.service.LoginServiceImpl.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    User user;/*from  w  ww  .  j  a  va  2 s  .c  o  m*/
    try {
        user = userService.getUserDetailsByUsername(username);
    } catch (Exception e) {
        throw new UsernameNotFoundException("User not found");
    }
    if (user == null) {
        throw new UsernameNotFoundException("User not found");
    }
    List<GrantedAuthority> authorities = new ArrayList<>();
    return new org.springframework.security.core.userdetails.User(user.getUserName(), user.getPassword(), true,
            true, true, true, authorities);
}

From source file:com.futuretech.service.LoginService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    Users user = userDao.findByUsername(username);

    if (user == null) {
        throw new UsernameNotFoundException("Oops!");
    }//from w  w w .  java2 s  .  c o  m

    List<SimpleGrantedAuthority> authorities = Arrays.asList(new SimpleGrantedAuthority(user.getRole()));

    return new User(user.getUsername(), user.getPassword(), authorities);
}

From source file:com.pwsz.kutadaniel.services.authentication.AccountDetailsService.java

/**
 * /* ww w.j a  va 2  s.  co m*/
 * @param username user login
 * @return user account
 * @throws UsernameNotFoundException 
 */
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    final Account account = accountRepository.findOneByLogin(username);
    if (account == null) {
        throw new UsernameNotFoundException("No user with login " + username);
    }
    return account;
}

From source file:aka.pirana.springsecurity.config.CustomUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
    User user = userService.findUserByEmail(email);
    System.out.println("aka.pirana.springsecurity.config.CustomUserDetailsService.loadUserByUsername()");
    if (user == null) {
        throw new UsernameNotFoundException("user with credentials" + email + "Not found");
    }// ww  w .j  a  va2 s  .c o  m
    return new SecurityUser(user);
}

From source file:org.cloudfoundry.identity.uaa.user.InMemoryUaaUserDatabase.java

@Override
public UaaUser retrieveUserByName(String username) throws UsernameNotFoundException {

    UaaUser u = users.get(username);/*w  w  w.jav a  2 s  .  c o  m*/
    if (u == null) {
        throw new UsernameNotFoundException("User " + username + " not found");
    }
    return u;

}

From source file:com.companyname.services.PlatCommonService.java

public UserAccount getUserAccount(AccountRepository repo, String userName) {

    if (repo == null) {
        throw new RuntimeException("System Error: No account repository is found (null)");
    }/* w w w.ja  v a2  s.  com*/

    if (userName == null) {
        throw new RuntimeException("System Error: No userName is passed (null)");
    }

    logger.info("retrieving account information for user name: " + userName);

    List<UserAccount> accounts = repo.findByLoginName(userName);

    if (accounts == null) {
        throw new UsernameNotFoundException("No user account found");
    }

    if (accounts.size() > 1) {
        throw new UsernameNotFoundException("More than one active account is found");
    }

    logger.info("user account is rertrieved from backend tables for user name: " + userName);

    return accounts.get(0);
}

From source file:hr.foi.rsc.services.PersonDetailsService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    Person user = personRepository.findByCredentialsUsername(username);
    if (user == null) {
        throw new UsernameNotFoundException(String.format("User %s does not exist!", username));
    }/*  w w  w . ja v a  2  s. c o m*/
    return new PersonRepositoryUserDetails(user);
}