use of org.springframework.security.core.userdetails.UsernameNotFoundException in project dhis2-core by dhis2.
the class DefaultClientDetailsUserDetailsService method loadUserByUsername.
public UserDetails loadUserByUsername(String username) {
ClientDetails clientDetails;
try {
clientDetails = clientDetailsService.loadClientByClientId(username);
} catch (NoSuchClientException e) {
throw new UsernameNotFoundException(e.getMessage(), e);
}
String clientSecret = clientDetails.getClientSecret();
if (clientSecret == null || clientSecret.trim().length() == 0) {
clientSecret = emptyPassword;
}
return new User(username, clientSecret, clientDetails.getAuthorities());
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project dhis2-core by dhis2.
the class DefaultLdapUserDetailsService method loadUserByUsername.
// -------------------------------------------------------------------------
// UserDetailsService implementation
// -------------------------------------------------------------------------
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
User user = userService.getUserByUsername(username);
if (!user.isExternalAuth() || !user.hasLdapId()) {
throw new UsernameNotFoundException("Wrong type of user, is not LDAP user.");
}
boolean enabled = !user.isDisabled();
boolean credentialsNonExpired = userService.userNonExpired(user);
boolean accountNonLocked = !securityService.isLocked(user.getUsername());
boolean accountNonExpired = !userService.isAccountExpired(user);
if (ObjectUtils.anyIsFalse(enabled, credentialsNonExpired, accountNonLocked, accountNonExpired)) {
log.info(String.format("Login attempt for disabled/locked user: '%s', enabled: %b, account non-expired: %b, user non-expired: %b, account non-locked: %b", username, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked));
}
return new org.springframework.security.core.userdetails.User(user.getUsername(), "EXTERNAL_LDAP_" + CodeGenerator.generateCode(10), enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, SecurityUtils.getGrantedAuthorities(user));
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project midpoint by Evolveum.
the class MidpointPrincipalContextMapper method mapUserFromContext.
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) {
String userNameEffective = username;
Class<? extends FocusType> focusType = UserType.class;
try {
if (ctx instanceof LdapDirContextAdapter && ((LdapDirContextAdapter) ctx).getNamingAttr() != null) {
userNameEffective = resolveLdapName(ctx, username, ((LdapDirContextAdapter) ctx).getNamingAttr());
focusType = ((LdapDirContextAdapter) ctx).getFocusType();
}
return principalManager.getPrincipal(userNameEffective, focusType);
} catch (ObjectNotFoundException e) {
throw new UsernameNotFoundException("UserProfileServiceImpl.unknownUser", e);
} catch (SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException | NamingException e) {
throw new SystemException(e.getMessage(), e);
}
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project incubator-atlas by apache.
the class UserDaoTest method testUserDaowithInValidLogin.
@Test
public void testUserDaowithInValidLogin() {
boolean hadException = false;
Properties userLogins = new Properties();
userLogins.put("admin", "ADMIN::admin123");
userLogins.put("test", "DATA_STEWARD::test123");
UserDao user = new UserDao();
user.setUserLogins(userLogins);
try {
User userBean = user.loadUserByUsername("xyz");
} catch (UsernameNotFoundException uex) {
hadException = true;
}
assertTrue(hadException);
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project incubator-atlas by apache.
the class FileAuthenticationTest method testInValidUsernameLogin.
@Test
public void testInValidUsernameLogin() {
when(authentication.getName()).thenReturn("wrongUserName");
when(authentication.getCredentials()).thenReturn("wrongpassword");
try {
Authentication auth = authProvider.authenticate(authentication);
LOG.debug(" {}", auth);
} catch (UsernameNotFoundException uExp) {
assertTrue(uExp.getMessage().contains("Username not found."));
}
}
Aggregations