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);
}
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());
}
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())));
}
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));
}
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()));
}
Aggregations