List of usage examples for org.springframework.security.core.userdetails UsernameNotFoundException UsernameNotFoundException
public UsernameNotFoundException(String msg)
UsernameNotFoundException
with the specified message. From source file:rzd.vivc.documentexamination.service.UserService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Account account = accountRepository.findByLogin(username); if (account != null) { List<GrantedAuthority> autiriries = new ArrayList<>(); autiriries.add(new SimpleGrantedAuthority(account.getUserType().getAutority())); return new User(account.getLogin(), account.getPassword(), autiriries); }/*from w ww. j a v a2 s . c o m*/ throw new UsernameNotFoundException(" " + username + " ."); }
From source file:fr.lepellerin.ecole.service.security.internal.GestEcoleUserDetailsServiceImpl.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User user = userService.getUserByUsername(username); if (user == null) { throw new UsernameNotFoundException("Impossible de trouver l'utilisateur " + username); }/*from w w w . j ava2 s. c o m*/ return new CurrentUser(user); }
From source file:com.gcrm.security.UserDetailsServiceImpl.java
public UserDetails loadUserByUsername(String username) { UserDetailsImpl userDetails = new UserDetailsImpl(); User user = null;/*from ww w . j av a 2s.c o m*/ try { user = userService.findByName(username); } catch (Exception e) { throw new UsernameNotFoundException("Error found in getting user"); } if (user == null) { throw new UsernameNotFoundException("Hasn't found user information."); } if (UserStatus.STATUS_INACTIVE.equalsIgnoreCase(user.getStatus().getValue())) { throw new RuntimeException("User hasn't been actived!"); } userDetails.setUsername(user.getName()); String password = user.getPassword(); if (password == null) { password = ""; } userDetails.setPassword(user.getPassword()); userDetails.setCredentialsNonExpired(true); userDetails.setAccountNonExpired(true); userDetails.setAccountNonLocked(true); userDetails.setEnabled(true); Set<Role> roles = user.getRoles(); ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (Role role : roles) { SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(role.getName()); authorities.add(grantedAuthority); try { UserUtil.setAccessValue(role, user); } catch (Exception e) { throw new RuntimeException("Failed to set the Access value"); } } userDetails.setAuthorities(authorities); userDetails.setUser(user); return userDetails; }
From source file:org.springrestoauth.configuration.CustomUserDetailsService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Student user = studentRepository.findByNameEquals(username); if (user == null) { throw new UsernameNotFoundException(String.format("User %s does not exist!", username)); }//from w w w . j a v a 2s . c o m return new UserRepositoryUserDetails(user); }
From source file:com.innominds.web.service.AuthenticationService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { final UserEntity personEntity = userRepository.findByUsername(username); if (personEntity == null) { throw new UsernameNotFoundException(String.format("Person %s does not exist!", username)); }/*w w w . j ava2 s . c o m*/ final User user = new User(); user.setId(personEntity.getId()); user.setUsername(personEntity.getUsername()); user.setPassword(personEntity.getPassword()); // this will be verified on AuthenticationProvider user.setAccountNonExpired(true); user.setAccountNonLocked(true); user.setCredentialsNonExpired(true); user.setEnabled(true); for (final AuthorityEntity authorityEntity : personEntity.getAuthorities()) { user.getAuthorities().add(new Authority(authorityEntity.getAuthority(), authorityEntity.getTitle())); } return user; }
From source file:uk.co.threeonefour.ifictionary.web.security.service.UserDetailsServiceImpl.java
@Override public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException { uk.co.threeonefour.ifictionary.web.user.model.User userEntity; userEntity = userDao.findUser(userId); if (userEntity == null) { throw new UsernameNotFoundException("user name not found"); }//from w w w. j a va2s . c o m return buildUserFromUserEntity(userEntity); }
From source file:com.bcknds.demo.oauth2.service.impl.UserServiceImpl.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { for (User user : users) { if (user.getUsername().equals(username)) { return user; }/* w ww .j a va 2 s . com*/ } throw new UsernameNotFoundException(String.format("The user with username %s does not exist", username)); }
From source file:com.jd.survey.service.security.JDUserDetailsService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { try {/*from w w w .j a v a 2 s. c o m*/ User user = userDAO.findByLogin(username); if (user != null) { return user; } else { throw new UsernameNotFoundException("Could not find a user with the provided login"); } } catch (Exception e) { log.error(e); throw new RuntimeException(e); } }
From source file:org.web4thejob.security.UserDetailsServiceImpl.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { Query query = ContextUtil.getEntityFactory().buildQuery(UserIdentity.class); query.addCriterion(new Path(UserIdentity.FLD_USERNAME), Condition.EQ, username); UserIdentity userIdentity = ContextUtil.getDRS().findUniqueByQuery(query); if (userIdentity == null) { throw new UsernameNotFoundException(username); }/*w w w. j a v a 2s . c o m*/ return new UserDetailsExImpl(userIdentity); }
From source file:net.thewaffleshop.nimbus.service.AccountUserDetailsService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Account account = accountRepository.findByUserName(username); if (account == null) { throw new UsernameNotFoundException(username); }// w w w .j a v a 2s . c o m List<GrantedAuthority> roles = AuthorityUtils.createAuthorityList("ROLE_USER"); AccountUser ret = new AccountUser(account.getUserName(), account.getPasswordHash(), roles); ret.setAccount(account); return ret; }