use of org.springframework.security.core.userdetails.UsernameNotFoundException in project molgenis by molgenis.
the class UserDetailsService method loadUserByUsername.
@Override
@RunAsSystem
public UserDetails loadUserByUsername(String username) {
User user = dataService.query(UserMetaData.USER, User.class).eq(UserMetaData.USERNAME, username).findOne();
if (user == null) {
throw new UsernameNotFoundException("unknown user '" + username + "'");
}
Collection<? extends GrantedAuthority> authorities = getAuthorities(user);
return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), user.isActive(), true, true, true, authorities);
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project hello-world by haoziapple.
the class DomainUserDetailsService method loadUserByUsername.
@Override
@Transactional
public UserDetails loadUserByUsername(final String login) {
log.debug("Authenticating {}", login);
String lowercaseLogin = login.toLowerCase(Locale.ENGLISH);
Optional<User> userByEmailFromDatabase = userRepository.findOneWithAuthoritiesByEmail(lowercaseLogin);
return userByEmailFromDatabase.map(user -> createSpringSecurityUser(lowercaseLogin, user)).orElseGet(() -> {
Optional<User> userByLoginFromDatabase = userRepository.findOneWithAuthoritiesByLogin(lowercaseLogin);
return userByLoginFromDatabase.map(user -> createSpringSecurityUser(lowercaseLogin, user)).orElseThrow(() -> new UsernameNotFoundException("User " + lowercaseLogin + " was not found in the " + "database"));
});
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project vaadin-jsf-integration by alejandro-du.
the class PasswordHint method execute.
public String execute() {
getFacesContext().getViewRoot().setViewId("/passwordHint.xhtml");
// ensure that the username has been sent
if (username == null || "".equals(username)) {
log.warn("Username not specified, notifying user that it's a required field.");
addError("errors.required", getText("user.username"));
return null;
} else if (username.endsWith(".xhtml")) {
username = username.substring(0, username.indexOf(".xhtml"));
}
if (log.isDebugEnabled()) {
log.debug("Processing Password Hint...");
}
// look up the user's information
try {
User user = userManager.getUserByUsername(username);
StringBuilder msg = new StringBuilder();
msg.append("Your password hint is: ").append(user.getPasswordHint());
msg.append("\n\nLogin at: ").append(RequestUtil.getAppURL(getRequest()));
message.setTo(user.getEmail());
String subject = '[' + getText("webapp.name") + "] " + getText("user.passwordHint");
message.setSubject(subject);
message.setText(msg.toString());
mailEngine.send(message);
addMessage("login.passwordHint.sent", new Object[] { username, user.getEmail() });
} catch (UsernameNotFoundException e) {
log.warn(e.getMessage());
// If exception is expected do not rethrow
addError("login.passwordHint.error", username);
} catch (MailException me) {
addError(me.getCause().getLocalizedMessage());
}
return "success";
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project summerb by skarpushin.
the class UserDetailsServiceDefaultImpl method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String userEmail) throws UsernameNotFoundException {
try {
User user = userService.getUserByEmail(userEmail);
List<String> permissions = permissionService.findUserPermissionsForSubject(SecurityConstants.DOMAIN, user.getUuid(), null);
AuthToken authToken = null;
UserDetailsImpl ret = new UserDetailsImpl(user, null, permissions, authToken);
return ret;
} catch (UserNotFoundException e) {
throw new UsernameNotFoundException("User not found", e);
} catch (FieldValidationException e) {
throw new UsernameNotFoundException("Email provided in invalid format", e);
} catch (Throwable t) {
throw new UsernameNotFoundException("Failed to get user by email", t);
}
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project fw-cloud-framework by liuweijw.
the class AjaxAuthenticationProvider method authenticate.
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
AjaxAuthenticationToken ajaxAuthenticationToken = (AjaxAuthenticationToken) authentication;
AuthUser user = userService.findUserByMobile((String) ajaxAuthenticationToken.getPrincipal());
if (null == user)
throw new UsernameNotFoundException("登录账户[" + ajaxAuthenticationToken.getPrincipal() + "]不存在");
UserDetailsImpl userDetails = buildUserDeatils(user);
if (null == userDetails)
throw new InternalAuthenticationServiceException("登录用户[" + ajaxAuthenticationToken.getPrincipal() + "]不存在!");
AjaxAuthenticationToken authenticationToken = new AjaxAuthenticationToken(userDetails, userDetails.getAuthorities());
authenticationToken.setDetails(ajaxAuthenticationToken.getDetails());
return authenticationToken;
}
Aggregations