Search in sources :

Example 16 with CasClient

use of org.pac4j.cas.client.CasClient in project cas by apereo.

the class DelegatedAuthenticationAuditResourceResolverTests method verifyAction.

@Test
public void verifyAction() {
    val r = new DelegatedAuthenticationAuditResourceResolver();
    val result = AuditableExecutionResult.builder().registeredService(CoreAuthenticationTestUtils.getRegisteredService()).service(CoreAuthenticationTestUtils.getService()).build();
    result.addProperty(CasClient.class.getSimpleName(), new CasClient(new CasConfiguration("http://cas.example.org")));
    val outcome = r.resolveFrom(mock(JoinPoint.class), result);
    assertTrue(outcome.length > 0);
}
Also used : lombok.val(lombok.val) CasConfiguration(org.pac4j.cas.config.CasConfiguration) CasClient(org.pac4j.cas.client.CasClient) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.junit.jupiter.api.Test)

Example 17 with CasClient

use of org.pac4j.cas.client.CasClient in project cas by apereo.

the class DefaultDelegatedAuthenticationDynamicDiscoveryProviderLocatorTests method verifyOperation.

@Test
public void verifyOperation() {
    val properties = new CasConfigurationProperties();
    val producer = mock(DelegatedClientIdentityProviderConfigurationProducer.class);
    val clients = mock(Clients.class);
    val client = new CasClient();
    when(clients.findClient(anyString())).thenReturn(Optional.of(client));
    val locator = new DefaultDelegatedAuthenticationDynamicDiscoveryProviderLocator(producer, clients, properties);
    assertNotNull(locator.getProviderProducer());
    assertNotNull(locator.getCasProperties());
    assertNotNull(locator.getClients());
    val request = DelegatedAuthenticationDynamicDiscoveryProviderLocator.DynamicDiscoveryProviderRequest.builder().userId("cas@example.org").build();
    var result = locator.locate(request);
    assertFalse(result.isPresent());
    properties.getAuthn().getPac4j().getCore().getDiscoverySelection().getJson().setLocation(new ClassPathResource("delegated-discovery.json"));
    result = locator.locate(request);
    assertTrue(result.isPresent());
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ClassPathResource(org.springframework.core.io.ClassPathResource) CasClient(org.pac4j.cas.client.CasClient) Test(org.junit.jupiter.api.Test)

Example 18 with CasClient

use of org.pac4j.cas.client.CasClient in project cas by apereo.

the class DelegatedClientIdentityProviderConfigurationFactoryTests method verifyRedirectUrl.

@Test
public void verifyRedirectUrl() {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    request.addParameter(CasProtocolConstants.PARAMETER_METHOD, "some-method");
    request.addParameter(casProperties.getLocale().getParamName(), "some-locale");
    request.addParameter(casProperties.getTheme().getParamName(), "some-theme");
    val context = new JEEContext(request, response);
    val service = RegisteredServiceTestUtils.getService("example");
    service.setOriginalUrl("http://service.original.url.com");
    val client = new CasClient(new CasConfiguration());
    val factory = DelegatedClientIdentityProviderConfigurationFactory.builder().casProperties(casProperties).client(client).service(service).webContext(context).build();
    val actual = factory.resolve();
    assertTrue(actual.isPresent());
    assertEquals(client.getName(), actual.get().getName());
    assertEquals("cas", actual.get().getType());
    val redirectUrl = actual.get().getRedirectUrl();
    assertNotNull(redirectUrl);
    assertTrue(redirectUrl.startsWith("clientredirect?"));
    assertTrue(redirectUrl.contains("client_name=" + client.getName()));
    assertTrue(redirectUrl.contains("method=some-method"));
    assertTrue(redirectUrl.contains("locale=some-locale"));
    assertTrue(redirectUrl.contains("theme=some-theme"));
    assertTrue(redirectUrl.contains(EncodingUtils.urlEncode(service.getOriginalUrl())));
}
Also used : lombok.val(lombok.val) CasConfiguration(org.pac4j.cas.config.CasConfiguration) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CasClient(org.pac4j.cas.client.CasClient) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with CasClient

use of org.pac4j.cas.client.CasClient in project cas by apereo.

the class SamlIdPDelegatedClientAuthenticationRequestCustomizerTests method verifyAuthorization.

@Test
public void verifyAuthorization() throws Exception {
    val saml2Client = mock(SAML2Client.class);
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val webContext = new JEEContext(request, response);
    val webApplicationService = CoreAuthenticationTestUtils.getWebApplicationService();
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() throws Throwable {
            customizer.customize(saml2Client, webContext);
        }
    });
    assertTrue(customizer.isAuthorized(webContext, saml2Client, webApplicationService));
    setAuthnRequestFor(webContext);
    assertTrue(customizer.isAuthorized(webContext, saml2Client, webApplicationService));
    setAuthnRequestFor(webContext, UUID.randomUUID().toString());
    assertFalse(customizer.isAuthorized(webContext, saml2Client, webApplicationService));
    val providerId = UUID.randomUUID().toString();
    when(saml2Client.getIdentityProviderResolvedEntityId()).thenReturn(providerId);
    setAuthnRequestFor(webContext, providerId);
    assertTrue(customizer.isAuthorized(webContext, saml2Client, webApplicationService));
    assertTrue(customizer.isAuthorized(webContext, new CasClient(), webApplicationService));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) Executable(org.junit.jupiter.api.function.Executable) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CasClient(org.pac4j.cas.client.CasClient) Test(org.junit.jupiter.api.Test)

Example 20 with CasClient

use of org.pac4j.cas.client.CasClient in project cas by apereo.

the class DefaultDelegatedClientAuthenticationWebflowManagerTests method verifyCasStoreOperation.

@Test
public void verifyCasStoreOperation() throws Exception {
    val config = new CasConfiguration();
    config.setLoginUrl("https://example.org/login");
    val client = new CasClient();
    client.setConfiguration(config);
    val ticket = delegatedClientAuthenticationWebflowManager.store(context, client);
    assertNotNull(ticketRegistry.getTicket(ticket.getId()));
    val service = delegatedClientAuthenticationWebflowManager.retrieve(requestContext, context, client);
    assertNotNull(service);
    assertNull(ticketRegistry.getTicket(ticket.getId()));
}
Also used : lombok.val(lombok.val) CasConfiguration(org.pac4j.cas.config.CasConfiguration) CasClient(org.pac4j.cas.client.CasClient) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

CasClient (org.pac4j.cas.client.CasClient)21 CasConfiguration (org.pac4j.cas.config.CasConfiguration)15 lombok.val (lombok.val)14 Test (org.junit.jupiter.api.Test)11 OidcClient (org.pac4j.oidc.client.OidcClient)6 SAML2Client (org.pac4j.saml.client.SAML2Client)6 JEEContext (org.pac4j.core.context.JEEContext)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)5 FacebookClient (org.pac4j.oauth.client.FacebookClient)4 TwitterClient (org.pac4j.oauth.client.TwitterClient)4 GoogleOidcClient (org.pac4j.oidc.client.GoogleOidcClient)4 Verb (com.github.scribejava.core.model.Verb)3 JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)3 Collection (java.util.Collection)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 StringUtils (org.apache.commons.lang3.StringUtils)3 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)3