CasRedirectionActionBuilder implements RedirectionActionBuilder { @Override public Optional<RedirectionAction> getRedirectionAction(final WebContext context) { String computeLoginUrl = configuration.computeFinalLoginUrl(context); final String computedCallbackUrl = client.computeFinalCallbackUrl(context); final String redirectionUrl = CommonUtils.constructRedirectUrl(computeLoginUrl, getServiceParameter(), computedCallbackUrl, configuration.isRenew(), configuration.isGateway(), configuration.getMethod()); logger.debug("redirectionUrl: {}", redirectionUrl); return Optional.of(RedirectionActionHelper.buildRedirectUrlAction(context, redirectionUrl)); } CasRedirectionActionBuilder(final CasConfiguration configuration, final CasClient client); @Override Optional<RedirectionAction> getRedirectionAction(final WebContext context);  }
@Test public void testRedirect() { final CasRedirectionActionBuilder builder = newBuilder(new CasConfiguration()); final RedirectionAction action = builder.getRedirectionAction(MockWebContext.create()).get(); assertTrue(action instanceof FoundAction); assertEquals(LOGIN_URL + "?service=http%3A%2F%2Fwww.pac4j.org%2Ftest.html%3Fclient_name%3DCasClient", ((FoundAction) action).getLocation()); }
@Test public void testRedirectWithMethod() { final CasConfiguration config = new CasConfiguration(); config.setMethod("post"); final CasRedirectionActionBuilder builder = newBuilder(config); final RedirectionAction action = builder.getRedirectionAction(MockWebContext.create()).get(); assertTrue(action instanceof FoundAction); assertEquals(LOGIN_URL + "?service=http%3A%2F%2Fwww.pac4j.org%2Ftest.html%3Fclient_name%3DCasClient&method=post", ((FoundAction) action).getLocation()); }
@Test public void testRedirectForSAMLProtocol() { final CasConfiguration config = new CasConfiguration(); config.setProtocol(CasProtocol.SAML); final CasRedirectionActionBuilder builder = newBuilder(config); final RedirectionAction action = builder.getRedirectionAction(MockWebContext.create()).get(); assertTrue(action instanceof FoundAction); assertEquals(LOGIN_URL + "?TARGET=http%3A%2F%2Fwww.pac4j.org%2Ftest.html%3Fclient_name%3DCasClient", ((FoundAction) action).getLocation()); }