Example #1
0
 @Test
 public void testForceAuthIsSetForPostBinding() throws Exception {
   final SAML2Client client = getClient();
   client.getConfiguration().setForceAuth(true);
   final WebContext context =
       new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
   final RedirectAction action = client.getRedirectAction(context);
   assertTrue(getDecodedAuthnRequest(action.getContent()).contains("ForceAuthn=\"true\""));
 }
Example #2
0
 @Test
 public void testSetComparisonTypeWithPostBinding() throws Exception {
   final SAML2Client client = getClient();
   client
       .getConfiguration()
       .setComparisonType(AuthnContextComparisonTypeEnumeration.EXACT.toString());
   final WebContext context =
       new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
   final RedirectAction action = client.getRedirectAction(context);
   assertTrue(getDecodedAuthnRequest(action.getContent()).contains("Comparison=\"exact\""));
 }
Example #3
0
 @Test
 public void testRelayState() throws HttpAction {
   final SAML2Client client = getClient();
   final WebContext context =
       new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
   context.setSessionAttribute(SAML2Client.SAML_RELAY_STATE_ATTRIBUTE, "relayState");
   final RedirectAction action = client.getRedirectAction(context);
   assertTrue(
       action
           .getContent()
           .contains("<input type=\"hidden\" name=\"RelayState\" value=\"relayState\"/>"));
 }
Example #4
0
 @Test
 public void testCustomSpEntityIdForPostBinding() throws Exception {
   final SAML2Client client = getClient();
   client.getConfiguration().setServiceProviderEntityId("http://localhost:8080/callback");
   final WebContext context =
       new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
   final RedirectAction action = client.getRedirectAction(context);
   assertTrue(
       getDecodedAuthnRequest(action.getContent())
           .contains(
               "<saml2:Issuer xmlns:saml2=\"urn:oasis:names:tc:SAML:2.0:assertion\">http://localhost:8080/callback</saml2:Issuer>"));
 }
Example #5
0
 @Test
 public void testStateParameter() {
   final MockIndirectClient client =
       new MockIndirectClient(
           TYPE, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
   final MockWebContext context = MockWebContext.create();
   TestsHelper.expectException(() -> client.redirect(context));
 }
Example #6
0
 @Test
 public void testNullCredentials() throws RequiresHttpAction {
   final MockIndirectClient client =
       new MockIndirectClient(
           TYPE, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
   final MockWebContext context = MockWebContext.create();
   client.setCallbackUrl(CALLBACK_URL);
   assertNull(client.getUserProfile(null, context));
 }
Example #7
0
 @Test
 public void testIndirectClientWithImmediate() throws RequiresHttpAction {
   final MockIndirectClient client =
       new MockIndirectClient(
           TYPE, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
   client.setCallbackUrl(CALLBACK_URL);
   final MockWebContext context = MockWebContext.create();
   client.redirect(context);
   final String redirectionUrl = context.getResponseLocation();
   assertEquals(LOGIN_URL, redirectionUrl);
 }
Example #8
0
  @Override
  protected RedirectAction retrieveRedirectAction(final WebContext wc) {

    ExtendedSAMLMessageContext context = this.contextProvider.buildSpAndIdpContext(wc);
    final String relayState = getStateParameter(wc);

    AuthnRequest authnRequest = this.authnRequestBuilder.build(context);

    this.handler.sendMessage(context, authnRequest, relayState);

    if (destinationBindingType.equalsIgnoreCase(SAMLConstants.SAML2_POST_BINDING_URI)) {
      String content =
          ((SimpleResponseAdapter) context.getOutboundMessageTransport()).getOutgoingContent();
      return RedirectAction.success(content);
    } else {
      String location =
          ((SimpleResponseAdapter) context.getOutboundMessageTransport()).getRedirectUrl();
      return RedirectAction.redirect(location);
    }
  }
Example #9
0
 /**
  * Get the redirection url.
  *
  * @param context the web context
  * @return the redirection url
  */
 @Override
 protected RedirectAction retrieveRedirectAction(final WebContext context) {
   final String redirectionUrl =
       CommonUtils.constructRedirectUrl(
           this.casLoginUrl,
           SERVICE_PARAMETER,
           computeFinalCallbackUrl(context),
           this.renew,
           this.gateway);
   logger.debug("redirectionUrl : {}", redirectionUrl);
   return RedirectAction.redirect(redirectionUrl);
 }
Example #10
0
 @Test
 public void testSaveAlreadyTried() throws RequiresHttpAction {
   final MockIndirectClient client =
       new MockIndirectClient(
           TYPE, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
   client.setCallbackUrl(CALLBACK_URL);
   final MockWebContext context = MockWebContext.create();
   client.getCredentials(context);
   assertEquals(
       "true",
       (String)
           context.getSessionAttribute(
               client.getName() + IndirectClient.ATTEMPTED_AUTHENTICATION_SUFFIX));
 }
Example #11
0
 @Test
 public void testAlreadyTried() {
   final MockIndirectClient client =
       new MockIndirectClient(
           TYPE, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
   client.setCallbackUrl(CALLBACK_URL);
   final MockWebContext context = MockWebContext.create();
   context.setSessionAttribute(
       client.getName() + IndirectClient.ATTEMPTED_AUTHENTICATION_SUFFIX, "true");
   final RequiresHttpAction e =
       (RequiresHttpAction) TestsHelper.expectException(() -> client.redirect(context));
   assertEquals(401, e.getCode());
   assertEquals(401, context.getResponseStatus());
 }
Example #12
0
 @Test
 public void testAjaxRequest() {
   final MockIndirectClient client =
       new MockIndirectClient(
           TYPE, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
   client.setCallbackUrl(CALLBACK_URL);
   final MockWebContext context =
       MockWebContext.create()
           .addRequestHeader(HttpConstants.AJAX_HEADER_NAME, HttpConstants.AJAX_HEADER_VALUE);
   final RequiresHttpAction e =
       (RequiresHttpAction) TestsHelper.expectException(() -> client.redirect(context));
   assertEquals(401, e.getCode());
   assertEquals(401, context.getResponseStatus());
 }
Example #13
0
 @Override
 protected RedirectAction retrieveRedirectAction(final WebContext context) {
   return RedirectAction.redirect(getContextualCallbackUrl(context));
 }