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.duracloud.account.db.util.impl.DuracloudUserServiceImpl.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { try {/*from w ww.ja v a 2 s. c om*/ return loadDuracloudUserByUsername(username); } catch (DBNotFoundException e) { throw new UsernameNotFoundException(e.getMessage()); } }
From source file:de.thm.arsnova.service.UserServiceImpl.java
@Override public User loadUser(final UserProfile.AuthProvider authProvider, final String loginId, final Collection<GrantedAuthority> grantedAuthorities, final boolean autoCreate) throws UsernameNotFoundException { logger.debug("Load user: LoginId: {}, AuthProvider: {}", loginId, authProvider); UserProfile userProfile = userRepository.findByAuthProviderAndLoginId(authProvider, loginId); if (userProfile == null) { if (autoCreate) { userProfile = new UserProfile(authProvider, loginId); /* Repository is accessed directly without EntityService to skip permission check */ userRepository.save(userProfile); } else {/*from ww w .j a v a 2 s. c om*/ throw new UsernameNotFoundException("User does not exist."); } } return new User(userProfile, grantedAuthorities); }
From source file:de.thm.arsnova.service.UserServiceImpl.java
@Override public User loadUser(final String userId, final Collection<GrantedAuthority> grantedAuthorities) throws UsernameNotFoundException { logger.debug("Load user: UserId: {}", userId); UserProfile userProfile = userRepository.findOne(userId); if (userProfile == null) { throw new UsernameNotFoundException("User does not exist."); }//from w w w . j av a2 s . com return new User(userProfile, grantedAuthorities); }
From source file:com.consult.app.controller.WebController.java
/** * Accepts a POST request with an XML message parameter * @param message serialized Message object * @return a string with the result of the POST *//* w ww . jav a 2 s. c o m*/ @RequestMapping(value = "completeunregisteruser", method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public @ResponseBody ResultResponse completeUnregisterUserByAdmin(@RequestBody CompleteUnregisterRequest req, //TelephoneRequest req, HttpServletResponse response, HttpServletRequest request) { ResultResponse rp = new ResultResponse(); rp.setResult(Cookie.RESPONSE_BAD_REQUEST); String strId = SecurityContextHolder.getContext().getAuthentication().getName(); if (CompleteUnregisterRequest.checkParameters(req) <= 0) { return rp; } if (Cookie.isPublishUser(strId)) { long pubId = Cookie.checkPublishUser(strId); return completeUnregisterBySales(req, pubId, Constant.TYPE_DONE); } // if (Cookie.isSalesmanUser(strId)) { // long salesId = Cookie.checkSalesmanUser(strId); // return completeUnregisterBySales(req, salesId, Constant.TYPE_UPDATE_BY_SALES); // } throw new UsernameNotFoundException("not publish user"); }
From source file:org.activiti.app.security.UserDetailsService.java
@Override @Transactional//from www.j ava 2s. c o m public UserDetails loadUserByUsername(final String login) { // This method is only called during the login. // All subsequent calls use the method with the long userId as parameter. // (Hence why the cache is NOT used here, but it is used in the loadByUserId) String actualLogin = login; User userFromDatabase = null; actualLogin = login.toLowerCase(); userFromDatabase = identityService.createUserQuery().userId(actualLogin).singleResult(); // Verify user if (userFromDatabase == null) { throw new UsernameNotFoundException("User " + actualLogin + " was not found in the database"); } // Add capabilities to user object Collection<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>(); // add default authority grantedAuthorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.USER)); // check if user is in super user group String superUserGroupName = env.getRequiredProperty("admin.group"); for (Group group : identityService.createGroupQuery().groupMember(userFromDatabase.getId()).list()) { if (StringUtils.equals(superUserGroupName, group.getName())) { grantedAuthorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.ADMIN)); } } // Adding it manually to cache userCache.putUser(userFromDatabase.getId(), new CachedUser(userFromDatabase, grantedAuthorities)); return new ActivitiAppUser(userFromDatabase, actualLogin, grantedAuthorities); }
From source file:org.activiti.app.security.UserDetailsService.java
@Transactional public UserDetails loadByUserId(final String userId) { CachedUser cachedUser = userCache.getUser(userId, true, true, false); // Do not check for validity. This would lead to A LOT of db requests! For login, there is a validity period (see below) if (cachedUser == null) { throw new UsernameNotFoundException("User " + userId + " was not found in the database"); }/* w ww. j a v a2s . c o m*/ long lastDatabaseCheck = cachedUser.getLastDatabaseCheck(); long currentTime = System.currentTimeMillis(); // No need to create a Date object. The Date constructor simply calls this method too! if (userValidityPeriod <= 0L || (currentTime - lastDatabaseCheck >= userValidityPeriod)) { userCache.invalidate(userId); cachedUser = userCache.getUser(userId, true, true, false); // Fetching it again will refresh data cachedUser.setLastDatabaseCheck(currentTime); } // The Spring security docs clearly state a new instance must be returned on every invocation User user = cachedUser.getUser(); String actualUserId = user.getEmail(); return new ActivitiAppUser(cachedUser.getUser(), actualUserId, cachedUser.getGrantedAuthorities()); }
From source file:org.apache.ambari.server.security.authorization.AmbariLocalUserDetailsService.java
/** * Loads Spring Security UserDetails from identity storage according to Configuration * * @param username username//from w w w . j a v a 2 s . c o m * @return UserDetails * @throws UsernameNotFoundException when user not found or have empty roles */ @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { log.info("Loading user by name: " + username); UserEntity user = userDAO.findLocalUserByName(username); if (user == null || !StringUtils.equals(user.getUserName(), username)) { //TODO case insensitive name comparison is a temporary solution, until users API will change to use id as PK log.info("user not found "); throw new UsernameNotFoundException("Username " + username + " not found"); } // get all of the privileges for the user List<PrincipalEntity> principalEntities = new LinkedList<PrincipalEntity>(); principalEntities.add(user.getPrincipal()); List<MemberEntity> memberEntities = memberDAO.findAllMembersByUser(user); for (MemberEntity memberEntity : memberEntities) { principalEntities.add(memberEntity.getGroup().getPrincipal()); } List<PrivilegeEntity> privilegeEntities = privilegeDAO.findAllByPrincipal(principalEntities); return new User(user.getUserName(), user.getUserPassword(), user.getActive(), true, true, true, authorizationHelper.convertPrivilegesToAuthorities(privilegeEntities)); }
From source file:org.apache.atlas.web.dao.UserDao.java
public User loadUserByUsername(final String username) throws AuthenticationException { String userdetailsStr = userLogins.getProperty(username); if (userdetailsStr == null || userdetailsStr.isEmpty()) { throw new UsernameNotFoundException("Username not found." + username); }// www.j a v a2 s.c om String password = ""; String role = ""; String dataArr[] = userdetailsStr.split("::"); if (dataArr != null && dataArr.length == 2) { role = dataArr[0]; password = dataArr[1]; } else { LOG.error("User role credentials is not set properly for {}", username); throw new AtlasAuthenticationException("User role credentials is not set properly for " + username); } List<GrantedAuthority> grantedAuths = new ArrayList<>(); if (StringUtils.hasText(role)) { grantedAuths.add(new SimpleGrantedAuthority(role)); } else { LOG.error("User role credentials is not set properly for {}", username); throw new AtlasAuthenticationException("User role credentials is not set properly for " + username); } User userDetails = new User(username, password, grantedAuths); return userDetails; }
From source file:org.apache.kylin.rest.service.LegacyUserService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Table htable = null;//from w ww .j a va2 s.com try { htable = aclHBaseStorage.getTable(userTableName); Get get = new Get(Bytes.toBytes(username)); get.addFamily(Bytes.toBytes(AclHBaseStorage.USER_AUTHORITY_FAMILY)); Result result = htable.get(get); User user = hbaseRowToUser(result); if (user == null) throw new UsernameNotFoundException("User " + username + " not found."); return user; } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(htable); } }
From source file:org.apache.kylin.rest.service.UserService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { HTableInterface htable = null;/*from www . jav a 2 s . co m*/ try { htable = aclHBaseStorage.getTable(userTableName); Get get = new Get(Bytes.toBytes(username)); get.addFamily(Bytes.toBytes(AclHBaseStorage.USER_AUTHORITY_FAMILY)); Result result = htable.get(get); User user = hbaseRowToUser(result); if (user == null) throw new UsernameNotFoundException("User " + username + " not found."); return user; } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(htable); } }