Skip to content

Commit

Permalink
fix for empty 'namingAttr' for ldap authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Oct 18, 2023
1 parent 1275658 commit 8843ae8
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,21 @@ public MidpointPrincipalContextMapper() {
public UserDetails mapUserFromContext(DirContextOperations ctx, String username,
Collection<? extends GrantedAuthority> authorities) {

if (!(ctx instanceof LdapDirContextAdapter) || ((LdapDirContextAdapter) ctx).getNamingAttr() == null) {
LOGGER.debug("Couldn't define midpoint user");
if (!(ctx instanceof LdapDirContextAdapter)) {
LOGGER.debug("Wrong type of authentication context expected LdapDirContextAdapter, but was "
+ (ctx == null ? null : ctx.getClass()));
throw new AuthenticationServiceException("web.security.provider.invalid");
}

String userNameEffective;
try {
userNameEffective = resolveLdapName(ctx, username, ((LdapDirContextAdapter) ctx).getNamingAttr());
} catch (ObjectNotFoundException e) {
throw new UsernameNotFoundException("web.security.provider.invalid.credentials", e);
} catch (NamingException e) {
throw new SystemException(e.getMessage(), e);
String userNameEffective = username;
if (((LdapDirContextAdapter) ctx).getNamingAttr() != null){
try {
userNameEffective = resolveLdapName(ctx, username, ((LdapDirContextAdapter) ctx).getNamingAttr());
} catch (ObjectNotFoundException e) {
throw new UsernameNotFoundException("web.security.provider.invalid.credentials", e);
} catch (NamingException e) {
throw new SystemException(e.getMessage(), e);
}
}

Class<? extends FocusType> focusType = ((LdapDirContextAdapter) ctx).getFocusType();
Expand Down

0 comments on commit 8843ae8

Please sign in to comment.