Search in sources :

Example 6 with EntryPersistenceException

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);
    }
}
Also used : ArrayList(java.util.ArrayList) ParsedKey(io.jans.orm.impl.model.ParsedKey) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) AttributeData(io.jans.orm.model.AttributeData) MappingException(io.jans.orm.exception.MappingException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) SearchException(io.jans.orm.exception.operation.SearchException) AuthenticationException(io.jans.orm.exception.AuthenticationException)

Example 7 with EntryPersistenceException

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);
    }
}
Also used : ParsedKey(io.jans.orm.impl.model.ParsedKey) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) AttributeData(io.jans.orm.model.AttributeData) MappingException(io.jans.orm.exception.MappingException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) SearchException(io.jans.orm.exception.operation.SearchException) AuthenticationException(io.jans.orm.exception.AuthenticationException) MappingException(io.jans.orm.exception.MappingException)

Example 8 with EntryPersistenceException

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);
    }
}
Also used : SimpleSessionState(io.jans.orm.sql.model.SimpleSessionState) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) SqlEntryManagerSample(io.jans.orm.sql.persistence.SqlEntryManagerSample) SqlEntryManager(io.jans.orm.sql.impl.SqlEntryManager) Date(java.util.Date)

Example 9 with EntryPersistenceException

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);
}
Also used : CustomEntry(io.jans.orm.model.base.CustomEntry) CustomAttribute(io.jans.orm.model.base.CustomAttribute) GregorianCalendar(java.util.GregorianCalendar) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) Date(java.util.Date)

Example 10 with EntryPersistenceException

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);
    }
}
Also used : AttributeDataModification(io.jans.orm.model.AttributeDataModification) ArrayList(java.util.ArrayList) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) JsonObject(com.couchbase.client.java.document.json.JsonObject) MutationSpec(com.couchbase.client.java.subdoc.MutationSpec) AttributeData(io.jans.orm.model.AttributeData) MappingException(io.jans.orm.exception.MappingException) DateTimeException(java.time.DateTimeException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) DateTimeParseException(java.time.format.DateTimeParseException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) SearchException(io.jans.orm.exception.operation.SearchException) AuthenticationException(io.jans.orm.exception.AuthenticationException)

Aggregations

EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)61 SearchException (io.jans.orm.exception.operation.SearchException)33 AuthenticationException (io.jans.orm.exception.AuthenticationException)31 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)30 MappingException (io.jans.orm.exception.MappingException)30 Filter (io.jans.orm.search.filter.Filter)24 AttributeData (io.jans.orm.model.AttributeData)16 DateTimeParseException (java.time.format.DateTimeParseException)15 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)13 ParsedKey (io.jans.orm.impl.model.ParsedKey)12 ArrayList (java.util.ArrayList)11 Date (java.util.Date)10 SearchScopeException (io.jans.orm.exception.operation.SearchScopeException)9 JsonObject (com.couchbase.client.java.document.json.JsonObject)8 ConnectionException (io.jans.orm.exception.operation.ConnectionException)8 ParseException (java.text.ParseException)8 DateTimeException (java.time.DateTimeException)7 List (java.util.List)7 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)6 EntryData (io.jans.orm.model.EntryData)6