use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class SpannerEntryManager method persist.
@Override
protected void persist(String dn, String[] objectClasses, List<AttributeData> attributes, Integer expiration) {
ArrayList<AttributeData> resultAttributes = new ArrayList<>(attributes.size() + 1);
for (AttributeData attribute : attributes) {
String attributeName = attribute.getName();
Object[] attributeValues = attribute.getValues();
Boolean multiValued = attribute.getMultiValued();
if (ArrayHelper.isNotEmpty(attributeValues) && (attributeValues[0] != null)) {
Object[] realValues = attributeValues;
// We need to store only one objectClass value in SQL
if (StringHelper.equalsIgnoreCase(SpannerOperationService.OBJECT_CLASS, attributeName)) {
if (!ArrayHelper.isEmpty(realValues)) {
realValues = new Object[] { realValues[0] };
multiValued = false;
}
}
// Process userPassword
if (StringHelper.equalsIgnoreCase(SpannerOperationService.USER_PASSWORD, attributeName)) {
realValues = getOperationService().createStoragePassword(StringHelper.toStringArray(attributeValues));
}
escapeValues(realValues);
AttributeData resultAttributeData;
if (Boolean.TRUE.equals(multiValued)) {
resultAttributeData = new AttributeData(toInternalAttribute(attributeName), realValues, multiValued);
} else {
resultAttributeData = new AttributeData(toInternalAttribute(attributeName), realValues[0]);
}
resultAttributes.add(resultAttributeData);
}
}
// Persist entry
try {
ParsedKey parsedKey = toSQLKey(dn);
resultAttributes.add(new AttributeData(SpannerOperationService.DN, dn));
resultAttributes.add(new AttributeData(SpannerOperationService.DOC_ID, parsedKey.getKey()));
boolean result = getOperationService().addEntry(parsedKey.getKey(), objectClasses[0], resultAttributes);
if (!result) {
throw new EntryPersistenceException(String.format("Failed to persist entry: '%s'", dn));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to persist entry: '%s'", dn), ex);
}
}
use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class SpannerEntryManager method exportEntry.
@Override
public List<AttributeData> exportEntry(String dn, String objectClass) {
if (StringHelper.isEmpty(objectClass)) {
throw new MappingException("Object class isn't defined!");
}
try {
// Load entry
ParsedKey keyWithInum = toSQLKey(dn);
List<AttributeData> entry = getOperationService().lookup(keyWithInum.getKey(), objectClass);
if (entry != null) {
return entry;
}
return null;
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entry: '%s'", dn), ex);
}
}
use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class SqlUpateMissingEntrySample method main.
public static void main(String[] args) {
// Prepare sample connection details
SqlEntryManagerSample sqlEntryManagerSample = new SqlEntryManagerSample();
// Create SQL entry manager
SqlEntryManager sqlEntryManager = sqlEntryManagerSample.createSqlEntryManager();
String sessionId = UUID.randomUUID().toString();
final String sessionDn = "uniqueIdentifier=" + sessionId + ",ou=session,o=jans";
final SimpleSessionState simpleSessionState = new SimpleSessionState();
simpleSessionState.setDn(sessionDn);
simpleSessionState.setId(sessionId);
simpleSessionState.setLastUsedAt(new Date());
try {
sqlEntryManager.merge(simpleSessionState);
System.out.println("Updated");
} catch (EntryPersistenceException ex) {
LOG.info("Failed to update, root case exception: {}", ex.getCause().getClass(), ex);
}
}
use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class ClientService method updateAccessTime.
public void updateAccessTime(Client client, boolean isUpdateLogonTime) {
if (isFalse(appConfiguration.getUpdateClientAccessTime())) {
return;
}
String clientDn = client.getDn();
CustomEntry customEntry = new CustomEntry();
customEntry.setDn(clientDn);
customEntry.setCustomObjectClasses(CLIENT_OBJECT_CLASSES);
Date now = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTime();
String nowDateString = ldapEntryManager.encodeTime(customEntry.getDn(), now);
CustomAttribute customAttributeLastAccessTime = new CustomAttribute("jansLastAccessTime", nowDateString);
customEntry.getCustomAttributes().add(customAttributeLastAccessTime);
if (isUpdateLogonTime) {
CustomAttribute customAttributeLastLogonTime = new CustomAttribute("jansLastLogonTime", nowDateString);
customEntry.getCustomAttributes().add(customAttributeLastLogonTime);
}
try {
ldapEntryManager.merge(customEntry);
} catch (EntryPersistenceException epe) {
log.error("Failed to update jansLastAccessTime and jansLastLogonTime of client '{}'", clientDn);
log.trace("Failed to update user:", epe);
}
removeFromCache(client);
}
use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class CouchbaseEntryManager method merge.
@Override
public void merge(String dn, String[] objectClasses, List<AttributeDataModification> attributeDataModifications, Integer expirationValue) {
// Update entry
try {
List<MutationSpec> modifications = new ArrayList<MutationSpec>(attributeDataModifications.size());
for (AttributeDataModification attributeDataModification : attributeDataModifications) {
AttributeData attribute = attributeDataModification.getAttribute();
AttributeData oldAttribute = attributeDataModification.getOldAttribute();
String attributeName = null;
Object[] attributeValues = null;
Boolean multiValued = null;
if (attribute != null) {
attributeName = attribute.getName();
attributeValues = attribute.getValues();
multiValued = attribute.getMultiValued();
}
String oldAttributeName = null;
Object[] oldAttributeValues = null;
if (oldAttribute != null) {
oldAttributeName = oldAttribute.getName();
oldAttributeValues = oldAttribute.getValues();
}
MutationSpec modification = null;
if (AttributeModificationType.ADD.equals(attributeDataModification.getModificationType())) {
modification = createModification(Mutation.DICT_ADD, toInternalAttribute(attributeName), multiValued, attributeValues);
} else {
if (AttributeModificationType.REMOVE.equals(attributeDataModification.getModificationType())) {
modification = createModification(Mutation.DELETE, toInternalAttribute(oldAttributeName), multiValued, oldAttributeValues);
} else if (AttributeModificationType.REPLACE.equals(attributeDataModification.getModificationType())) {
modification = createModification(Mutation.REPLACE, toInternalAttribute(attributeName), multiValued, attributeValues);
}
}
if (modification != null) {
modifications.add(modification);
}
}
if (modifications.size() > 0) {
boolean result = getOperationService().updateEntry(toCouchbaseKey(dn).getKey(), modifications, expirationValue);
if (!result) {
throw new EntryPersistenceException(String.format("Failed to update entry: %s", dn));
}
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to update entry: %s", dn), ex);
}
}
Aggregations