use of org.apache.syncope.core.persistence.api.entity.Privilege in project syncope by apache.
the class RoleDataBinderImpl method update.
@Override
public Role update(final Role toBeUpdated, final RoleTO roleTO) {
toBeUpdated.setKey(roleTO.getKey());
Role role = roleDAO.save(toBeUpdated);
role.getEntitlements().clear();
role.getEntitlements().addAll(roleTO.getEntitlements());
role.getRealms().clear();
for (String realmFullPath : roleTO.getRealms()) {
Realm realm = realmDAO.findByFullPath(realmFullPath);
if (realm == null) {
LOG.debug("Invalid realm full path {}, ignoring", realmFullPath);
} else {
role.add(realm);
}
}
role.getDynRealms().clear();
for (String key : roleTO.getDynRealms()) {
DynRealm dynRealm = dynRealmDAO.find(key);
if (dynRealm == null) {
LOG.debug("Invalid dynamic ream {}, ignoring", key);
} else {
role.add(dynRealm);
}
}
role = roleDAO.save(role);
// dynamic membership
roleDAO.clearDynMembers(role);
if (role.getKey() == null && roleTO.getDynMembershipCond() != null) {
setDynMembership(role, roleTO.getDynMembershipCond());
} else if (role.getDynMembership() != null && roleTO.getDynMembershipCond() == null) {
role.setDynMembership(null);
} else if (role.getDynMembership() == null && roleTO.getDynMembershipCond() != null) {
setDynMembership(role, roleTO.getDynMembershipCond());
} else if (role.getDynMembership() != null && roleTO.getDynMembershipCond() != null && !role.getDynMembership().getFIQLCond().equals(roleTO.getDynMembershipCond())) {
setDynMembership(role, roleTO.getDynMembershipCond());
}
role.getPrivileges().clear();
for (String key : roleTO.getPrivileges()) {
Privilege privilege = applicationDAO.findPrivilege(key);
if (privilege == null) {
LOG.debug("Invalid privilege {}, ignoring", key);
} else {
role.add(privilege);
}
}
return role;
}
use of org.apache.syncope.core.persistence.api.entity.Privilege 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.core.persistence.api.entity.Privilege in project syncope by apache.
the class ApplicationTest method crud.
@Test
public void crud() {
// 1. create application
Application application = entityFactory.newEntity(Application.class);
application.setKey(UUID.randomUUID().toString());
String privilege1Key = UUID.randomUUID().toString();
Privilege privilege = entityFactory.newEntity(Privilege.class);
privilege.setKey(privilege1Key);
privilege.setSpec("{ \"one\": true }");
application.add(privilege);
String privilege2Key = UUID.randomUUID().toString();
privilege = entityFactory.newEntity(Privilege.class);
privilege.setKey(privilege2Key);
privilege.setSpec("{ \"two\": true }");
application.add(privilege);
String privilege3Key = UUID.randomUUID().toString();
privilege = entityFactory.newEntity(Privilege.class);
privilege.setKey(privilege3Key);
privilege.setSpec("{ \"three\": true }");
application.add(privilege);
application = applicationDAO.save(application);
assertNotNull(application);
assertNull(application.getDescription());
assertEquals(3, application.getPrivileges().size());
// 2. update application
application.setDescription("A description");
Privilege priv3 = applicationDAO.findPrivilege(privilege3Key);
priv3.setApplication(null);
application.getPrivileges().remove(priv3);
assertEquals(2, application.getPrivileges().size());
applicationDAO.save(application);
applicationDAO.flush();
application = applicationDAO.find(application.getKey());
assertNotNull(application);
assertNotNull(application.getDescription());
assertEquals(2, application.getPrivileges().size());
// 3. delete application
applicationDAO.delete(application);
applicationDAO.flush();
assertNull(applicationDAO.find(application.getKey()));
assertNull(applicationDAO.findPrivilege(privilege1Key));
assertNull(applicationDAO.findPrivilege(privilege2Key));
}
use of org.apache.syncope.core.persistence.api.entity.Privilege in project syncope by apache.
the class ApplicationTest method find.
@Test
public void find() {
Application mightyApp = applicationDAO.find("mightyApp");
assertNotNull(mightyApp);
assertEquals(2, mightyApp.getPrivileges().size());
Privilege getMighty = applicationDAO.findPrivilege("getMighty");
assertNotNull(getMighty);
assertEquals(getMighty, mightyApp.getPrivilege("getMighty").get());
}
Aggregations