List of usage examples for org.springframework.security.core.userdetails UsernameNotFoundException UsernameNotFoundException
public UsernameNotFoundException(String msg)
UsernameNotFoundException
with the specified message. From source file:com.trenako.security.AccountDetailsService.java
/** * Locates the user based on the email address. * * @param emailAddress the email address. * @return the user details.//from ww w . j av a2s .co m */ @Override public UserDetails loadUserByUsername(String emailAddress) throws UsernameNotFoundException { Account account = service.findByEmailAddress(emailAddress); if (account == null) { throw new UsernameNotFoundException("Could not find user with email " + emailAddress); } return new AccountDetails(account); }
From source file:it.smartcommunitylab.aac.oauth.UserDetailsRepo.java
@Override public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException { List<GrantedAuthority> list = Collections .<GrantedAuthority>singletonList(new SimpleGrantedAuthority("ROLE_USER")); Long id = null;//w w w. j av a 2 s .co m // expected that the user name is the numerical identifier try { id = Long.parseLong(userName); } catch (NumberFormatException e) { throw new UsernameNotFoundException("Incorrect user ID: " + userName); } it.smartcommunitylab.aac.model.User userEntity = userRepository.findOne(id); if (userEntity == null) throw new UsernameNotFoundException("User with id " + id + " does not exist."); return new User(userEntity.getId().toString(), "", list); }
From source file:org.ng200.openolympus.services.UserSecurityService.java
@Override public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException { final User user = this.userRepository.findByUsername(username); if (user == null) { throw new UsernameNotFoundException("No user with that username exists."); }/*from ww w.j a va2 s. c o m*/ return user; }
From source file:org.parancoe.plugins.securityevolution.ParancoeUserDetailsService.java
@Override public UserDetails loadUserByUsername(java.lang.String username) throws UsernameNotFoundException, DataAccessException { org.parancoe.plugins.securityevolution.User user = userDao.findByUsername(username); if (user == null) throw new UsernameNotFoundException("username " + username + " not found in the system"); List<Authority> authorities = authorityDao.findAllAuthoritiesAssociatedToUsername(username); return new User(user.getUsername(), user.getPassword(), user.isEnabled(), true, true, !user.isLocked(), authorities2GrantedAuthorities(authorities)); }
From source file:com.erudika.para.security.SimpleUserService.java
/** * Loads a user from the data store.// ww w. ja v a 2 s.c o m * @param ident the user identifier * @return a user object or null if user is not found */ public UserDetails loadUserByUsername(String ident) { User user = new User(); user.setIdentifier(ident); user = loadUser(user); if (user == null) { throw new UsernameNotFoundException(ident); } return user; }
From source file:bookmarks.WebSecurityConfiguration.java
@Bean UserDetailsService userDetailsService() { return (username) -> accountRepository.findByUsername(username) .map(a -> new User(a.username, a.password, true, true, true, true, AuthorityUtils.createAuthorityList("USER", "write"))) .orElseThrow(() -> new UsernameNotFoundException("could not find the user '" + username + "'")); }
From source file:eu.trentorise.smartcampus.permissionprovider.oauth.InternalUserDetailsRepo.java
@Override public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException { List<GrantedAuthority> list = Collections .<GrantedAuthority>singletonList(new SimpleGrantedAuthority("ROLE_USER")); Registration reg = userRepository.findByEmail(userName); if (reg == null) throw new UsernameNotFoundException("User " + userName + " not found"); if (!reg.isConfirmed()) throw new UsernameNotFoundException("Registration not confirmed"); return new User(reg.getUserId().toString(), reg.getPassword(), list); }
From source file:com.alehuo.wepas2016projekti.service.CustomUserDetailsService.java
/** * Hakee kyttjn tietokannasta ja asettaa sille oikeat kyttoikeudet * @param string Kyttjtunnus//from w w w.j a va 2 s . c o m * @return Kyttjtiedot * @throws UsernameNotFoundException */ @Override public UserDetails loadUserByUsername(String string) throws UsernameNotFoundException { UserAccount u = userRepo.findByUsernameIgnoreCase(string.trim()); if (u == null) { throw new UsernameNotFoundException("Kyttjtunnusta " + string + " ei lydy"); } return new org.springframework.security.core.userdetails.User(u.getUsername(), u.getPassword(), true, true, true, true, Arrays.asList(new SimpleGrantedAuthority(u.getRole().toString()))); }
From source file:com.javiermoreno.springboot.mvc.users.UserManagementServiceImpl.java
@Override @Transactional// ww w . j a va2 s . c o m public DailyUser loadUserByUsername(String email) throws UsernameNotFoundException { DailyUser user = userRepository.findByEmail(email); if (user == null) throw new UsernameNotFoundException(String.format("{0} email was not found.", email)); return user; }
From source file:eu.trentorise.smartcampus.permissionprovider.oauth.UserDetailsRepo.java
@Override public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException { List<GrantedAuthority> list = Collections .<GrantedAuthority>singletonList(new SimpleGrantedAuthority("ROLE_USER")); Long id = null;/* w w w. ja v a 2s . co m*/ // expected that the user name is the numerical identifier try { id = Long.parseLong(userName); } catch (NumberFormatException e) { throw new UsernameNotFoundException("Incorrect user ID: " + userName); } eu.trentorise.smartcampus.permissionprovider.model.User userEntity = userRepository.findOne(id); if (userEntity == null) throw new UsernameNotFoundException("User with id " + id + " does not exist."); return new User(userEntity.getId().toString(), "", list); }