Skip to content

Commit b1fb340

Browse files
committed
Enable DAO for non-interactive action and send error context to flow
1 parent bcde7b2 commit b1fb340

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/main/java/io/cos/cas/osf/web/config/OsfCasSupportActionsConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public Action osfNonInteractiveAuthenticationCheckAction() {
100100
serviceTicketRequestWebflowEventResolver.getObject(),
101101
adaptiveAuthenticationPolicy.getObject(),
102102
centralAuthenticationService.getObject(),
103+
jpaOsfDao.getObject(),
103104
casProperties.getAuthn().getOsfUrl(),
104105
casProperties.getAuthn().getOsfApi(),
105106
authnDelegationClients

src/main/java/io/cos/cas/osf/web/flow/login/OsfPrincipalFromNonInteractiveCredentialsAction.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
import io.cos.cas.osf.authentication.exception.InstitutionSsoOsfApiFailedException;
1616
import io.cos.cas.osf.authentication.support.DelegationProtocol;
1717
import io.cos.cas.osf.authentication.support.OsfApiPermissionDenied;
18+
import io.cos.cas.osf.authentication.support.OsfInstitutionUtils;
1819
import io.cos.cas.osf.configuration.model.OsfApiProperties;
1920
import io.cos.cas.osf.configuration.model.OsfUrlProperties;
21+
import io.cos.cas.osf.dao.JpaOsfDao;
2022
import io.cos.cas.osf.web.support.OsfApiInstitutionAuthenticationResult;
2123
import io.cos.cas.osf.web.support.OsfCasSsoErrorContext;
2224

@@ -142,7 +144,7 @@
142144
@Getter
143145
public class OsfPrincipalFromNonInteractiveCredentialsAction extends AbstractNonInteractiveCredentialsAction {
144146

145-
private static final String PARAMETER_SSO_ERROR_CONTEXT = "osfSsoErrorContext";
147+
private static final String PARAMETER_SSO_ERROR_CONTEXT = "osfCasSsoErrorContext";
146148

147149
private static final String USERNAME_PARAMETER_NAME = "username";
148150

@@ -182,6 +184,9 @@ public class OsfPrincipalFromNonInteractiveCredentialsAction extends AbstractNon
182184
@NotNull
183185
private CentralAuthenticationService centralAuthenticationService;
184186

187+
@NotNull
188+
private final JpaOsfDao jpaOsfDao;
189+
185190
@NotNull
186191
private OsfUrlProperties osfUrlProperties;
187192

@@ -198,6 +203,7 @@ public OsfPrincipalFromNonInteractiveCredentialsAction(
198203
final CasWebflowEventResolver serviceTicketRequestWebflowEventResolver,
199204
final AdaptiveAuthenticationPolicy adaptiveAuthenticationPolicy,
200205
final CentralAuthenticationService centralAuthenticationService,
206+
final JpaOsfDao jpaOsfDao,
201207
final OsfUrlProperties osfUrlProperties,
202208
final OsfApiProperties osfApiProperties,
203209
final Map<String, List<String>> authnDelegationClients
@@ -208,6 +214,7 @@ public OsfPrincipalFromNonInteractiveCredentialsAction(
208214
adaptiveAuthenticationPolicy
209215
);
210216
this.centralAuthenticationService = centralAuthenticationService;
217+
this.jpaOsfDao = jpaOsfDao;
211218
this.osfUrlProperties = osfUrlProperties;
212219
this.osfApiProperties = osfApiProperties;
213220
this.authnDelegationClients = authnDelegationClients;
@@ -243,7 +250,8 @@ protected Credential constructCredentialsFromRequest(final RequestContext contex
243250
);
244251
final OsfPostgresCredential osfPostgresCredential = constructCredentialsFromPac4jAuthentication(context, clientName);
245252
if (osfPostgresCredential != null) {
246-
final OsfApiInstitutionAuthenticationResult remoteUserInfo = notifyOsfApiOfInstnAuthnSuccess(osfPostgresCredential);
253+
final OsfApiInstitutionAuthenticationResult remoteUserInfo
254+
= notifyOsfApiOfInstnAuthnSuccess(context, osfPostgresCredential);
247255
osfPostgresCredential.setUsername(remoteUserInfo.getSsoEmail());
248256
osfPostgresCredential.setInstitutionId(remoteUserInfo.getInstitutionId());
249257
WebUtils.removeCredential(context);
@@ -266,7 +274,8 @@ protected Credential constructCredentialsFromRequest(final RequestContext contex
266274
// Type 3: institution sso via Shibboleth authentication using the SAML protocol
267275
LOGGER.debug("Shibboleth session / header found in request context.");
268276
final OsfPostgresCredential osfPostgresCredential = constructCredentialsFromShibbolethAuthentication(context, request);
269-
final OsfApiInstitutionAuthenticationResult remoteUserInfo = notifyOsfApiOfInstnAuthnSuccess(osfPostgresCredential);
277+
final OsfApiInstitutionAuthenticationResult remoteUserInfo
278+
= notifyOsfApiOfInstnAuthnSuccess(context, osfPostgresCredential);
270279
final String ssoIdentity = osfPostgresCredential.getSsoIdentity();
271280
final String eppn = osfPostgresCredential.getDelegationAttributes().get("eppn");
272281
final String mail = osfPostgresCredential.getDelegationAttributes().get("mail");
@@ -571,6 +580,7 @@ private JSONObject extractInstnAuthnDataFromCredential(final OsfPostgresCredenti
571580
* @throws AccountException if there is an issue with authentication data or if the OSF API request has failed
572581
*/
573582
private OsfApiInstitutionAuthenticationResult notifyOsfApiOfInstnAuthnSuccess(
583+
final RequestContext context,
574584
final OsfPostgresCredential credential
575585
) throws AccountException {
576586

@@ -761,6 +771,15 @@ private OsfApiInstitutionAuthenticationResult notifyOsfApiOfInstnAuthnSuccess(
761771
final String errorDetail = ((JsonObject) error).get("detail").getAsString();
762772
if (OsfApiPermissionDenied.INSTITUTION_SSO_SELECTIVE_LOGIN_DENIED.getId().equals(errorDetail)) {
763773
LOGGER.error("[OSF API] Failure - Institution Selective SSO Not Allowed: {}, filter={}", ssoUser, selectiveSsoFilter);
774+
setSsoErrorContext(
775+
context,
776+
InstitutionSsoSelectiveLoginDeniedException.class.getSimpleName(),
777+
String.format("Institution Selective SSO Not Allowed: %s", ssoUser),
778+
ssoEmail,
779+
ssoIdentity,
780+
institutionId,
781+
OsfInstitutionUtils.getInstitutionSupportEmail(this.jpaOsfDao, institutionId)
782+
);
764783
throw new InstitutionSsoSelectiveLoginDeniedException("OSF API denies selective SSO login");
765784
}
766785
if (OsfApiPermissionDenied.INSTITUTION_SSO_DUPLICATE_IDENTITY.getId().equals(errorDetail)) {

0 commit comments

Comments
 (0)