Skip to content

Commit

Permalink
Merge pull request indigo-iam#488 from indigo-iam/changes-for-AARC-G0…
Browse files Browse the repository at this point in the history
…02-profile

Changes on AARC profile
  • Loading branch information
enricovianello authored Jul 1, 2022
2 parents 1391589 + 64fdc3f commit f4b2f3b
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,42 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.google.common.base.Strings;
import com.google.common.collect.Sets;

import it.infn.mw.iam.persistence.model.IamGroup;
import it.infn.mw.iam.persistence.model.IamUserInfo;

@Component
public class AarcClaimValueHelper {

public static final Set<String> ADDITIONAL_CLAIMS =
Set.of("eduperson_scoped_affiliation", "eduperson_entitlement");

@Value("${iam.host}")
String iamHost;

@Value("${iam.organisation.name}")
String organisationName;
Set.of("eduperson_scoped_affiliation", "eduperson_entitlement", "eduperson_assurance");

@Value("${iam.aarc-profile.urn-namespace}")
String urnNamespace;

@Value("${iam.aarc-profile.urn-nid}")
String urnNid;

@Value("${iam.aarc-profile.urn-subnamespaces}")
String urnSubnamespaces;

final String URN_AFFILIATION = "member";

public Object getClaimValueFromUserInfo(String claim, IamUserInfo info) {

switch (claim) {

case "eduperson_scoped_affiliation":
return organisationName;
return String.format("%s@%s", URN_AFFILIATION, urnNamespace);

case "eduperson_entitlement":
return resolveGroups(info);

case "eduperson_assurance":
return resolveLOA();

default:
return null;
}
Expand All @@ -63,7 +71,16 @@ public Set<String> resolveGroups(IamUserInfo userInfo) {

private String encodeGroup(IamGroup group) {
String encodedGroupName = group.getName().replaceAll("/", ":");
return String.format("urn:%s:group:%s#%s", urnNamespace, encodedGroupName, iamHost);
String encodedSubnamespace = "";
if (!Strings.isNullOrEmpty(urnSubnamespaces)) {
encodedSubnamespace = String.format(":%s", String.join(":", urnSubnamespaces.trim().split(" ")));
}
return String.format("urn:%s:%s%s:group:%s", urnNid, urnNamespace, encodedSubnamespace, encodedGroupName);
}

public Set<String> resolveLOA() {

return Sets.newHashSet("https://refeds.org/assurance/IAP/low");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public Map<String, Object> assembleIntrospectionResult(OAuth2AccessTokenEntity a
result.put(EDUPERSON_ENTITLEMENT,
claimValueHelper.getClaimValueFromUserInfo(EDUPERSON_ENTITLEMENT, iamUserInfo));
}

if (scopes.contains(EDUPERSON_ASSURANCE)) {
result.put(EDUPERSON_ASSURANCE,
claimValueHelper.getClaimValueFromUserInfo(EDUPERSON_ASSURANCE, iamUserInfo));
}
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ public UserInfo resolveUserInfo(OAuth2Authentication authentication) {
IamUserInfo iamUserInfo = ((UserInfoAdapter) ui).getUserinfo();

AarcDecoratedUserInfo aui = AarcDecoratedUserInfo.forUser(ui);
aui.setScopedAffiliation(getProperties().getOrganisation().getName());
aui.setScopedAffiliation(claimValueHelper.getClaimValueFromUserInfo("eduperson_scoped_affiliation", iamUserInfo).toString());
aui.setEntitlements(claimValueHelper.resolveGroups(iamUserInfo));
aui.setAssurance(claimValueHelper.resolveLOA());

return aui;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public abstract class BaseIntrospectionHelper implements IntrospectionResultHelp
public static final String ISSUER = "iss";
public static final String EDUPERSON_SCOPED_AFFILIATION = "eduperson_scoped_affiliation";
public static final String EDUPERSON_ENTITLEMENT = "eduperson_entitlement";
public static final String EDUPERSON_ASSURANCE = "eduperson_assurance";

private final IamProperties properties;
private final IntrospectionResultAssembler assembler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ public class AarcDecoratedUserInfo extends DelegateUserInfoAdapter implements Aa

public static final String EDUPERSON_SCOPED_AFFILIATION_CLAIM = "eduperson_scoped_affiliation";
public static final String EDUPERSON_ENTITLEMENT_CLAIM = "eduperson_entitlement";
public static final String EDUPERSON_ASSURANCE_CLAIM = "eduperson_assurance";

private String scopedAffiliation;
private Set<String> entitlements;
private Set<String> assurance;

public AarcDecoratedUserInfo(UserInfo delegate) {
super(delegate);
Expand All @@ -44,10 +46,14 @@ public JsonObject toJson() {
json.remove("groups");
json.remove("organisation_name");

json.add(EDUPERSON_SCOPED_AFFILIATION_CLAIM, new JsonPrimitive(scopedAffiliation));
json.add(EDUPERSON_SCOPED_AFFILIATION_CLAIM, new JsonPrimitive(getScopedAffiliation()));

JsonArray values = new JsonArray();
getAssurance().forEach(value -> values.add(new JsonPrimitive(value)));
json.add(EDUPERSON_ASSURANCE_CLAIM, values);

JsonArray urns = new JsonArray();
entitlements.forEach(urn -> urns.add(new JsonPrimitive(urn)));
getEntitlements().forEach(urn -> urns.add(new JsonPrimitive(urn)));
json.add(EDUPERSON_ENTITLEMENT_CLAIM, urns);

return json;
Expand All @@ -73,7 +79,18 @@ public void setEntitlements(Set<String> entitlements) {
this.entitlements = entitlements;
}

@Override
public Set<String> getAssurance() {
return assurance;
}

@Override
public void setAssurance(Set<String> assurance) {
this.assurance = assurance;
}

public static AarcDecoratedUserInfo forUser(UserInfo u) {
return new AarcDecoratedUserInfo(u);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ public interface AarcUserInfo extends UserInfo {

Set<String> getEntitlements();
void setEntitlements(Set<String> entitlements);

Set<String> getAssurance();
void setAssurance(Set<String> assurance);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static it.infn.mw.iam.core.userinfo.UserInfoClaim.BIRTHDATE;
import static it.infn.mw.iam.core.userinfo.UserInfoClaim.EDUPERSON_ENTITLEMENT;
import static it.infn.mw.iam.core.userinfo.UserInfoClaim.EDUPERSON_SCOPED_AFFILIATION;
import static it.infn.mw.iam.core.userinfo.UserInfoClaim.EDUPERSON_ASSURANCE;
import static it.infn.mw.iam.core.userinfo.UserInfoClaim.EMAIL;
import static it.infn.mw.iam.core.userinfo.UserInfoClaim.EMAIL_VERIFIED;
import static it.infn.mw.iam.core.userinfo.UserInfoClaim.EXTERNAL_AUTHN;
Expand Down Expand Up @@ -69,6 +70,7 @@ public class IamScopeClaimTranslationService implements ScopeClaimTranslationSer
public static final String ADDRESS_SCOPE = "address";
public static final String EDUPERSON_SCOPED_AFFILIATION_SCOPE = "eduperson_scoped_affiliation";
public static final String EDUPERSON_ENTITLEMENT_SCOPE = "eduperson_entitlement";
public static final String EDUPERSON_ASSURANCE_SCOPE = "eduperson_assurance";
public static final String ATTR_SCOPE = "attr";
public static final String SSH_KEYS_SCOPE = "ssh-keys";
public static final String WLCG_GROUPS_SCOPE = "wlcg.groups";
Expand All @@ -90,6 +92,7 @@ public IamScopeClaimTranslationService() {
mapScopeToClaim(ADDRESS_SCOPE, ADDRESS);
mapScopeToClaim(EDUPERSON_SCOPED_AFFILIATION_SCOPE, EDUPERSON_SCOPED_AFFILIATION);
mapScopeToClaim(EDUPERSON_ENTITLEMENT_SCOPE, EDUPERSON_ENTITLEMENT);
mapScopeToClaim(EDUPERSON_ASSURANCE_SCOPE, EDUPERSON_ASSURANCE);
mapScopeToClaim(ATTR_SCOPE, ATTR);
mapScopeToClaim(SSH_KEYS_SCOPE, SSH_KEYS);
mapScopeToClaim(WLCG_GROUPS_SCOPE, WLCG_GROUPS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public enum UserInfoClaim {
EXTERNAL_AUTHN("external_authn"),
EDUPERSON_SCOPED_AFFILIATION("eduperson_scoped_affiliation"),
EDUPERSON_ENTITLEMENT("eduperson_entitlement"),
EDUPERSON_ASSURANCE("eduperson_assurance"),
SSH_KEYS("ssh_keys");

private UserInfoClaim(String claimName) {
Expand Down
4 changes: 3 additions & 1 deletion iam-login-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ iam:
- surname

aarc-profile:
urn-namespace: ${IAM_AARC_PROFILE_URN_NAMESPACE:example:iam}
urn-namespace: ${IAM_AARC_PROFILE_URN_NAMESPACE:iam.example}
urn-nid: ${IAM_AARC_PROFILE_URN_NID:geant}
urn-subnamespaces: ${IAM_AARC_PROFILE_URN_SUBNAMESPACES:}

external-connectivity-probe:
enabled: ${IAM_HEALTH_EXTERNAL_CONNECTIVITY_PROBE_ENABLED:false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@
@IamMockMvcIntegrationTest
@TestPropertySource(properties = {
// @formatter:off
"iam.host=example.org",
"iam.organisation.name=org",
"iam.aarc-profile.urn-namespace=example:iam:test",
"iam.aarc-profile.urn-namespace=projectescape.eu",
"iam.aarc-profile.urn-subnamespaces=sub mission",
// @formatter:on
})
@Transactional
Expand Down Expand Up @@ -81,7 +80,7 @@ public void testEmptyGroupsUrnEncode() {
@Test
public void testGroupUrnEncode() {

String s = "urn:example:iam:test:group:test#example.org";
String s = "urn:geant:projectescape.eu:sub:mission:group:test";

IamGroup g = new IamGroup();
g.setName("test");
Expand All @@ -98,9 +97,9 @@ public void testGroupUrnEncode() {
@Test
public void testGroupHierarchyUrnEncode() {

String parentUrn = "urn:example:iam:test:group:parent#example.org";
String childUrn = "urn:example:iam:test:group:parent:child#example.org";
String grandchildUrn = "urn:example:iam:test:group:parent:child:grandchild#example.org";
String parentUrn = "urn:geant:projectescape.eu:sub:mission:group:parent";
String childUrn = "urn:geant:projectescape.eu:sub:mission:group:parent:child";
String grandchildUrn = "urn:geant:projectescape.eu:sub:mission:group:parent:child:grandchild";

IamGroup parent = new IamGroup();
parent.setName("parent");
Expand Down
Loading

0 comments on commit f4b2f3b

Please sign in to comment.