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