use of org.apache.syncope.common.lib.to.ApplicationTO in project syncope by apache.
the class ApplicationServiceImpl method create.
@Override
public Response create(final ApplicationTO applicationTO) {
ApplicationTO created = logic.create(applicationTO);
URI location = uriInfo.getAbsolutePathBuilder().path(created.getKey()).build();
return Response.created(location).header(RESTHeaders.RESOURCE_KEY, created.getKey()).build();
}
use of org.apache.syncope.common.lib.to.ApplicationTO in project syncope by apache.
the class ApplicationITCase method read.
@Test
public void read() {
ApplicationTO mightyApp = applicationService.read("mightyApp");
assertNotNull(mightyApp);
assertEquals(2, mightyApp.getPrivileges().size());
assertTrue(mightyApp.getPrivileges().stream().anyMatch(privilege -> "postMighty".equals(privilege.getKey())));
PrivilegeTO getMighty = applicationService.readPrivilege("getMighty");
assertNotNull(getMighty);
assertEquals("mightyApp", getMighty.getApplication());
RoleTO role = roleService.read("Other");
assertFalse(role.getPrivileges().isEmpty());
assertEquals(1, role.getPrivileges().size());
assertTrue(role.getPrivileges().stream().anyMatch(privilege -> "postMighty".equals(privilege)));
}
use of org.apache.syncope.common.lib.to.ApplicationTO in project syncope by apache.
the class ApplicationDataBinderImpl method getApplicationTO.
@Override
public ApplicationTO getApplicationTO(final Application application) {
ApplicationTO applicationTO = new ApplicationTO();
applicationTO.setKey(application.getKey());
applicationTO.setDescription(application.getDescription());
applicationTO.getPrivileges().addAll(application.getPrivileges().stream().map(privilege -> getPrivilegeTO(privilege)).collect(Collectors.toList()));
return applicationTO;
}
use of org.apache.syncope.common.lib.to.ApplicationTO in project syncope by apache.
the class ApplicationDataBinderImpl method update.
@Override
public Application update(final Application toBeUpdated, final ApplicationTO applicationTO) {
toBeUpdated.setKey(applicationTO.getKey());
Application application = applicationDAO.save(toBeUpdated);
application.setDescription(applicationTO.getDescription());
// 1. add or update all (valid) privileges from TO
applicationTO.getPrivileges().forEach(privilegeTO -> {
if (privilegeTO == null) {
LOG.error("Null {}", PrivilegeTO.class.getSimpleName());
} else {
Privilege privilege = applicationDAO.findPrivilege(privilegeTO.getKey());
if (privilege == null) {
privilege = entityFactory.newEntity(Privilege.class);
privilege.setKey(privilegeTO.getKey());
privilege.setApplication(application);
application.add(privilege);
} else if (!application.equals(privilege.getApplication())) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPrivilege);
sce.getElements().add("Privilege " + privilege.getKey() + " already owned by " + privilege.getApplication());
throw sce;
}
privilege.setDescription(privilegeTO.getDescription());
privilege.setSpec(privilegeTO.getSpec());
}
});
// 2. remove all privileges not contained in the TO
for (Iterator<? extends Privilege> itor = application.getPrivileges().iterator(); itor.hasNext(); ) {
Privilege privilege = itor.next();
if (!applicationTO.getPrivileges().stream().anyMatch(privilegeTO -> privilege.getKey().equals(privilegeTO.getKey()))) {
privilege.setApplication(null);
itor.remove();
}
}
return application;
}
use of org.apache.syncope.common.lib.to.ApplicationTO in project syncope by apache.
the class ApplicationITCase method crud.
@Test
public void crud() {
// 1. create application
ApplicationTO application = new ApplicationTO();
application.setKey(UUID.randomUUID().toString());
PrivilegeTO privilegeTO = new PrivilegeTO();
privilegeTO.setKey(UUID.randomUUID().toString());
privilegeTO.setSpec("{ \"one\": true }");
application.getPrivileges().add(privilegeTO);
privilegeTO = new PrivilegeTO();
privilegeTO.setKey(UUID.randomUUID().toString());
privilegeTO.setSpec("{ \"two\": true }");
application.getPrivileges().add(privilegeTO);
privilegeTO = new PrivilegeTO();
privilegeTO.setKey(UUID.randomUUID().toString());
privilegeTO.setSpec("{ \"three\": true }");
application.getPrivileges().add(privilegeTO);
Response response = applicationService.create(application);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
application = getObject(response.getLocation(), ApplicationService.class, ApplicationTO.class);
assertNotNull(application);
assertNull(application.getDescription());
assertEquals(3, application.getPrivileges().size());
// 2. update application
application.setDescription("A description");
application.getPrivileges().remove(1);
applicationService.update(application);
application = applicationService.read(application.getKey());
assertNotNull(application);
assertNotNull(application.getDescription());
assertEquals(2, application.getPrivileges().size());
// 3. assign application's privileges to a new role
RoleTO role = new RoleTO();
role.setKey("privileged");
role.getPrivileges().addAll(application.getPrivileges().stream().map(EntityTO::getKey).collect(Collectors.toList()));
response = roleService.create(role);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
role = getObject(response.getLocation(), RoleService.class, RoleTO.class);
assertNotNull(role);
assertEquals(2, role.getPrivileges().size());
// 4. delete application => delete privileges
applicationService.delete(application.getKey());
try {
applicationService.read(application.getKey());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
role = roleService.read(role.getKey());
assertNotNull(role);
assertTrue(role.getPrivileges().isEmpty());
}
Aggregations