[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) public List<Group> getSpecialGroups(Context context, HttpServletRequest request)
throws SQLException; 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. * Authenticate the given or implicit credentials.
* This is the heart of the authentication method: test the * This is the heart of the authentication method: test the

View File

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

View File

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