85276: Store and retrieve the Authentication method in the JWT

This commit is contained in:
Yana De Pauw
2021-12-01 15:33:13 +01:00
parent dcfa74a2c3
commit 16e704a285
14 changed files with 200 additions and 4 deletions

View File

@@ -83,6 +83,9 @@ public class LDAPAuthentication
protected ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();
private static final String LDAP_AUTHENTICATED = "ldap.authenticated";
/**
* Let a real auth method return true if it wants.
*
@@ -261,6 +264,7 @@ public class LDAPAuthentication
if (ldap.ldapAuthenticate(dn, password, context)) {
context.setCurrentUser(eperson);
request.getSession().setAttribute(LDAP_AUTHENTICATED, true);
// assign user to groups based on ldap dn
assignGroups(dn, ldap.ldapGroup, context);
@@ -311,6 +315,8 @@ public class LDAPAuthentication
context.dispatchEvents();
context.restoreAuthSystemState();
context.setCurrentUser(eperson);
request.getSession().setAttribute(LDAP_AUTHENTICATED, true);
// assign user to groups based on ldap dn
assignGroups(dn, ldap.ldapGroup, context);
@@ -341,6 +347,8 @@ public class LDAPAuthentication
ePersonService.update(context, eperson);
context.dispatchEvents();
context.setCurrentUser(eperson);
request.getSession().setAttribute(LDAP_AUTHENTICATED, true);
// assign user to groups based on ldap dn
assignGroups(dn, ldap.ldapGroup, context);
@@ -734,4 +742,14 @@ public class LDAPAuthentication
}
}
}
@Override
public boolean isUsed(final Context context, final HttpServletRequest request) {
if (request != null &&
context.getCurrentUser() != null &&
request.getSession().getAttribute(LDAP_AUTHENTICATED) != null) {
return true;
}
return false;
}
}