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.mycompany.springrest.web.controller.UserLoginService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    com.mycompany.springrest.model.User myUser = userDAO.getUserByName(username);

    if (myUser == null)
        throw new UsernameNotFoundException("user not found");

    StringBuilder code = new StringBuilder();
    MessageDigest messageDigest = null;
    try {/*from   w  w w.  ja v  a  2 s .  c  om*/
        messageDigest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(UserLoginService.class.getName()).log(Level.SEVERE, null, ex);
    }
    byte[] bytes = myUser.getPassWord().trim().getBytes();
    byte[] digest = messageDigest.digest(bytes); //create code
    for (int i = 0; i < digest.length; ++i) {
        code.append(Integer.toHexString(0x0100 + (digest[i] & 0x00FF)).substring(1));
    }
    UserDetails u = new User(username, code.toString(), true, true, true, true,
            getAuthority(roleDAO.listRoles(username)));

    //        UserDetails u= new User(username, myUser.getPassword(), true, true, true, true, getAuthority(myUser.getRole()));
    //System.out.println("userdetails: "+u.getUsername()+" "+u.getPassword());            
    return u;
}

From source file:net.triptech.metahive.service.OpenIdUserDetailsService.java

/**
 * Implementation of {@code UserDetailsService}. We only need this to
 * satisfy the {@code RememberMeServices} requirements.
 *///from  w ww .  j ava  2 s  .  c o  m
public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException {

    List<Person> people = Person.findPeopleByOpenIdIdentifier(id).getResultList();

    Person person = people.size() == 0 ? null : people.get(0);

    if (person == null) {
        throw new UsernameNotFoundException(id);
    }
    if (!person.isEnabled()) {
        throw new DisabledException("This user is disabled");
    }

    return person;
}

From source file:com.kazuki43zoo.jpetstore.service.AccountUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    return Optional.ofNullable(accountMapper.getAccountByUsername(username)).map(AccountUserDetails::new)
            .orElseThrow(() -> new UsernameNotFoundException(username));
}

From source file:com.seyren.core.security.mongo.MongoUserDetails.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    User user = getUser(username);// w  w  w  .j  a  va  2s .c o m
    if (user == null) {
        throw new UsernameNotFoundException("The user with name " + username + " could not be found");
    }

    return user;
}

From source file:org.nekorp.workflow.backend.security.service.WorkflowUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    WorkflowUserDetails userDetails = userSecurityDAO.loadUserByName(username);
    if (userDetails == null) {
        throw new UsernameNotFoundException("");
    }/* www .java2s .c  o  m*/
    return userDetails;
}

From source file:org.darwinathome.server.persistence.UserService.java

public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException, DataAccessException {
    try {//w  w w. j  a  va 2 s .  c  o  m
        Player player = storage.get(email);
        if (player == null) {
            throw new UsernameNotFoundException("Never heard of " + email);
        }
        player.appeared();
        return new PlayerUserDetails(player);
    } catch (Exception e) {
        throw new DataRetrievalFailureException("Storage problem", e);
    }
}

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

@Override
public UaaUser retrieveUserByName(String username) throws UsernameNotFoundException {
    if (user.getUsername().equals(username)) {
        return user;
    } else {//from w w  w . j  a va  2  s.com
        throw new UsernameNotFoundException(username);
    }
}

From source file:com.mothsoft.alexis.service.security.AlexisUserDetailsService.java

@Transactional
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    final com.mothsoft.alexis.domain.User user = this.dao.findUserByUsername(username);

    if (user == null) {
        throw new UsernameNotFoundException("username");
    }/*  w ww.  j a  va  2s.  c o m*/

    return new UserAuthenticationDetails(user);
}

From source file:capital.scalable.restdocs.example.security.CustomUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    // Usually, you would consult a database, but for simplicity we hardcode a user
    // with username "test" and password "test".
    if ("test".equals(username)) {
        return new User(username, "test", Collections.<GrantedAuthority>emptyList());
    } else {//from   w  w w .  ja v  a 2  s  .  c om
        throw new UsernameNotFoundException(String.format("User %s does not exist!", username));
    }
}

From source file:com.sivalabs.jcart.admin.security.CustomUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String userEmail) {
    User user = securityService.findUserByEmail(userEmail);
    if (isNull(user)) {
        throw new UsernameNotFoundException("Email " + userEmail + " not found");
    }// w w  w  .  ja va  2 s  .  c o m
    return new AuthenticatedUser(user);
}