List of usage examples for org.springframework.security.core.userdetails UsernameNotFoundException UsernameNotFoundException
public UsernameNotFoundException(String msg)
UsernameNotFoundException
with the specified message. From source file:de.steilerdev.myVerein.server.security.UserAuthenticationService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { logger.debug("Loading user " + username); User user = userRepository.findByEmail(username); if (user == null) { logger.warn("Unable to find user with username " + username); throw new UsernameNotFoundException("Could not find user " + username); } else {//from w w w . j a v a2 s . c o m user.setAuthorities(getUserAuthorities(user)); return user; } }
From source file:com.github.djabry.platform.service.security.DefaultUserDetailsService.java
/** * Locates the user based on the username. In the actual implementation, the search may possibly be case * sensitive, or case insensitive depending on how the implementation instance is configured. In this case, the * <code>UserDetails</code> object that comes back may have a username that is of a different case than what was * actually requested..// w w w. ja va2 s . c o m * * @param username the username identifying the user whose data is required. * @return a fully populated user record (never <code>null</code>) * @throws org.springframework.security.core.userdetails.UsernameNotFoundException if the user could not be found or the user has no GrantedAuthority */ @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { BooleanExpression expression = QDBUserAccount.dBUserAccount.user.username.eq(username); DBUserAccount account = userDBRepository.findOne(expression); if (account != null) { UserDetails userDetails = userDetailsFactory.from(account); return userDetails; } throw new UsernameNotFoundException(username + " does not exist!"); }
From source file:org.exoplatform.acceptance.security.CrowdUserDetailsServiceMock.java
/** * {@inheritDoc}//from ww w .j a va 2 s . com * Locates the user based on the username. In the actual implementation, the search may possibly be case * insensitive, or case insensitive depending on how the implementation instance is configured. In this case, the * <code>UserDetails</code> object that comes back may have a username that is of a different case than what was * actually requested.. */ @Override public ICrowdUserDetails loadUserByUsername(String username) throws UsernameNotFoundException { if (user.getUsername().equals(username)) { return user; } else if (administrator.getUsername().equals(username)) { return administrator; } else { throw new UsernameNotFoundException("Unknown user : " + username); } }
From source file:com.mobileman.moments.core.security.UserSecurityService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { final UserDetail userDetail; if (username.equalsIgnoreCase(this.adminUsername)) { userDetail = new UserDetail(this.adminUsername, this.adminPassword, UserRole.ADMIN, null); } else {//from w w w. ja va 2 s.c o m User sysUser = getUserDetail(username); if (sysUser == null) { throw new UsernameNotFoundException("User with email " + username + " not found"); } // check for user exists HttpServletRequest request = getHttpServletRequest(); String tokenB64 = request.getHeader("AuthorizationToken"); if (tokenB64 != null && !"".equals(tokenB64)) { String token = null; try { token = new String(Base64.getDecoder().decode(tokenB64), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } UserCacheInfo userCacheInfo = cache.get(username); if (userCacheInfo != null) { synchronized (userCacheInfo) { sanitizeUserCacheInfo(userCacheInfo); // try to find token Date lastAccess = userCacheInfo.getTokens().get(token); if (lastAccess != null) { userCacheInfo.getTokens().put(token, new Date()); userDetail = getUserDetailsAuthenticated(sysUser); } else { // new device... userDetail = getUserDetailsPasswordCheck(sysUser, username, token); } } } else { userDetail = getUserDetailsPasswordCheck(sysUser, username, token); } } else { userDetail = getUserDetails(sysUser); } } return userDetail; }
From source file:com.organization.projectname.service.impl.UserServiceImpl.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { log.info(String.format("Load user by username '%s'.", username)); User user = userRepository.findByUsername(username); if (user == null) { throw new UsernameNotFoundException("Invalid credential"); } else {//from w w w .j a v a 2s . c om return user; } }
From source file:org.mitre.openid.connect.client.OIDCAuthenticationProvider.java
@Override public Authentication authenticate(final Authentication authentication) throws AuthenticationException { if (!supports(authentication.getClass())) { return null; }/*ww w. j a va2 s . c o m*/ if (authentication instanceof PendingOIDCAuthenticationToken) { PendingOIDCAuthenticationToken token = (PendingOIDCAuthenticationToken) authentication; // get the ID Token value out JWT idToken = token.getIdToken(); // load the user info if we can UserInfo userInfo = userInfoFetcher.loadUserInfo(token); if (userInfo == null) { // user info not found -- could be an error, could be fine } else { // if we found userinfo, double check it if (!Strings.isNullOrEmpty(userInfo.getSub()) && !userInfo.getSub().equals(token.getSub())) { // the userinfo came back and the user_id fields don't match what was in the id_token throw new UsernameNotFoundException("user_id mismatch between id_token and user_info call: " + token.getSub() + " / " + userInfo.getSub()); } } return createAuthenticationToken(token, authoritiesMapper.mapAuthorities(idToken, userInfo), userInfo); } return null; }
From source file:org.jasig.schedassist.web.security.DelegateCalendarAccountUserDetailsServiceImpl.java
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException, DataAccessException { if (NONE_PROVIDED.equals(username)) { LOG.debug("caught NONE_PROVIDED being passed into loadUserByUsername"); throw new UsernameNotFoundException(NONE_PROVIDED); }/*from www . j a v a 2 s.c o m*/ CalendarAccountUserDetailsImpl currentUser = (CalendarAccountUserDetailsImpl) SecurityContextHolder .getContext().getAuthentication().getPrincipal(); IDelegateCalendarAccount delegate = this.delegateCalendarAccountDao.getDelegate(username, currentUser.getCalendarAccount()); if (null == delegate) { throw new UsernameNotFoundException("no delegate account found with name " + username); } IScheduleOwner delegateOwner = ownerDao.locateOwner(delegate); DelegateCalendarAccountUserDetailsImpl result = new DelegateCalendarAccountUserDetailsImpl(delegate, delegateOwner); return result; }
From source file:org.socialhistoryservices.security.MongoUserDetailService.java
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { UserDetails userDetails = getUser(username); if (userDetails == null) { throw new UsernameNotFoundException("Query returned no results for user '" + username + "'"); }// w w w . j a v a 2s . co m return userDetails; }
From source file:com.github.jguaneri.notifications.service.impl.UserServiceImpl.java
@Transactional @Override//from w ww . j ava2 s . com public User retrieveUserByName(final String username) { final List<User> users = userRepository.query(new UserSpecificationByUsername(username)); if (users.size() == 0) { throw new UsernameNotFoundException("Cannot find a user with specified username: " + username); } if (users.size() > 1) { throw new UsernameNotFoundException("Expected to find 1 user found: " + users.size()); } return users.get(0); }
From source file:org.dhara.CustomUserService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { logger.info("Custom User Service called to get user information"); final User user = userRepository.getByUsername(username); if (user == null) { throw new UsernameNotFoundException("User with username '" + username + "' was not found!"); }//w ww .ja va2 s . com fetchCustomCredential(user); return user; }