Search in sources :

Example 6 with J2EContext

use of org.pac4j.core.context.J2EContext in project pac4j by pac4j.

the class KerberosClientTests method testMissingKerberosHeader.

@Test
public void testMissingKerberosHeader() {
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    final DirectKerberosClient client = new DirectKerberosClient(new KerberosAuthenticator(krbValidator));
    KerberosCredentials credentials = client.getCredentials(new J2EContext(request, response));
    assertNull(credentials);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) KerberosAuthenticator(org.pac4j.kerberos.credentials.authenticator.KerberosAuthenticator) KerberosCredentials(org.pac4j.kerberos.credentials.KerberosCredentials) HttpServletResponse(javax.servlet.http.HttpServletResponse) J2EContext(org.pac4j.core.context.J2EContext) Test(org.junit.Test)

Example 7 with J2EContext

use of org.pac4j.core.context.J2EContext in project pac4j by pac4j.

the class PostSAML2ClientTests method testRelayState.

@Test
public void testRelayState() {
    final SAML2Client client = getClient();
    final WebContext context = new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
    context.getSessionStore().set(context, SAML2Client.SAML_RELAY_STATE_ATTRIBUTE, "relayState");
    final RedirectAction action = client.getRedirectAction(context);
    assertTrue(action.getContent().contains("<input type=\"hidden\" name=\"RelayState\" value=\"relayState\"/>"));
}
Also used : WebContext(org.pac4j.core.context.WebContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) J2EContext(org.pac4j.core.context.J2EContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) RedirectAction(org.pac4j.core.redirect.RedirectAction) Test(org.junit.Test)

Example 8 with J2EContext

use of org.pac4j.core.context.J2EContext in project pac4j by pac4j.

the class PostSAML2ClientTests method testForceAuthIsSetForPostBinding.

@Test
public void testForceAuthIsSetForPostBinding() {
    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\""));
}
Also used : WebContext(org.pac4j.core.context.WebContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) J2EContext(org.pac4j.core.context.J2EContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) RedirectAction(org.pac4j.core.redirect.RedirectAction) Test(org.junit.Test)

Example 9 with J2EContext

use of org.pac4j.core.context.J2EContext in project pac4j by pac4j.

the class PostSAML2ClientTests method testCustomSpEntityIdForPostBinding.

@Test
public void testCustomSpEntityIdForPostBinding() {
    final SAML2Client client = getClient();
    client.getConfiguration().setServiceProviderEntityId("http://localhost:8080/cb");
    final WebContext context = new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
    final RedirectAction action = client.getRedirectAction(context);
    assertTrue(getDecodedAuthnRequest(action.getContent()).contains("<saml2:Issuer " + "Format=\"urn:oasis:names:tc:SAML:2.0:nameid-format:entity\" " + "NameQualifier=\"http://localhost:8080/cb\" " + "xmlns:saml2=\"urn:oasis:names:tc:SAML:2.0:assertion\">http://localhost:8080/cb</saml2:Issuer>"));
}
Also used : WebContext(org.pac4j.core.context.WebContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) J2EContext(org.pac4j.core.context.J2EContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) RedirectAction(org.pac4j.core.redirect.RedirectAction) Test(org.junit.Test)

Example 10 with J2EContext

use of org.pac4j.core.context.J2EContext in project pac4j by pac4j.

the class RedirectSAML2ClientTests method testCustomSpEntityIdForRedirectBinding.

@Test
public void testCustomSpEntityIdForRedirectBinding() {
    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);
    final String inflated = getInflatedAuthnRequest(action.getLocation());
    assertTrue(inflated.contains("<saml2:Issuer " + "Format=\"urn:oasis:names:tc:SAML:2.0:nameid-format:entity\" " + "NameQualifier=\"http://localhost:8080/callback\" " + "xmlns:saml2=\"urn:oasis:names:tc:SAML:2.0:assertion\">http://localhost:8080/callback</saml2:Issuer>"));
}
Also used : WebContext(org.pac4j.core.context.WebContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) J2EContext(org.pac4j.core.context.J2EContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) RedirectAction(org.pac4j.core.redirect.RedirectAction) Test(org.junit.Test)

Aggregations

J2EContext (org.pac4j.core.context.J2EContext)32 RedirectAction (org.pac4j.core.redirect.RedirectAction)13 Test (org.junit.Test)11 WebContext (org.pac4j.core.context.WebContext)11 ProfileManager (org.pac4j.core.profile.ProfileManager)11 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 UnauthorizedServiceException (org.apereo.cas.services.UnauthorizedServiceException)6 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)6 UserProfile (org.pac4j.core.profile.UserProfile)6 GetMapping (org.springframework.web.bind.annotation.GetMapping)6 Service (org.apereo.cas.authentication.principal.Service)5 Authentication (org.apereo.cas.authentication.Authentication)4 AccessToken (org.apereo.cas.ticket.accesstoken.AccessToken)4 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)3 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)2 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)2 PrincipalException (org.apereo.cas.authentication.PrincipalException)2