Search in sources :

Example 1 with RestAuthenticationPolicyProperties

use of org.apereo.cas.configuration.model.core.authentication.RestAuthenticationPolicyProperties in project cas by apereo.

the class CoreAuthenticationUtilsTests method verifyAuthnPolicyRest.

@Test
public void verifyAuthnPolicyRest() throws Exception {
    val props = new AuthenticationPolicyProperties();
    val rest = new RestAuthenticationPolicyProperties();
    rest.setUrl("http://example.org");
    props.getRest().add(rest);
    val policy = CoreAuthenticationUtils.newAuthenticationPolicy(props);
    verifySerialization(policy);
}
Also used : lombok.val(lombok.val) RestAuthenticationPolicyProperties(org.apereo.cas.configuration.model.core.authentication.RestAuthenticationPolicyProperties) RestAuthenticationPolicyProperties(org.apereo.cas.configuration.model.core.authentication.RestAuthenticationPolicyProperties) AuthenticationPolicyProperties(org.apereo.cas.configuration.model.core.authentication.AuthenticationPolicyProperties) GroovyAuthenticationPolicyProperties(org.apereo.cas.configuration.model.core.authentication.GroovyAuthenticationPolicyProperties) Test(org.junit.jupiter.api.Test)

Example 2 with RestAuthenticationPolicyProperties

use of org.apereo.cas.configuration.model.core.authentication.RestAuthenticationPolicyProperties in project cas by apereo.

the class RestfulAuthenticationPolicyTests method assertPolicyFails.

private static void assertPolicyFails(final int port, final HttpStatus status, final Class<? extends Throwable> exceptionClass) {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    try (val webServer = new MockWebServer(port, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), status)) {
        webServer.start();
        val props = new RestAuthenticationPolicyProperties();
        props.setUrl("http://localhost:" + port);
        val policy = new RestfulAuthenticationPolicy(props);
        assertThrowsWithRootCause(GeneralSecurityException.class, exceptionClass, () -> policy.isSatisfiedBy(CoreAuthenticationTestUtils.getAuthentication("casuser"), new LinkedHashSet<>(), applicationContext, Optional.empty()));
    }
}
Also used : lombok.val(lombok.val) RestAuthenticationPolicyProperties(org.apereo.cas.configuration.model.core.authentication.RestAuthenticationPolicyProperties) LinkedHashSet(java.util.LinkedHashSet) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource)

Example 3 with RestAuthenticationPolicyProperties

use of org.apereo.cas.configuration.model.core.authentication.RestAuthenticationPolicyProperties in project cas by apereo.

the class RestfulRegisteredServiceAuthenticationPolicyCriteria method toAuthenticationPolicy.

@Override
public AuthenticationPolicy toAuthenticationPolicy(final RegisteredService registeredService) {
    val props = new RestAuthenticationPolicyProperties();
    props.setUrl(url);
    props.setBasicAuthUsername(basicAuthUsername);
    props.setBasicAuthPassword(basicAuthPassword);
    return new RestfulAuthenticationPolicy(props);
}
Also used : lombok.val(lombok.val) RestAuthenticationPolicyProperties(org.apereo.cas.configuration.model.core.authentication.RestAuthenticationPolicyProperties) RestfulAuthenticationPolicy(org.apereo.cas.authentication.policy.RestfulAuthenticationPolicy)

Example 4 with RestAuthenticationPolicyProperties

use of org.apereo.cas.configuration.model.core.authentication.RestAuthenticationPolicyProperties in project cas by apereo.

the class RestfulAuthenticationPolicyTests method verifyAllowedOperation.

@Test
public void verifyAllowedOperation() throws Exception {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    try (val webServer = new MockWebServer(9200, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val props = new RestAuthenticationPolicyProperties();
        props.setUrl("http://localhost:9200");
        val policy = new RestfulAuthenticationPolicy(props);
        assertTrue(policy.isSatisfiedBy(CoreAuthenticationTestUtils.getAuthentication("casuser"), new LinkedHashSet<>(), applicationContext, Optional.empty()).isSuccess());
    }
}
Also used : lombok.val(lombok.val) RestAuthenticationPolicyProperties(org.apereo.cas.configuration.model.core.authentication.RestAuthenticationPolicyProperties) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)4 RestAuthenticationPolicyProperties (org.apereo.cas.configuration.model.core.authentication.RestAuthenticationPolicyProperties)4 MockWebServer (org.apereo.cas.util.MockWebServer)2 Test (org.junit.jupiter.api.Test)2 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)2 ByteArrayResource (org.springframework.core.io.ByteArrayResource)2 LinkedHashSet (java.util.LinkedHashSet)1 RestfulAuthenticationPolicy (org.apereo.cas.authentication.policy.RestfulAuthenticationPolicy)1 AuthenticationPolicyProperties (org.apereo.cas.configuration.model.core.authentication.AuthenticationPolicyProperties)1 GroovyAuthenticationPolicyProperties (org.apereo.cas.configuration.model.core.authentication.GroovyAuthenticationPolicyProperties)1