Skip to content

Commit

Permalink
[DURACOM-192] Authentication Method related special groups are put in…
Browse files Browse the repository at this point in the history
… claim set even if a different authentication method is used
  • Loading branch information
LucaGiamminonni committed Oct 17, 2023
1 parent 92844f0 commit 6504d74
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ public boolean allowSetPassword(Context context,
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,15 @@ public List<Group> getSpecialGroups(Context context,
int totalLen = 0;

for (AuthenticationMethod method : getAuthenticationMethodStack()) {
List<Group> gl = method.getSpecialGroups(context, request);
if (gl.size() > 0) {
result.addAll(gl);
totalLen += gl.size();

if (method.areSpecialGroupsApplicable(context, request)) {

List<Group> gl = method.getSpecialGroups(context, request);
if (gl.size() > 0) {
result.addAll(gl);
totalLen += gl.size();
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ public List<Group> getSpecialGroups(Context context, HttpServletRequest request)
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 {
Expand Down

0 comments on commit 6504d74

Please sign in to comment.