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.wisemapping.security.UserDetailsService.java
@Override public UserDetails loadUserByUsername(@NotNull String email) throws UsernameNotFoundException, DataAccessException { final User user = userService.getUserBy(email); if (user != null) { return new UserDetails(user, isAdmin(email)); } else {// www . j a va 2s. c om throw new UsernameNotFoundException(email); } }
From source file:com.stephengream.simplecms.authentication.SimpleCmsUserDetailsService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { CmsUser u = userDao.loadByUsername(username); if (u == null) { throw new UsernameNotFoundException(username + " not found"); }/*w ww . j a v a 2 s . co m*/ HashSet<GrantedAuthority> roles = new HashSet<>(); try { final Set<Role> userRoles = u.getRoles(); if (userRoles != null && userRoles.size() > 0) { for (Role role : userRoles) { roles.add(new SimpleGrantedAuthority(role.getRoleName())); } } } catch (Exception e) { Logger.getLogger(UserDetails.class.getName()).log(Logger.Level.INFO, e.getStackTrace()); } return new User(u.getUsername(), u.getPassHash(), roles); }
From source file:com.create.security.core.userdetails.RepositoryUserDetailsService.java
@Override public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException { final Person person = personRepository.findByLogin(username); if (person == null) { throw new UsernameNotFoundException(String.format("User does not exists : %s", username)); }/*w ww. ja va 2s .c o m*/ return new User(username, "password", getGrantedAuthorities(person)); }
From source file:cz.sohlich.workstack.security.MongoUserDetailService.java
@Override public User loadUserByUsername(String username) throws UsernameNotFoundException { cz.sohlich.workstack.domain.User user = repository.findByUsername(username); if (user != null) { return user; }//from w ww. j av a 2 s . c om throw new UsernameNotFoundException(username + "not found"); }
From source file:es.ucm.fdi.dalgs.user.service.CustomUserDetailsService.java
/** * Returns a populated {@link UserDetails} object. The username is first * retrieved from the database and then mapped to a {@link UserDetails} * object.// w ww . j av a 2 s . co m */ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { try { User domainUser = userRepository.findByUsername(username); if (domainUser == null) { domainUser = userRepository.findByEmail(username); } if (domainUser == null) { throw new UsernameNotFoundException(String.format("User %s not found", username)); } return domainUser; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.example.LoginService.java
@Override public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException { final Map<String, String> query = new HashMap<String, String>() { {/* w w w . ja v a 2 s . com*/ put("username", username); } }; try { final ResponseEntity<UserEntity> response = restTemplate .getForEntity(String.format("%s?username={username}", USER_ENDPOINT), UserEntity.class, query); final UserEntity user = response.getBody(); return new AuthenticatedUser(user); } catch (RestClientException e) { throw new UsernameNotFoundException("user [" + username + "] not found."); } }
From source file:de.dlopes.stocks.facilitator.services.impl.MyUserDetailsService.java
@Transactional // important: otherwise we can't store the many-to-many rel. @Override // between user and userRole public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User user = userRepo.findByUsername(username); if (user == null) { throw new UsernameNotFoundException(username + " does not exist"); } else if (user.getRoles().isEmpty()) { throw new UsernameNotFoundException("User" + username + " has no authorities"); }// w ww .j a va 2 s . co m return buildUserDetails(user); }
From source file:com.redhat.rhtracking.web.domain.SecureUser.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Map<String, Object> request = new HashMap<>(); request.put("username", username); Map<String, Object> response = service.findByUsername(request); if (response.get("status") != EventStatus.SUCCESS) throw new UsernameNotFoundException("User not found"); Collection<GrantedAuthority> roles = new ArrayList<>(); for (String s : (List<String>) response.get("roles")) { roles.add(new SimpleGrantedAuthority(s)); }//from w w w .j a va 2s . c o m return new User((String) response.get("username"), (String) response.get("password"), (boolean) response.get("enabled"), (boolean) response.get("accountNonExpired"), (boolean) response.get("credentialsNonExpired"), (boolean) response.get("accountNonLocked"), roles); }
From source file:net.nan21.dnet.core.security.DefaultAuthenticationSystemUserService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { SystemAdministratorUser u = this.repository.findByUserName(username); LoginParams lp = LoginParamsHolder.params.get(); IClient client = new DnetClient(null, null, null); IUserSettings settings;//from ww w. j a va2 s. c om try { settings = DnetUserSettings.newInstance(this.settings); } catch (InvalidConfiguration e) { throw new UsernameNotFoundException(e.getMessage()); } IUserProfile profile = new DnetUserProfile(true, u.getRoles(), false, false, false); String workspacePath = this.getSettings().get(Constants.PROP_WORKSPACE); IWorkspace ws = new DnetWorkspace(workspacePath); IUser user = new DnetUser(u.getCode(), u.getName(), u.getLoginName(), u.getPassword(), null, null, client, settings, profile, ws, true); ISessionUser su = new DnetSessionUser(user, lp.getUserAgent(), new Date(), lp.getRemoteHost(), lp.getRemoteIp()); return su; }
From source file:org.smigo.user.authentication.UsernameUserDetailsService.java
public User getUser(String username) { final List<User> byUsername = userDao.getUsersByUsername(username); if (!byUsername.isEmpty()) { return byUsername.get(0); }// w ww. j a va2 s .c om final List<User> byEmail = userDao.getUsersByEmail(username); if (!byEmail.isEmpty()) { return byEmail.get(0); } throw new UsernameNotFoundException("User not found:" + username); }