Search in sources :

Example 1 with AccountRegistrationRequest

use of org.apereo.cas.acct.AccountRegistrationRequest in project cas by apereo.

the class RestfulAccountRegistrationProvisionerTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    try (val webServer = new MockWebServer(5002, HttpStatus.OK)) {
        webServer.start();
        val registrationRequest = new AccountRegistrationRequest(Map.of("username", "casuser"));
        val results = accountMgmtRegistrationProvisioner.provision(registrationRequest);
        assertTrue(results.isSuccess());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) AccountRegistrationRequest(org.apereo.cas.acct.AccountRegistrationRequest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with AccountRegistrationRequest

use of org.apereo.cas.acct.AccountRegistrationRequest in project cas by apereo.

the class RestfulAccountRegistrationProvisionerTests method verifyOperationFails.

@Test
public void verifyOperationFails() throws Exception {
    try (val webServer = new MockWebServer(5002, HttpStatus.INTERNAL_SERVER_ERROR)) {
        webServer.start();
        val registrationRequest = new AccountRegistrationRequest(Map.of("username", "casuser"));
        val results = accountMgmtRegistrationProvisioner.provision(registrationRequest);
        assertFalse(results.isSuccess());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) AccountRegistrationRequest(org.apereo.cas.acct.AccountRegistrationRequest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with AccountRegistrationRequest

use of org.apereo.cas.acct.AccountRegistrationRequest in project cas by apereo.

the class ScimAccountRegistrationProvisionerTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    val registrationRequest = new AccountRegistrationRequest(Map.of("username", UUID.randomUUID().toString()));
    val results = accountMgmtRegistrationProvisioner.provision(registrationRequest);
    assertTrue(results.isSuccess());
}
Also used : lombok.val(lombok.val) AccountRegistrationRequest(org.apereo.cas.acct.AccountRegistrationRequest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with AccountRegistrationRequest

use of org.apereo.cas.acct.AccountRegistrationRequest in project cas by apereo.

the class ChainingAccountRegistrationProvisioner method provision.

@Audit(action = AuditableActions.ACCOUNT_REGISTRATION, actionResolverName = AuditActionResolvers.ACCOUNT_REGISTRATION_PROVISIONING_ACTION_RESOLVER, resourceResolverName = AuditResourceResolvers.ACCOUNT_REGISTRATION_PROVISIONING_RESOURCE_RESOLVER)
@Override
public AccountRegistrationResponse provision(final AccountRegistrationRequest request) throws Exception {
    val aggregate = new AccountRegistrationResponse();
    provisioners.forEach(Unchecked.consumer(p -> aggregate.collect(p.provision(request))));
    return aggregate;
}
Also used : lombok.val(lombok.val) List(java.util.List) Unchecked(org.jooq.lambda.Unchecked) AccountRegistrationRequest(org.apereo.cas.acct.AccountRegistrationRequest) AccountRegistrationResponse(org.apereo.cas.acct.AccountRegistrationResponse) Audit(org.apereo.inspektr.audit.annotation.Audit) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) AuditResourceResolvers(org.apereo.cas.audit.AuditResourceResolvers) AuditableActions(org.apereo.cas.audit.AuditableActions) AuditActionResolvers(org.apereo.cas.audit.AuditActionResolvers) AccountRegistrationResponse(org.apereo.cas.acct.AccountRegistrationResponse) Audit(org.apereo.inspektr.audit.annotation.Audit)

Example 5 with AccountRegistrationRequest

use of org.apereo.cas.acct.AccountRegistrationRequest in project cas by apereo.

the class RestfulAccountRegistrationProvisioner method provision.

@Override
public AccountRegistrationResponse provision(final AccountRegistrationRequest request) throws Exception {
    HttpResponse response = null;
    try {
        val headers = new HashMap<String, Object>();
        headers.put("Content-Type", MediaType.APPLICATION_JSON);
        headers.put("Accept", MediaType.APPLICATION_JSON);
        headers.putAll(properties.getHeaders());
        val exec = HttpUtils.HttpExecutionRequest.builder().basicAuthPassword(properties.getBasicAuthPassword()).basicAuthUsername(properties.getBasicAuthUsername()).method(HttpMethod.POST).url(properties.getUrl()).headers(headers).entity(MAPPER.writeValueAsString(request)).build();
        response = HttpUtils.execute(exec);
        if (HttpStatus.valueOf(response.getStatusLine().getStatusCode()).is2xxSuccessful()) {
            val entity = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
            val success = AccountRegistrationResponse.success();
            Arrays.stream(response.getAllHeaders()).forEach(header -> success.putProperty(header.getName(), header.getValue()));
            FunctionUtils.doIf(StringUtils.isNotBlank(entity), value -> success.putProperty("entity", value)).accept(StringUtils.defaultString(entity));
            success.putProperty("status", response.getStatusLine().getStatusCode());
            success.putProperty("entity", StringUtils.defaultString(entity));
            return success;
        }
        val details = CollectionUtils.wrap("status", response.getStatusLine().getStatusCode(), "reason", response.getStatusLine().getReasonPhrase());
        Arrays.stream(response.getAllHeaders()).forEach(header -> details.put(header.getName(), header.getValue()));
        return new AccountRegistrationResponse(details);
    } finally {
        HttpUtils.close(response);
    }
}
Also used : lombok.val(lombok.val) Arrays(java.util.Arrays) AccountRegistrationRequest(org.apereo.cas.acct.AccountRegistrationRequest) RestfulAccountManagementRegistrationProvisioningProperties(org.apereo.cas.configuration.model.support.account.provision.RestfulAccountManagementRegistrationProvisioningProperties) MediaType(org.springframework.http.MediaType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) HttpMethod(org.springframework.http.HttpMethod) HashMap(java.util.HashMap) HttpUtils(org.apereo.cas.util.HttpUtils) StringUtils(org.apache.commons.lang3.StringUtils) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) HttpStatus(org.springframework.http.HttpStatus) FunctionUtils(org.apereo.cas.util.function.FunctionUtils) AccountRegistrationResponse(org.apereo.cas.acct.AccountRegistrationResponse) JacksonObjectMapperFactory(org.apereo.cas.util.serialization.JacksonObjectMapperFactory) CollectionUtils(org.apereo.cas.util.CollectionUtils) HttpResponse(org.apache.http.HttpResponse) HashMap(java.util.HashMap) AccountRegistrationResponse(org.apereo.cas.acct.AccountRegistrationResponse) HttpResponse(org.apache.http.HttpResponse)

Aggregations

lombok.val (lombok.val)8 AccountRegistrationRequest (org.apereo.cas.acct.AccountRegistrationRequest)8 Test (org.junit.jupiter.api.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 AccountRegistrationResponse (org.apereo.cas.acct.AccountRegistrationResponse)2 MockWebServer (org.apereo.cas.util.MockWebServer)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 IOUtils (org.apache.commons.io.IOUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 HttpResponse (org.apache.http.HttpResponse)1 AuditActionResolvers (org.apereo.cas.audit.AuditActionResolvers)1 AuditResourceResolvers (org.apereo.cas.audit.AuditResourceResolvers)1 AuditableActions (org.apereo.cas.audit.AuditableActions)1 RestfulAccountManagementRegistrationProvisioningProperties (org.apereo.cas.configuration.model.support.account.provision.RestfulAccountManagementRegistrationProvisioningProperties)1 CollectionUtils (org.apereo.cas.util.CollectionUtils)1