Search in sources :

Example 31 with Clients

use of org.pac4j.core.client.Clients in project pac4j by pac4j.

the class DefaultCallbackLogicTests method testCallback.

@Test
public void testCallback() {
    final String originalSessionId = request.getSession().getId();
    request.setParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, NAME);
    final CommonProfile profile = new CommonProfile();
    final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), profile);
    config.setClients(new Clients(CALLBACK_URL, indirectClient));
    config.getClients().init();
    call();
    final HttpSession session = request.getSession();
    final String newSessionId = session.getId();
    final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) session.getAttribute(Pac4jConstants.USER_PROFILES);
    assertTrue(profiles.containsValue(profile));
    assertEquals(1, profiles.size());
    assertNotEquals(newSessionId, originalSessionId);
    assertEquals(302, response.getStatus());
    assertEquals(Pac4jConstants.DEFAULT_URL_VALUE, response.getRedirectedUrl());
}
Also used : CommonProfile(org.pac4j.core.profile.CommonProfile) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) MockCredentials(org.pac4j.core.credentials.MockCredentials) HttpSession(javax.servlet.http.HttpSession) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) IndirectClient(org.pac4j.core.client.IndirectClient) Clients(org.pac4j.core.client.Clients) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 32 with Clients

use of org.pac4j.core.client.Clients in project cas by apereo.

the class DelegatedClientAuthenticationHandlerTests method initialize.

@BeforeEach
public void initialize() {
    this.fbClient = new FacebookClient();
    val clients = new Clients(CALLBACK_URL, fbClient);
    this.handler = new DelegatedClientAuthenticationHandler(StringUtils.EMPTY, 0, mock(ServicesManager.class), PrincipalFactoryUtils.newPrincipalFactory(), clients, DelegatedClientUserProfileProvisioner.noOp(), JEESessionStore.INSTANCE);
    this.handler.setTypedIdUsed(true);
    val credentials = new OAuth20Credentials(null);
    this.clientCredential = new ClientCredential(credentials, fbClient.getName());
    val mock = new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse());
    ExternalContextHolder.setExternalContext(mock);
}
Also used : lombok.val(lombok.val) ClientCredential(org.apereo.cas.authentication.principal.ClientCredential) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FacebookClient(org.pac4j.oauth.client.FacebookClient) OAuth20Credentials(org.pac4j.oauth.credentials.OAuth20Credentials) Clients(org.pac4j.core.client.Clients) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 33 with Clients

use of org.pac4j.core.client.Clients in project cas by apereo.

the class SamlIdentityProviderDiscoveryConfiguration method samlIdentityProviderEntityParser.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnMissingBean(name = "samlIdentityProviderEntityParser")
public Supplier<List<SamlIdentityProviderEntityParser>> samlIdentityProviderEntityParser(final CasConfigurationProperties casProperties, @Qualifier("builtClients") final Clients builtClients) {
    val parsers = new ArrayList<SamlIdentityProviderEntityParser>();
    val resource = casProperties.getAuthn().getPac4j().getSamlDiscovery().getResource();
    resource.stream().filter(res -> res.getLocation() != null).forEach(Unchecked.consumer(res -> parsers.add(new SamlIdentityProviderEntityParser(res.getLocation()))));
    builtClients.findAllClients().stream().filter(c -> c instanceof SAML2Client).map(SAML2Client.class::cast).forEach(c -> {
        c.init();
        val entity = new SamlIdentityProviderEntity();
        entity.setEntityID(c.getIdentityProviderResolvedEntityId());
        parsers.add(new SamlIdentityProviderEntityParser(entity));
    });
    return () -> parsers;
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ArgumentExtractor(org.apereo.cas.web.support.ArgumentExtractor) SAML2Client(org.pac4j.saml.client.SAML2Client) FlowBuilderServices(org.springframework.webflow.engine.builder.support.FlowBuilderServices) Supplier(java.util.function.Supplier) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ArrayList(java.util.ArrayList) Clients(org.pac4j.core.client.Clients) CasWebflowConstants(org.apereo.cas.web.flow.CasWebflowConstants) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ServicesManager(org.apereo.cas.services.ServicesManager) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Unchecked(org.jooq.lambda.Unchecked) FlowDefinitionRegistry(org.springframework.webflow.definition.registry.FlowDefinitionRegistry) lombok.val(lombok.val) ScopedProxyMode(org.springframework.context.annotation.ScopedProxyMode) ConditionalOnFeature(org.apereo.cas.util.spring.boot.ConditionalOnFeature) SamlIdentityProviderEntity(org.apereo.cas.entity.SamlIdentityProviderEntity) Configuration(org.springframework.context.annotation.Configuration) SamlIdentityProviderDiscoveryWebflowConfigurer(org.apereo.cas.web.flow.SamlIdentityProviderDiscoveryWebflowConfigurer) List(java.util.List) AuditableExecution(org.apereo.cas.audit.AuditableExecution) CasFeatureModule(org.apereo.cas.configuration.support.CasFeatureModule) SamlIdentityProviderDiscoveryFeedController(org.apereo.cas.web.SamlIdentityProviderDiscoveryFeedController) DelegatedAuthenticationAccessStrategyHelper(org.apereo.cas.validation.DelegatedAuthenticationAccessStrategyHelper) CasWebflowConfigurer(org.apereo.cas.web.flow.CasWebflowConfigurer) SamlIdentityProviderEntityParser(org.apereo.cas.entity.SamlIdentityProviderEntityParser) Bean(org.springframework.context.annotation.Bean) CasWebflowExecutionPlanConfigurer(org.apereo.cas.web.flow.CasWebflowExecutionPlanConfigurer) ArrayList(java.util.ArrayList) SAML2Client(org.pac4j.saml.client.SAML2Client) SamlIdentityProviderEntityParser(org.apereo.cas.entity.SamlIdentityProviderEntityParser) SamlIdentityProviderEntity(org.apereo.cas.entity.SamlIdentityProviderEntity) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

Clients (org.pac4j.core.client.Clients)33 Test (org.junit.Test)19 CommonProfile (org.pac4j.core.profile.CommonProfile)19 MockIndirectClient (org.pac4j.core.client.MockIndirectClient)16 Client (org.pac4j.core.client.Client)13 WebContext (org.pac4j.core.context.WebContext)10 MockWebContext (org.pac4j.core.context.MockWebContext)7 FacebookClient (org.pac4j.oauth.client.FacebookClient)6 Credentials (org.pac4j.core.credentials.Credentials)5 IndirectClient (org.pac4j.core.client.IndirectClient)4 MockCredentials (org.pac4j.core.credentials.MockCredentials)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)4 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 HttpSession (javax.servlet.http.HttpSession)3 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)3 BaseClient (org.pac4j.core.client.BaseClient)3 Config (org.pac4j.core.config.Config)3