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.javiermoreno.springboot.rest.CustomUserDetailsService.java

@Override
//@Cacheable/*w w  w .j  ava  2 s  .  c  o  m*/
public CustomUserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    CustomUserDetails userDetails = (CustomUserDetails) em.createNamedQuery("findByUsername")
            .setParameter("username", username).getSingleResult();
    if (userDetails == null)
        throw new UsernameNotFoundException(String.format("{0} username was not found.", username));
    return userDetails;
}

From source file:org.terasoluna.tourreservation.domain.service.userdetails.ReservationUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    Customer customer = customerRepository.findOne(username);
    if (customer == null) {
        throw new UsernameNotFoundException(username + " is not found."); // TODO to property file
    }/*from  w w w  .  j a v  a2 s  .  c o m*/
    return new ReservationUserDetails(customer);
}

From source file:com.imps.struts2base.servicio.impl.UsuarioServiceImpl.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    Usuario usuario = null;//  w w  w  .  j a va2 s .co  m
    List<Usuario> usuarios = usuarioDAO.buscarUsuarioPorCodigo(username);
    if (usuarios.size() == 0)
        throw new UsernameNotFoundException("Usuario no existe.");
    else {
        usuario = usuarios.get(0);
        usuario.setPerfiles(usuarioDAO.buscarSectoresDeUsuariosPorCodigo(username));
        return usuario;
    }
}

From source file:io.github.proxyprint.kitchen.models.repositories.UserService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    User u = userDAO.findByUsername(username);
    if (u == null) {
        throw new UsernameNotFoundException("Username not found: " + username);
    }/*w w w . j a  v a2  s .c  o m*/
    return new org.springframework.security.core.userdetails.User(username, u.getPassword(), u.getRoles());
}

From source file:cz.cvut.kbss.wpa.service.impl.UserDetailServiceImpl.java

@Transactional
public UserDetails loadUserByUsername(String string) throws UsernameNotFoundException {
    UserDTO dto;/*from ww w .  j a va2s.  com*/
    dto = userService.getUserByName(string);
    if (dto == null) {
        throw new UsernameNotFoundException("Username " + string + " does not exist");//TODO add transaltion
    }

    List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
    authorities.addAll(dto.getGrantedAuthorities());
    CurrentUserDetails curr = new CurrentUserDetails(authorities);
    curr.setUserDto(dto);
    return curr;
}

From source file:com.mycompany.thymeleafspringapp.service.UserService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    Users user = usersDAO.getUserByName(username);
    if (user == null) {
        throw new UsernameNotFoundException("Couldn't find the user " + username);
    }// w ww.  j a  v a  2  s  . co  m
    return new UserDetailsService(user);
}

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

public void updateUser(String username, UaaUser user) throws UsernameNotFoundException {

    if (!users.containsKey(username)) {
        throw new UsernameNotFoundException("User " + username + " not found");
    }/*w w  w  .j a  va 2 s.  com*/
    users.put(username, user);
}

From source file:org.mzd.shap.domain.authentication.UserAdminServiceImpl.java

public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    User user = getUserDao().findByField("username", username);
    if (user == null) {
        throw new UsernameNotFoundException(username);
    }// w ww .  ja va  2 s.  c  o m
    return user;
}

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

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

    return new PersonRepositoryUserDetails(user);
}

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

@Transactional(readOnly = true)

@Override/*w ww  .j  a  va2s.  c  o  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));
}