diff --git a/cas-server-support-osf/src/main/java/io/cos/cas/authentication/exceptions/InstitutionLoginFailedOsfApiLoAException.java b/cas-server-support-osf/src/main/java/io/cos/cas/authentication/exceptions/InstitutionLoginFailedOsfApiLoAException.java deleted file mode 100644 index f5be5dc5..00000000 --- a/cas-server-support-osf/src/main/java/io/cos/cas/authentication/exceptions/InstitutionLoginFailedOsfApiLoAException.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2020. Center for Open Science - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.cos.cas.authentication.exceptions; - -/** - * Describes an error condition where institution login fails when communicating with OSF API. - * - * @author Longze Chen - * @since 20.1.0 - */ -public class InstitutionLoginFailedOsfApiLoAException extends InstitutionLoginFailedException { - - private static final long serialVersionUID = 1737367176204402913L; - - /** Instantiates a new exception (default). */ - public InstitutionLoginFailedOsfApiLoAException() { - super(); - } - - /** - * Instantiates a new exception with a given message. - * - * @param message the message - */ - public InstitutionLoginFailedOsfApiLoAException(final String message) { - super(message); - } -} diff --git a/cas-server-support-osf/src/main/java/io/cos/cas/authentication/handler/support/OpenScienceFrameworkPrincipalFromRequestRemoteUserNonInteractiveCredentialsAction.java b/cas-server-support-osf/src/main/java/io/cos/cas/authentication/handler/support/OpenScienceFrameworkPrincipalFromRequestRemoteUserNonInteractiveCredentialsAction.java index 84b0f098..c47bf3fb 100644 --- a/cas-server-support-osf/src/main/java/io/cos/cas/authentication/handler/support/OpenScienceFrameworkPrincipalFromRequestRemoteUserNonInteractiveCredentialsAction.java +++ b/cas-server-support-osf/src/main/java/io/cos/cas/authentication/handler/support/OpenScienceFrameworkPrincipalFromRequestRemoteUserNonInteractiveCredentialsAction.java @@ -35,7 +35,6 @@ import io.cos.cas.authentication.exceptions.InstitutionLoginFailedAttributesMissingException; import io.cos.cas.authentication.exceptions.InstitutionLoginFailedAttributesParsingException; import io.cos.cas.authentication.exceptions.InstitutionLoginFailedOsfApiException; -import io.cos.cas.authentication.exceptions.InstitutionLoginFailedOsfApiLoAException; // @R2022-48 loa import io.cos.cas.authentication.OpenScienceFrameworkCredential; import org.apache.http.client.fluent.Request; @@ -59,7 +58,6 @@ import org.jasig.cas.ticket.TicketGrantingTicket; import org.jasig.cas.web.support.WebUtils; import org.json.JSONObject; -import org.json.JSONException; import org.json.XML; import org.pac4j.oauth.client.OrcidClient; @@ -142,19 +140,16 @@ public static class PrincipalAuthenticationResult { private String username; private String institutionId; - private String context; /** * Creates a new instance with the given parameters. * * @param username The username * @param institutionId The institution id - * @param context The context */ - public PrincipalAuthenticationResult(final String username, final String institutionId, final String context) { + public PrincipalAuthenticationResult(final String username, final String institutionId) { this.username = username; this.institutionId = institutionId; - this.context = context; } public String getUsername() { @@ -164,10 +159,6 @@ public String getUsername() { public String getInstitutionId() { return institutionId; } - - public String getContext() { - return context; - } } private static final String CONST_CREDENTIAL = "credential"; @@ -331,7 +322,6 @@ protected OpenScienceFrameworkCredential constructCredential( ) throws AccountException, FailedLoginException { final HttpServletRequest request = WebUtils.getHttpServletRequest(context); - final HttpServletResponse response = WebUtils.getHttpServletResponse(context); // WARN: Do not use `WebUtils.getCredential(RequestContext context)`, it will make the credential `null`. // TODO: Check both `FlowScope` and `RequestScope`. Write a `.getCredential(RequestContext context)` which @@ -395,38 +385,9 @@ protected OpenScienceFrameworkCredential constructCredential( } } - logger.info("[SAML Shibboleth] credential : '{}'", credential); - // Parse the attributes and notify OSF API of the remote principal authentication final PrincipalAuthenticationResult remoteUserInfo = notifyRemotePrincipalAuthenticated(credential); - final String remoteUserContext = remoteUserInfo.getContext(); - final JSONObject json; - logger.info("[SAML Shibboleth] context : '{}'", remoteUserContext); - if (StringUtils.hasText(remoteUserContext)) { - try { - json = new JSONObject(remoteUserContext); - } catch (final JSONException e) { - logger.error( - "[OSF API] Notify Remote Principal Authenticated Failed: Communication Error - {}", - e.getMessage() - ); - throw new InstitutionLoginFailedOsfApiException("Communication Error between OSF CAS and OSF API"); - } - final String mfaUrl = json.optString("mfa_url"); - if (StringUtils.hasText(mfaUrl)) { - try { - logger.info("[OSF API] Redirect MFA URL: '{}'", mfaUrl); - response.sendRedirect(mfaUrl); - return null; - } catch (final IOException e) { - logger.error( - "[OSF API] Notify Remote Principal Authenticated Failed: Communication Error - {}", - e.getMessage() - ); - throw new InstitutionLoginFailedOsfApiException("Communication Error between OSF CAS and OSF API"); - } - } - } + // Build and return the OSF-specific credential credential.setUsername(remoteUserInfo.getUsername()); credential.setInstitutionId(remoteUserInfo.getInstitutionId()); @@ -544,34 +505,7 @@ protected OpenScienceFrameworkCredential constructCredential( // Parse the attributes and notify OSF API of the remote principal authentication final PrincipalAuthenticationResult remoteUserInfo = notifyRemotePrincipalAuthenticated(credential); - final String remoteUserContext = remoteUserInfo.getContext(); - final JSONObject json; - logger.info("[CAS PAC4J] context : '{}'", remoteUserContext); - if (StringUtils.hasText(remoteUserContext)) { - try { - json = new JSONObject(remoteUserContext); - } catch (final JSONException e) { - logger.error( - "[OSF API] Notify Remote Principal Authenticated Failed: Communication Error - {}", - e.getMessage() - ); - throw new InstitutionLoginFailedOsfApiException("Communication Error between OSF CAS and OSF API"); - } - final String mfaUrl = json.optString("mfa_url"); - if (StringUtils.hasText(mfaUrl)) { - try { - logger.info("[OSF API] Redirect MFA URL: '{}'", mfaUrl); - response.sendRedirect(mfaUrl); - return null; - } catch (final IOException e) { - logger.error( - "[OSF API] Notify Remote Principal Authenticated Failed: Communication Error - {}", - e.getMessage() - ); - throw new InstitutionLoginFailedOsfApiException("Communication Error between OSF CAS and OSF API"); - } - } - } + credential.setUsername(remoteUserInfo.getUsername()); credential.setInstitutionId(remoteUserInfo.getInstitutionId()); @@ -633,8 +567,6 @@ protected PrincipalAuthenticationResult notifyRemotePrincipalAuthenticated( logger.error("[CAS XSLT] Missing institutional user"); throw new InstitutionLoginFailedAttributesMissingException("Missing institutional user"); } - final String givenNameTmp = user.optString("givenName"); - logger.info("[CAS XSLT] All attributes checked: givenNameTmp={}", givenNameTmp); final String username = user.optString("username").trim(); final String fullname = user.optString("fullname").trim(); final String givenName = user.optString("givenName").trim(); @@ -648,73 +580,38 @@ protected PrincipalAuthenticationResult notifyRemotePrincipalAuthenticated( throw new InstitutionLoginFailedAttributesMissingException("Missing user's names"); } - final String email = user.optString("email").trim(); - final String o = user.optString("o").trim(); - final String ou = user.optString("ou").trim(); - final String eduPersonAffiliation = user.optString("eduPersonAffiliation").trim(); - final String entitlement = user.optString("entitlement").trim(); - final String eduPersonScopedAffiliation = user.optString("eduPersonScopedAffiliation").trim(); - final String eduPersonTargetedID = user.optString("eduPersonTargetedID").trim(); - final String eduPersonAssurance = user.optString("eduPersonAssurance").trim(); - final String eduPersonUniqueId = user.optString("eduPersonUniqueId").trim(); - final String eduPersonOrcid = user.optString("eduPersonOrcid").trim(); - final String isMemberOf = user.optString("isMemberOf").trim(); - final String jasn = user.optString("jasn").trim(); - final String jaGivenName = user.optString("jaGivenName").trim(); - final String jaDisplayName = user.optString("jaDisplayName").trim(); - final String jao = user.optString("jao").trim(); - final String jaou = user.optString("jaou").trim(); - final String gakuninScopedPersonalUniqueCode = user.optString("gakuninScopedPersonalUniqueCode").trim(); - // Call Login Availability API - final JSONObject bodyObj = new JSONObject(); - bodyObj.put("institution_id", institutionId); - bodyObj.put("mail", email); - bodyObj.put("sn", familyName); - bodyObj.put("o", getStringList(o)); - bodyObj.put("ou", ou); - bodyObj.put("givenName", givenName); - bodyObj.put("displayName", fullname); - bodyObj.put("eduPersonAffiliation", getStringList(eduPersonAffiliation)); - bodyObj.put("eduPersonPrincipalName", username); - bodyObj.put("eduPersonEntitlement", getStringList(entitlement)); - bodyObj.put("eduPersonScopedAffiliation", getStringList(eduPersonScopedAffiliation)); - bodyObj.put("eduPersonTargetedID", getStringList(eduPersonTargetedID)); - bodyObj.put("eduPersonAssurance", getStringList(eduPersonAssurance)); - bodyObj.put("eduPersonUniqueId", eduPersonUniqueId); - bodyObj.put("eduPersonOrcid", getStringList(eduPersonOrcid)); - bodyObj.put("isMemberOf", getStringList(isMemberOf)); - bodyObj.put("jasn", jasn); - bodyObj.put("jaGivenName", jaGivenName); - bodyObj.put("jaDisplayName", jaDisplayName); - bodyObj.put("jao", getStringList(jao)); - bodyObj.put("jaou", jaou); - bodyObj.put("gakuninScopedPersonalUniqueCode", getStringList(gakuninScopedPersonalUniqueCode)); - - // send post method to RDM API - HttpResponse httpResponse; - try { - httpResponse = callLoginAvailabilityAPI(bodyObj); - final int statusCode = httpResponse.getStatusLine().getStatusCode(); - if (statusCode == HttpStatus.SC_FORBIDDEN) { - throw new InstitutionLoginAvailabilityException(); + final String entitlement = user.optString("entitlement").trim(); + if (!StringUtils.isEmpty(entitlement)) { + // send post method to RDM API + final JSONObject bodyObj = new JSONObject(); + final String normalizeEntitlement = entitlement.replace("\\;", ";"); + bodyObj.put("institution_id", institutionId); + bodyObj.put("entitlements", getEntitlements(normalizeEntitlement)); + user.put("entitlement", normalizeEntitlement); // normalize entitlement in payload + + HttpResponse httpResponse; + try { + httpResponse = callLoginAvailabilityAPI(bodyObj); + final BufferedReader bf = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); + String bodyData = ""; + final StringBuilder builder = new StringBuilder(); + while ((bodyData = bf.readLine()) != null) { + builder.append(bodyData); + } + final JSONObject json = new JSONObject(builder.toString()); + final boolean isLoginAvailability = (Boolean) json.get("login_availability"); + if (!isLoginAvailability) { + throw new InstitutionLoginAvailabilityException(); + } + } catch (final IOException e) { + logger.error( + "[OSF API] Notify Remote Principal Authenticated Failed: Communication Error - {}", + e.getMessage() + ); + throw new InstitutionLoginFailedOsfApiException("Communication Error between OSF CAS and OSF API"); } - final BufferedReader bf = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); - String bodyData = ""; - final StringBuilder builder = new StringBuilder(); - while ((bodyData = bf.readLine()) != null) { - builder.append(bodyData); - } - final JSONObject json = new JSONObject(builder.toString()); - final String loginAvailability = (String) json.get("login_availability"); - user.put("login_availability", loginAvailability); - } catch (final IOException e) { - logger.error( - "[OSF API] Notify Remote Principal Authenticated Failed: Communication Error - {}", - e.getMessage() - ); - throw new InstitutionLoginFailedOsfApiException("Communication Error between OSF CAS and OSF API"); } final String payload = normalizedPayload.toString(); @@ -755,42 +652,36 @@ protected PrincipalAuthenticationResult notifyRemotePrincipalAuthenticated( // Step 4 - Make the OSF API request with the encrypted payload. try { - httpResponse = Request.Post(this.institutionsAuthUrl) + final HttpResponse httpResponse = Request.Post(this.institutionsAuthUrl) .addHeader(new BasicHeader("Content-Type", "text/plain")) .bodyString(jweString, ContentType.APPLICATION_JSON) .execute() .returnResponse(); final int statusCode = httpResponse.getStatusLine().getStatusCode(); - final String context = new BasicResponseHandler().handleResponse(httpResponse); logger.info( - "[OSF API] Notify Remote Principal Authenticated Response: username={} statusCode={} context={}", + "[OSF API] Notify Remote Principal Authenticated Response: username={} statusCode={}", username, - statusCode, - context + statusCode ); // The OSF API institution authentication endpoint always returns the HTTP 204 No Content if successful. - //if (statusCode != HttpStatus.SC_NO_CONTENT) { - if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_NO_CONTENT) { + if (statusCode != HttpStatus.SC_NO_CONTENT) { + final String responseString = new BasicResponseHandler().handleResponse(httpResponse); logger.error( - "[OSF API] Notify Remote Principal Authenticated Failed: statusCode={}, context={}", + "[OSF API] Notify Remote Principal Authenticated Failed: statusCode={}, body={}", statusCode, - context + responseString ); throw new InstitutionLoginFailedOsfApiException("OSF API failed to process CAS request"); } + // Return user's username and the institution ID to build the OSF credential - return new PrincipalAuthenticationResult(username, institutionId, context); + return new PrincipalAuthenticationResult(username, institutionId); } catch (final IOException e) { - final String errmsg = e.getMessage(); logger.error( "[OSF API] Notify Remote Principal Authenticated Failed: Communication Error - {}", e.getMessage() ); - if ("Bad Request".equals(errmsg)) { - throw new InstitutionLoginFailedOsfApiLoAException("Communication Error between OSF CAS and OSF API"); - } else { - throw new InstitutionLoginFailedOsfApiException("Communication Error between OSF CAS and OSF API"); - } + throw new InstitutionLoginFailedOsfApiException("Communication Error between OSF CAS and OSF API"); } } @@ -810,21 +701,20 @@ protected HttpResponse callLoginAvailabilityAPI(final JSONObject bodyObj) throws } /** - * Get list of string. + * Gets the entitlements. * - * @param value value - * @return list of string + * @param entitlement the entitlement + * @return the entitlements */ - protected List getStringList(final String value) { - final String normalizedValue = value.replace("\\;", ";"); - final List values = new ArrayList(); - if (!StringUtils.isEmpty(normalizedValue)) { - final String[] arr = normalizedValue.split(";"); + protected List getEntitlements(final String entitlement) { + final List entitlements = new ArrayList(); + if (!StringUtils.isEmpty(entitlement)) { + final String[] arr = entitlement.split(";"); for (final String str : arr) { - values.add(str.trim()); + entitlements.add(str.trim()); } } - return values; + return entitlements; } /** diff --git a/cas-server-support-osf/src/main/java/io/cos/cas/web/flow/OpenScienceFrameworkAuthenticationExceptionHandler.java b/cas-server-support-osf/src/main/java/io/cos/cas/web/flow/OpenScienceFrameworkAuthenticationExceptionHandler.java index 5d1981ba..73d1e044 100644 --- a/cas-server-support-osf/src/main/java/io/cos/cas/web/flow/OpenScienceFrameworkAuthenticationExceptionHandler.java +++ b/cas-server-support-osf/src/main/java/io/cos/cas/web/flow/OpenScienceFrameworkAuthenticationExceptionHandler.java @@ -29,7 +29,6 @@ import io.cos.cas.authentication.exceptions.InstitutionLoginFailedAttributesMissingException; import io.cos.cas.authentication.exceptions.InstitutionLoginFailedAttributesParsingException; import io.cos.cas.authentication.exceptions.InstitutionLoginFailedOsfApiException; -import io.cos.cas.authentication.exceptions.InstitutionLoginFailedOsfApiLoAException; // @R2022-48 loa import io.cos.cas.authentication.exceptions.InvalidUserStatusException; import io.cos.cas.authentication.exceptions.InvalidVerificationKeyException; import io.cos.cas.authentication.exceptions.OneTimePasswordFailedLoginException; @@ -91,7 +90,6 @@ public class OpenScienceFrameworkAuthenticationExceptionHandler extends Authenti DEFAULT_ERROR_LIST.add(InstitutionLoginFailedAttributesMissingException.class); DEFAULT_ERROR_LIST.add(InstitutionLoginFailedAttributesParsingException.class); DEFAULT_ERROR_LIST.add(InstitutionLoginFailedOsfApiException.class); - DEFAULT_ERROR_LIST.add(InstitutionLoginFailedOsfApiLoAException.class); // @R2022-48 loa DEFAULT_ERROR_LIST.add(InvalidVerificationKeyException.class); DEFAULT_ERROR_LIST.add(InvalidUserStatusException.class); DEFAULT_ERROR_LIST.add(OneTimePasswordFailedLoginException.class); diff --git a/cas-server-support-osf/src/main/java/io/cos/cas/web/flow/OpenScienceFrameworkTerminateSessionAction.java b/cas-server-support-osf/src/main/java/io/cos/cas/web/flow/OpenScienceFrameworkTerminateSessionAction.java index fdfc6605..40d5fbe5 100644 --- a/cas-server-support-osf/src/main/java/io/cos/cas/web/flow/OpenScienceFrameworkTerminateSessionAction.java +++ b/cas-server-support-osf/src/main/java/io/cos/cas/web/flow/OpenScienceFrameworkTerminateSessionAction.java @@ -91,11 +91,9 @@ public Event terminate(final RequestContext context) { String institutionId = null; Boolean remotePrincipal = Boolean.FALSE; - final HttpServletRequest request = WebUtils.getHttpServletRequest(context); - final String serviceUrl = request.getParameter("service"); - logger.info("[serviceUrl] Param: '{}'", serviceUrl); // for logout, we need to get the cookie's value if (tgtId == null) { + final HttpServletRequest request = WebUtils.getHttpServletRequest(context); tgtId = this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request); } // for institution logout, get the institutionId stored in TGT @@ -124,14 +122,9 @@ public Event terminate(final RequestContext context) { this.ticketGrantingTicketCookieGenerator.removeCookie(response); this.warnCookieGenerator.removeCookie(response); - final String institutionLogoutUrl; // if logged in through institutions, redirect to institution logout endpoint if (remotePrincipal && institutionId != null) { - if (serviceUrl != null) { - institutionLogoutUrl = serviceUrl; - } else { - institutionLogoutUrl = institutionHandler.findInstitutionLogoutUrlById(institutionId); - } + final String institutionLogoutUrl = institutionHandler.findInstitutionLogoutUrlById(institutionId); if (institutionLogoutUrl == null) { logger.warn("Institution {} does not have a dedicated logout url, use default logout redirection instead", institutionId); } else { @@ -139,9 +132,6 @@ public Event terminate(final RequestContext context) { // return `finish` event to prevent `logoutRedirectUrl` being overwritten return new Event(this, "finish"); } - } else if (serviceUrl != null) { - context.getFlowScope().put("logoutRedirectUrl", serviceUrl); - return new Event(this, "finish"); } return this.eventFactorySupport.success(this); diff --git a/cas-server-support-osf/src/test/java/io/cos/cas/AbstractTestUtils.java b/cas-server-support-osf/src/test/java/io/cos/cas/AbstractTestUtils.java index 944ba9db..1daa3c67 100644 --- a/cas-server-support-osf/src/test/java/io/cos/cas/AbstractTestUtils.java +++ b/cas-server-support-osf/src/test/java/io/cos/cas/AbstractTestUtils.java @@ -45,8 +45,6 @@ public abstract class AbstractTestUtils { public static final String[] CONST_SINGLE_ENTITLEMENTS_OUTPUT = {"value1-1", "value1-2", "value1-3"}; - public static final String CONST_JSON_STRING = "{\"key1-1\":\"value1-1\"}"; - private static final String REMOTE_USER = "REMOTE_USER"; private static final String ATTRIBUTE_PREFIX = "AUTH-"; diff --git a/cas-server-support-osf/src/test/java/io/cos/cas/authentication/handler/support/OpenScienceFrameworkPrincipalFromRequestRemoteUserNonInteractiveCredentialsActionTests.java b/cas-server-support-osf/src/test/java/io/cos/cas/authentication/handler/support/OpenScienceFrameworkPrincipalFromRequestRemoteUserNonInteractiveCredentialsActionTests.java index 909ea2f7..2bd48c19 100644 --- a/cas-server-support-osf/src/test/java/io/cos/cas/authentication/handler/support/OpenScienceFrameworkPrincipalFromRequestRemoteUserNonInteractiveCredentialsActionTests.java +++ b/cas-server-support-osf/src/test/java/io/cos/cas/authentication/handler/support/OpenScienceFrameworkPrincipalFromRequestRemoteUserNonInteractiveCredentialsActionTests.java @@ -117,8 +117,6 @@ public void handleInstitutionValidRemotePrincipal() throws Exception { final OpenScienceFrameworkCredential osfCredential = new OpenScienceFrameworkCredential(); osfCredential.setUsername(AbstractTestUtils.CONST_MAIL); osfCredential.setInstitutionId(AbstractTestUtils.CONST_INSTITUTION_ID); - osfRemoteAuthenticate - .setInstitutionsLoginAvailabilityUrl(AbstractTestUtils.CONST_INSTITUTION_LOGIN_AVAILABILITY_URL); try { osfRemoteAuthenticate.notifyRemotePrincipalAuthenticated(osfCredential); } catch (final AccountException e) { @@ -256,7 +254,7 @@ public void verifyLoginAvailabilityGetEntitlementFlow() throws Exception { List entitlementList = new ArrayList(); // Verify in case single entitlement - entitlementList = osfRemoteAuthenticate.getStringList(AbstractTestUtils.CONST_SINGLE_ENTITLEMENT_INPUT); + entitlementList = osfRemoteAuthenticate.getEntitlements(AbstractTestUtils.CONST_SINGLE_ENTITLEMENT_INPUT); assertEquals(entitlementList.size(), AbstractTestUtils.CONST_SINGLE_ENTITLEMENTS_OUTPUT.length); } @@ -274,7 +272,7 @@ public void verifyLoginAvailabilitySingleEntitlementFlow() throws Exception { osfCredential.setUsername(AbstractTestUtils.CONST_MAIL); osfRemoteAuthenticate.setSingleEntitlement(true); - osfRemoteAuthenticate.setLoginAvailability("can login"); + osfRemoteAuthenticate.setLoginAvailability(true); osfRemoteAuthenticate .setInstitutionsLoginAvailabilityUrl(AbstractTestUtils.CONST_INSTITUTION_LOGIN_AVAILABILITY_URL); @@ -298,6 +296,7 @@ public void verifyLoginAvailabilityExceptionFlow() throws Exception { osfCredential.setUsername(AbstractTestUtils.CONST_MAIL); osfRemoteAuthenticate.setSingleEntitlement(true); + osfRemoteAuthenticate.setLoginAvailability(false); osfRemoteAuthenticate .setInstitutionsLoginAvailabilityUrl(AbstractTestUtils.CONST_INSTITUTION_LOGIN_AVAILABILITY_URL); osfRemoteAuthenticate.notifyRemotePrincipalAuthenticated(osfCredential); diff --git a/cas-server-support-osf/src/test/java/io/cos/cas/mock/MockNormalizeRemotePrincipalWithEntitlement.java b/cas-server-support-osf/src/test/java/io/cos/cas/mock/MockNormalizeRemotePrincipalWithEntitlement.java index 76b01cf9..6b81906d 100644 --- a/cas-server-support-osf/src/test/java/io/cos/cas/mock/MockNormalizeRemotePrincipalWithEntitlement.java +++ b/cas-server-support-osf/src/test/java/io/cos/cas/mock/MockNormalizeRemotePrincipalWithEntitlement.java @@ -3,15 +3,12 @@ import java.io.ByteArrayInputStream; import java.io.IOException; -import org.apache.http.HttpStatus; import org.apache.http.HttpResponse; -import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; import org.apache.http.entity.BasicHttpEntity; import org.jasig.cas.CentralAuthenticationService; import org.json.JSONObject; import org.mockito.Mockito; -import org.springframework.util.StringUtils; import io.cos.cas.AbstractTestUtils; import io.cos.cas.authentication.OpenScienceFrameworkCredential; @@ -24,12 +21,12 @@ public class MockNormalizeRemotePrincipalWithEntitlement extends MockNormalizeRemotePrincipal { private boolean isSingleEntitlement; - private String loginAvailability; + private boolean isLoginAvailability; public MockNormalizeRemotePrincipalWithEntitlement(final CentralAuthenticationService centralAuthenticationService) { super(centralAuthenticationService); this.isSingleEntitlement = false; - this.loginAvailability = ""; + this.isLoginAvailability = false; } @Override @@ -41,7 +38,7 @@ protected JSONObject normalizeRemotePrincipal(final OpenScienceFrameworkCredenti user.put("fullname", AbstractTestUtils.CONST_DISPLAY_NAME); if (isSingleEntitlement) { - user.put("eduPersonEntitlement", AbstractTestUtils.CONST_SINGLE_ENTITLEMENT_INPUT); + user.put("entitlement", AbstractTestUtils.CONST_SINGLE_ENTITLEMENT_INPUT); } provider.put("id", credential.getInstitutionId()); @@ -52,18 +49,13 @@ protected JSONObject normalizeRemotePrincipal(final OpenScienceFrameworkCredenti protected HttpResponse callLoginAvailabilityAPI(final JSONObject bodyObj) throws IOException, ClientProtocolException { final HttpResponse mockedResponse = Mockito.mock(HttpResponse.class); - final StatusLine statusLine = Mockito.mock(StatusLine.class); final BasicHttpEntity entity = new BasicHttpEntity(); - String bodyResponse = "{\"meta\":{\"version\":\"2.0\"}}"; - if (StringUtils.hasText(this.loginAvailability)) { - bodyResponse = "{\"login_availability\":\"" + this.loginAvailability + "\",\"meta\":{\"version\":\"2.0\"}}"; - Mockito.when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK); - } else { - Mockito.when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_FORBIDDEN); + String bodyResponse = "{\"login_availability\":false,\"meta\":{\"version\":\"2.0\"}}"; + if (this.isLoginAvailability) { + bodyResponse = "{\"login_availability\":true,\"meta\":{\"version\":\"2.0\"}}"; } entity.setContent(new ByteArrayInputStream(bodyResponse.getBytes())); - Mockito.when(mockedResponse.getStatusLine()).thenReturn(statusLine); Mockito.when(mockedResponse.getEntity()).thenReturn(entity); return mockedResponse; } @@ -72,8 +64,8 @@ public void setSingleEntitlement(final boolean isSingleEntitlement) { this.isSingleEntitlement = isSingleEntitlement; } - public void setLoginAvailability(final String loginAvailability) { - this.loginAvailability = loginAvailability; + public void setLoginAvailability(final boolean isLoginAvailability) { + this.isLoginAvailability = isLoginAvailability; } } diff --git a/cas-server-support-osf/src/test/java/io/cos/cas/mock/MockNotifyRemotePrincipalAuthenticated.java b/cas-server-support-osf/src/test/java/io/cos/cas/mock/MockNotifyRemotePrincipalAuthenticated.java index d70330fb..a878d4fa 100644 --- a/cas-server-support-osf/src/test/java/io/cos/cas/mock/MockNotifyRemotePrincipalAuthenticated.java +++ b/cas-server-support-osf/src/test/java/io/cos/cas/mock/MockNotifyRemotePrincipalAuthenticated.java @@ -23,9 +23,6 @@ public MockNotifyRemotePrincipalAuthenticated(final CentralAuthenticationService @Override protected PrincipalAuthenticationResult notifyRemotePrincipalAuthenticated( final OpenScienceFrameworkCredential credential) throws AccountException { - return new PrincipalAuthenticationResult( - AbstractTestUtils.CONST_MAIL, - AbstractTestUtils.CONST_INSTITUTION_ID, - AbstractTestUtils.CONST_JSON_STRING); + return new PrincipalAuthenticationResult(AbstractTestUtils.CONST_MAIL, AbstractTestUtils.CONST_INSTITUTION_ID); } } diff --git a/cas-server-webapp/src/main/resources/messages.properties b/cas-server-webapp/src/main/resources/messages.properties index f3407fd1..8c3a4194 100644 --- a/cas-server-webapp/src/main/resources/messages.properties +++ b/cas-server-webapp/src/main/resources/messages.properties @@ -164,13 +164,6 @@ screen.institutionloginfailed.message=Your request cannot be completed at this t is in error, please contact Support for help and \ include the error code below. -# Institution Login Failure(LoA) Page -screen.institutionloginfailedloa.heading=Institution login failed -screen.institutionloginfailedloa.message=Does not meet the required AAL and IAL.

\ - If you believe this is in error,\ - please contact Support for help and \ - include the error code below. - # OAuth screen.oauth.confirm.header=Authorize application screen.oauth.confirm.message=

{0}

has asked for the following permission(s) to access your GakuNin RDM account. diff --git a/cas-server-webapp/src/main/webapp/WEB-INF/view/jsp/default/ui/casInstitutionLoginAvailabilityFailedView.jsp b/cas-server-webapp/src/main/webapp/WEB-INF/view/jsp/default/ui/casInstitutionLoginAvailabilityFailedView.jsp index ec79a5e0..3e8064c7 100644 --- a/cas-server-webapp/src/main/webapp/WEB-INF/view/jsp/default/ui/casInstitutionLoginAvailabilityFailedView.jsp +++ b/cas-server-webapp/src/main/webapp/WEB-INF/view/jsp/default/ui/casInstitutionLoginAvailabilityFailedView.jsp @@ -16,9 +16,26 @@ --%> -<%-- Login availability failed redirect page --%> +<%-- Login availability failed page --%> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> - - + + +
+

+

+
+ + + + + + + + + + diff --git a/cas-server-webapp/src/main/webapp/WEB-INF/view/jsp/default/ui/casInstitutionLoginFailedLoAView.jsp b/cas-server-webapp/src/main/webapp/WEB-INF/view/jsp/default/ui/casInstitutionLoginFailedLoAView.jsp deleted file mode 100644 index b9bc6f2c..00000000 --- a/cas-server-webapp/src/main/webapp/WEB-INF/view/jsp/default/ui/casInstitutionLoginFailedLoAView.jsp +++ /dev/null @@ -1,42 +0,0 @@ -<%-- - - Copyright (c) 2016. Center for Open Science - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---%> - -<%-- Institution login exception page --%> - - - -
-

-

-

errorCode=${casViewErrorCode}

-
- - - - - - - - - - diff --git a/cas-server-webapp/src/main/webapp/WEB-INF/webflow/login/login-webflow.xml b/cas-server-webapp/src/main/webapp/WEB-INF/webflow/login/login-webflow.xml index ae648b2a..11c45267 100644 --- a/cas-server-webapp/src/main/webapp/WEB-INF/webflow/login/login-webflow.xml +++ b/cas-server-webapp/src/main/webapp/WEB-INF/webflow/login/login-webflow.xml @@ -209,7 +209,6 @@ - @@ -313,12 +312,6 @@ - - - - - - diff --git a/cas-server-webapp/src/main/webapp/WEB-INF/webflow/logout/logout-webflow.xml b/cas-server-webapp/src/main/webapp/WEB-INF/webflow/logout/logout-webflow.xml index 5e7f22fa..2108fc00 100644 --- a/cas-server-webapp/src/main/webapp/WEB-INF/webflow/logout/logout-webflow.xml +++ b/cas-server-webapp/src/main/webapp/WEB-INF/webflow/logout/logout-webflow.xml @@ -25,10 +25,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow.xsd"> - - - - @@ -52,14 +48,9 @@ - + - - - - -