[DURACOM-192] Authentication Method related special groups are put in claim set even if a different authentication method is used

This commit is contained in:
Luca Giamminonni
2023-10-17 16:28:37 +02:00
parent 92844f0b05
commit 6504d749b9
3 changed files with 30 additions and 4 deletions

View File

@@ -153,6 +153,22 @@ public interface AuthenticationMethod {
public List<Group> getSpecialGroups(Context context, HttpServletRequest request)
throws SQLException;
/**
* Returns true if the special groups returned by
* {@link org.dspace.authenticate.AuthenticationMethod#getSpecialGroups(Context, HttpServletRequest)}
* should be implicitly be added to the groups related to the current user. By
* default this is true if the authentication method is the actual
* authentication mechanism used by the user.
* @param context A valid DSpace context.
* @param request The request that started this operation, or null if not
* applicable.
* @return true is the special groups must be considered, false
* otherwise
*/
public default boolean areSpecialGroupsApplicable(Context context, HttpServletRequest request) {
return getName().equals(context.getAuthenticationMethod());
}
/**
* Authenticate the given or implicit credentials.
* This is the heart of the authentication method: test the

View File

@@ -179,11 +179,16 @@ public class AuthenticationServiceImpl implements AuthenticationService {
int totalLen = 0;
for (AuthenticationMethod method : getAuthenticationMethodStack()) {
if (method.areSpecialGroupsApplicable(context, request)) {
List<Group> gl = method.getSpecialGroups(context, request);
if (gl.size() > 0) {
result.addAll(gl);
totalLen += gl.size();
}
}
}
return result;

View File

@@ -252,6 +252,11 @@ public class IPAuthentication implements AuthenticationMethod {
return groups;
}
@Override
public boolean areSpecialGroupsApplicable(Context context, HttpServletRequest request) {
return true;
}
@Override
public int authenticate(Context context, String username, String password,
String realm, HttpServletRequest request) throws SQLException {