use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.
the class PlainAttrTest method saveWithEncrypted.
@Test
public void saveWithEncrypted() throws Exception {
User user = userDAO.find("1417acbe-cbf6-4277-9372-e75e04f97000");
PlainSchema obscureSchema = plainSchemaDAO.find("obscure");
assertNotNull(obscureSchema);
assertNotNull(obscureSchema.getSecretKey());
assertNotNull(obscureSchema.getCipherAlgorithm());
UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
attr.setOwner(user);
attr.setSchema(obscureSchema);
attr.add("testvalue", anyUtilsFactory.getInstance(AnyTypeKind.USER));
user.add(attr);
userDAO.save(user);
UPlainAttr obscure = user.getPlainAttr("obscure").get();
assertNotNull(obscure);
assertEquals(1, obscure.getValues().size());
assertEquals(Encryptor.getInstance(obscureSchema.getSecretKey()).encode("testvalue", obscureSchema.getCipherAlgorithm()), obscure.getValues().get(0).getStringValue());
}
use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.
the class GoogleAppsPullActions method afterAll.
@Transactional
@Override
public void afterAll(final ProvisioningProfile<?, ?> profile) throws JobExecutionException {
googleAppsIds.forEach((key, value) -> {
User user = userDAO.find(key);
if (user == null) {
LOG.error("Could not find user {}, skipping", key);
} else {
AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
// 1. stores the __UID__ received by Google
PlainSchema googleAppsId = plainSchemaDAO.find(getGoogleAppsIdSchema());
if (googleAppsId == null) {
LOG.error("Could not find schema googleAppsId, skipping");
} else {
UPlainAttr attr = user.getPlainAttr(getGoogleAppsIdSchema()).orElse(null);
if (attr == null) {
attr = entityFactory.newEntity(UPlainAttr.class);
attr.setSchema(googleAppsId);
attr.setOwner(user);
user.add(attr);
try {
attr.add(value, anyUtils);
userDAO.save(user);
} catch (InvalidPlainAttrValueException e) {
LOG.error("Invalid value for attribute {}: {}", googleAppsId.getKey(), value, e);
}
} else {
LOG.debug("User {} has already a googleAppsId assigned: {}", user, attr.getValuesAsStrings());
}
}
}
});
}
use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.
the class AnyTypeClassTest method create.
@Test
public void create() {
PlainSchema newSchema = entityFactory.newEntity(PlainSchema.class);
newSchema.setKey("new_plain_schema");
newSchema.setType(AttrSchemaType.String);
plainSchemaDAO.save(newSchema);
plainSchemaDAO.flush();
newSchema = plainSchemaDAO.find(newSchema.getKey());
assertNotNull(newSchema);
AnyTypeClass newClass = entityFactory.newEntity(AnyTypeClass.class);
newClass.setKey("new class");
newClass.add(newSchema);
anyTypeClassDAO.save(newClass);
anyTypeClassDAO.flush();
newClass = anyTypeClassDAO.find(newClass.getKey());
assertNotNull(newClass);
assertEquals(1, newClass.getPlainSchemas().size());
assertEquals(newSchema, newClass.getPlainSchemas().get(0));
assertEquals(newClass, newClass.getPlainSchemas().get(0).getAnyTypeClass());
newSchema = plainSchemaDAO.find(newSchema.getKey());
assertNotNull(newSchema.getAnyTypeClass());
}
use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.
the class PlainSchemaTest method deleteSurname.
@Test
public void deleteSurname() {
// search for user schema fullname
PlainSchema schema = plainSchemaDAO.find("surname");
assertNotNull(schema);
// check for associated mappings
Set<MappingItem> mappings = new HashSet<>();
for (ExternalResource resource : resourceDAO.findAll()) {
if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
if (schema.getKey().equals(mapItem.getIntAttrName())) {
mappings.add(mapItem);
}
}
}
}
assertFalse(mappings.isEmpty());
// delete user schema fullname
plainSchemaDAO.delete("surname");
plainSchemaDAO.flush();
// check for schema deletion
schema = plainSchemaDAO.find("surname");
assertNull(schema);
}
use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.
the class PlainSchemaTest method deleteFullname.
@Test
public void deleteFullname() {
// fullname is mapped as ConnObjectKey for ws-target-resource-2, need to swap it otherwise validation errors
// will be raised
resourceDAO.find("ws-target-resource-2").getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().forEach(item -> {
if ("fullname".equals(item.getIntAttrName())) {
item.setConnObjectKey(false);
} else if ("surname".equals(item.getIntAttrName())) {
item.setConnObjectKey(true);
}
});
// search for user schema fullname
PlainSchema schema = plainSchemaDAO.find("fullname");
assertNotNull(schema);
// check for associated mappings
Set<MappingItem> mapItems = new HashSet<>();
for (ExternalResource resource : resourceDAO.findAll()) {
if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
if (schema.getKey().equals(mapItem.getIntAttrName())) {
mapItems.add(mapItem);
}
}
}
}
assertFalse(mapItems.isEmpty());
// delete user schema fullname
plainSchemaDAO.delete("fullname");
plainSchemaDAO.flush();
// check for schema deletion
schema = plainSchemaDAO.find("fullname");
assertNull(schema);
plainSchemaDAO.clear();
// check for mappings deletion
mapItems = new HashSet<>();
for (ExternalResource resource : resourceDAO.findAll()) {
if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
if ("fullname".equals(mapItem.getIntAttrName())) {
mapItems.add(mapItem);
}
}
}
}
assertTrue(mapItems.isEmpty());
assertNull(plainAttrDAO.find("01f22fbd-b672-40af-b528-686d9b27ebc4", UPlainAttr.class));
assertNull(plainAttrDAO.find(UUID.randomUUID().toString(), UPlainAttr.class));
assertFalse(userDAO.findByUsername("rossini").getPlainAttr("fullname").isPresent());
assertFalse(userDAO.findByUsername("vivaldi").getPlainAttr("fullname").isPresent());
}
Aggregations