List of usage examples for org.springframework.security.core.userdetails UsernameNotFoundException UsernameNotFoundException
public UsernameNotFoundException(String msg)
UsernameNotFoundException
with the specified message. From source file:org.springframework.security.ldap.search.FilterBasedLdapUserSearch.java
/** * Return the LdapUserDetails containing the user's information * * @param username the username to search for. * * @return An LdapUserDetails object containing the details of the located user's * directory entry/*from ww w. j a v a2s .c o m*/ * * @throws UsernameNotFoundException if no matching entry is found. */ @Override public DirContextOperations searchForUser(String username) { if (logger.isDebugEnabled()) { logger.debug("Searching for user '" + username + "', with user search " + this); } SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(contextSource); template.setSearchControls(searchControls); try { return template.searchForSingleEntry(searchBase, searchFilter, new String[] { username }); } catch (IncorrectResultSizeDataAccessException notFound) { if (notFound.getActualSize() == 0) { throw new UsernameNotFoundException("User " + username + " not found in directory."); } // Search should never return multiple results if properly configured, so just // rethrow throw notFound; } }
From source file:org.springframework.security.provisioning.InMemoryUserDetailsManager.java
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { UserDetails user = users.get(username.toLowerCase()); if (user == null) { throw new UsernameNotFoundException(username); }//w w w . j a v a 2 s . co m return new User(user.getUsername(), user.getPassword(), user.isEnabled(), user.isAccountNonExpired(), user.isCredentialsNonExpired(), user.isAccountNonLocked(), user.getAuthorities()); }
From source file:org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServicesTests.java
void udsWillThrowNotFound() { when(uds.loadUserByUsername(any(String.class))).thenThrow(new UsernameNotFoundException("")); }
From source file:org.taverna.server.master.identity.UserStore.java
@Override @WithinSingleTransaction/*from w w w .j a v a 2s. c o m*/ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { User u; if (base != null) { log.warn("bootstrap user store still installed!"); BootstrapUserInfo ud = base.get(username); if (ud != null) { log.warn("retrieved production credentials for " + username + " from bootstrap store"); u = ud.get(encoder); if (u != null) return u; } } try { u = detach(getById(username)); } catch (NullPointerException npe) { throw new UsernameNotFoundException("who are you?"); } catch (Exception ex) { throw new UsernameNotFoundException("who are you?", ex); } if (u != null) return u; throw new UsernameNotFoundException("who are you?"); }
From source file:org.tightblog.ui.security.CustomUserDetailsService.java
/** * @throws UsernameNotFoundException, DataAccessException *///from ww w . j a va 2 s . c o m @Override public UserDetails loadUserByUsername(String userName) { if (!dynamicProperties.isDatabaseReady()) { // Should only happen in case of 1st time startup, setup required // Thowing a "soft" exception here allows setup to proceed throw new UsernameNotFoundException("User info not available yet."); } UserCredentials creds = userCredentialsRepository.findByUserName(userName); GlobalRole targetGlobalRole; String targetPassword; if (creds == null) { throw new UsernameNotFoundException("ERROR no user: " + userName); } targetPassword = creds.getPassword(); // If MFA required & user hasn't a secret for Google Authenticator, limit role // to PRE_AUTH_USER (intended to limit user to QR code scan page.) if (mfaEnabled && StringUtils.isBlank(creds.getMfaSecret())) { targetGlobalRole = GlobalRole.MISSING_MFA_SECRET; } else { targetGlobalRole = creds.getGlobalRole(); } List<SimpleGrantedAuthority> authorities = new ArrayList<>(1); authorities.add(new SimpleGrantedAuthority(targetGlobalRole.name())); return new org.springframework.security.core.userdetails.User(userName, targetPassword, true, true, true, true, authorities); }
From source file:piecework.ldap.CustomLdapUserDetailsService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { if (LOG.isDebugEnabled()) LOG.debug("Looking for user by uniqueId " + username); if (StringUtils.isEmpty(username)) return null; if (authenticationPrincipalConverter != null) username = authenticationPrincipalConverter.convert(username); Cache.ValueWrapper wrapper = cacheService.get(CacheName.IDENTITY, username); UserDetails userDetails = null;/*from w w w. j a va 2 s. c om*/ if (wrapper != null) { userDetails = (UserDetails) wrapper.get(); if (userDetails == null) throw new UsernameNotFoundException(username); return userDetails; } if (LOG.isDebugEnabled()) LOG.debug("Retrieving user by uniqueId " + username); try { DirContextOperations userData = userSearch.searchForUser(username); String actualUserName = userData.getStringAttribute(ldapSettings.getLdapGroupMemberUserName()); if (StringUtils.isEmpty(actualUserName)) { LOG.info( "No property ldap.group.member.username defined, assuming that person username attribute is the same as the group member attribute"); actualUserName = username; } userDetails = userDetailsMapper.mapUserFromContext(userData, username, authoritiesPopulator.getGrantedAuthorities(userData, actualUserName)); } finally { cacheService.put(CacheName.IDENTITY, username, userDetails); } return userDetails; }
From source file:ro.nextreports.server.security.DatabaseExternalUsersService.java
@SuppressWarnings("unchecked") public User getUser(String username) throws UsernameNotFoundException, DataAccessException { List<User> users = userByUsernameMapping.execute(username); if (users.size() == 0) { throw new UsernameNotFoundException("User '" + username + "' not found"); }//from w ww. j av a 2s . com User user = (User) users.get(0); return user; }
From source file:rusch.megan6server.TextFileAuthentication.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { UserDetails ud = name2tokens.get(username); if (ud == null) { throw new UsernameNotFoundException("No user with name: " + username); }//from ww w . j a va 2 s. c om return new User(ud.getUsername(), ud.getPassword(), ud.getAuthorities()); }
From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalUserServiceImpl.java
@Override @CheckOwncloudModification//from w w w.jav a2 s . c o m public void delete(String username) { Validate.notBlank(username); if (getLocalUserDataService().userNotExists(username)) { log.error("User {} doesn't exist", username); throw new UsernameNotFoundException(username); } log.debug("Remove User {}", username); getLocalUserDataService().removeUser(username); log.debug("Notify registered Listeners about removed User {}", username); deleteUserListeners.forEach(listener -> listener.accept(username)); log.info("User {} successfully removed", username); }
From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalUtils.java
public static void validateUserNotNull(OwncloudLocalUserData.User user, String username) { if (user == null) { throw new UsernameNotFoundException(username); }/*from w w w. j a va 2 s .c om*/ }