use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr in project syncope by apache.
the class PlainAttrTest method read.
@Test
public void read() {
UPlainAttr attribute = plainAttrDAO.find("01f22fbd-b672-40af-b528-686d9b27ebc4", UPlainAttr.class);
assertNotNull(attribute);
assertTrue(attribute.getValues().isEmpty());
assertNotNull(attribute.getUniqueValue());
}
use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr in project syncope by apache.
the class PlainAttrTest method save.
@Test
public void save() throws ClassNotFoundException {
User user = userDAO.find("1417acbe-cbf6-4277-9372-e75e04f97000");
PlainSchema emailSchema = plainSchemaDAO.find("email");
assertNotNull(emailSchema);
UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
attr.setOwner(user);
attr.setSchema(emailSchema);
Exception thrown = null;
try {
attr.add("john.doe@gmail.com", anyUtilsFactory.getInstance(AnyTypeKind.USER));
attr.add("mario.rossi@gmail.com", anyUtilsFactory.getInstance(AnyTypeKind.USER));
} catch (ValidationException e) {
thrown = e;
}
assertNull(thrown);
try {
attr.add("http://www.apache.org", anyUtilsFactory.getInstance(AnyTypeKind.USER));
} catch (ValidationException e) {
thrown = e;
}
assertNotNull(thrown);
}
use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr 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.user.UPlainAttr in project syncope by apache.
the class PlainAttrTest method deleteAttributeValue.
@Test
public void deleteAttributeValue() {
UPlainAttrValue value = plainAttrValueDAO.find("7034de3b-3687-4db5-8454-363468f1a9de", UPlainAttrValue.class);
int attributeValueNumber = value.getAttr().getValues().size();
plainAttrValueDAO.delete(value.getKey(), UPlainAttrValue.class);
plainAttrValueDAO.flush();
assertNull(plainAttrValueDAO.find(value.getKey(), UPlainAttrValue.class));
UPlainAttr attribute = plainAttrDAO.find("9d0d9e40-1b18-488e-9482-37dab82163c9", UPlainAttr.class);
assertEquals(attribute.getValues().size(), attributeValueNumber - 1);
}
use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr 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());
}
}
}
});
}
Aggregations