Skip to content

Commit 6ec9f20

Browse files
authored
[ENG-10293] Hide institution with in-progress SSO setup from the institution login dropdown list (#107)
* Add only public sso availability to institution login URL map * Add/update JavaDoc/comments
1 parent 6384aaf commit 6ec9f20

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/main/java/io/cos/cas/osf/authentication/support/OsfInstitutionUtils.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.util.Map;
1515

1616
/**
17-
* This is {@link OsfInstitutionUtils}.
17+
* This is {@link OsfInstitutionUtils}, which provides helper methods supporting the institution SSO login flow.
1818
*
1919
* @author Longze Chen
2020
* @since 21.0.0
@@ -52,6 +52,25 @@ public static Map<String, String> getInstitutionLoginUrlMap(
5252
}
5353
final Map<String, String> institutionLoginUrlMap = new HashMap<>();
5454
for (final OsfInstitution institution: institutionList) {
55+
final SsoAvailability ssoAvailability = institution.getSsoAvailability();
56+
if (ssoAvailability == null) {
57+
// Catch a rare exception case where OSF DB has changed the choices of the field
58+
// `sso_availability` in table `osf_institution` without syncing with CAS.
59+
LOGGER.error(
60+
"Skipped due to invalid SSO Availability: [institutionId={}]",
61+
institution.getInstitutionId()
62+
);
63+
continue;
64+
}
65+
if (!ssoAvailability.isPublic()) {
66+
// Hide institutions of which SSO Availability is not Public
67+
LOGGER.debug(
68+
"Skipped because SSO Availability is not public: [institutionId={}, ssoAvailability={}]",
69+
institution.getInstitutionId(),
70+
ssoAvailability.getId()
71+
);
72+
continue;
73+
}
5574
final DelegationProtocol delegationProtocol = institution.getDelegationProtocol();
5675
if (DelegationProtocol.SAML_SHIB.equals(delegationProtocol)) {
5776
institutionLoginUrlMap.put(

src/main/java/io/cos/cas/osf/authentication/support/SsoAvailability.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package io.cos.cas.osf.authentication.support;
22

33
/**
4-
* This is {@link SsoAvailability}.
4+
* This is {@link SsoAvailability}, which is used in {@link io.cos.cas.osf.model.OsfInstitution}
5+
* to map to the types/choices of its counterpart in the OSF model.
56
*
67
* @author Longze Chen
78
* @since 26.1.0
@@ -40,6 +41,13 @@ public static SsoAvailability getType(final String id) throws IllegalArgumentExc
4041
throw new IllegalArgumentException("No matching type for id " + id);
4142
}
4243

44+
/**
45+
* @return whether the enum type is {@link SsoAvailability#PUBLIC}.
46+
*/
47+
public boolean isPublic () {
48+
return SsoAvailability.PUBLIC.equals(this);
49+
}
50+
4351
public final String getId() {
4452
return id;
4553
}

0 commit comments

Comments
 (0)