Search in sources :

Example 6 with TableMapping

use of io.jans.orm.sql.model.TableMapping in project jans by JanssenProject.

the class SqlConnectionProvider method getTableMappingByKey.

public TableMapping getTableMappingByKey(String key, String objectClass) {
    String tableName = objectClass;
    Map<String, String> columTypes = tableColumnsMap.get(tableName);
    if ("_".equals(key)) {
        return new TableMapping("", tableName, objectClass, columTypes);
    }
    String[] baseNameParts = key.split("_");
    if (ArrayHelper.isEmpty(baseNameParts)) {
        throw new KeyConversionException("Failed to determine base key part!");
    }
    TableMapping tableMapping = new TableMapping(baseNameParts[0], tableName, objectClass, columTypes);
    return tableMapping;
}
Also used : KeyConversionException(io.jans.orm.exception.KeyConversionException) TableMapping(io.jans.orm.sql.model.TableMapping)

Example 7 with TableMapping

use of io.jans.orm.sql.model.TableMapping in project jans by JanssenProject.

the class SqlOperationServiceImpl method updateEntry.

@Override
public boolean updateEntry(String key, String objectClass, List<AttributeDataModification> mods) throws UnsupportedOperationException, PersistenceException {
    Instant startTime = OperationDurationUtil.instance().now();
    TableMapping tableMapping = connectionProvider.getTableMappingByKey(key, objectClass);
    boolean result = updateEntryImpl(tableMapping, key, mods);
    Duration duration = OperationDurationUtil.instance().duration(startTime);
    OperationDurationUtil.instance().logDebug("SQL operation: modify, duration: {}, table: {}, key: {}, mods: {}", duration, tableMapping.getTableName(), key, mods);
    return result;
}
Also used : Instant(java.time.Instant) TableMapping(io.jans.orm.sql.model.TableMapping) Duration(java.time.Duration)

Example 8 with TableMapping

use of io.jans.orm.sql.model.TableMapping in project jans by JanssenProject.

the class SqlOperationServiceImpl method delete.

@Override
public boolean delete(String key, String objectClass) throws EntryNotFoundException {
    Instant startTime = OperationDurationUtil.instance().now();
    TableMapping tableMapping = connectionProvider.getTableMappingByKey(key, objectClass);
    boolean result = deleteImpl(tableMapping, key);
    Duration duration = OperationDurationUtil.instance().duration(startTime);
    OperationDurationUtil.instance().logDebug("SQL operation: delete, duration: {}, table: {}, key: {}", duration, tableMapping.getTableName(), key);
    return result;
}
Also used : Instant(java.time.Instant) TableMapping(io.jans.orm.sql.model.TableMapping) Duration(java.time.Duration)

Example 9 with TableMapping

use of io.jans.orm.sql.model.TableMapping in project jans by JanssenProject.

the class SqlOperationServiceImpl method authenticateImpl.

private boolean authenticateImpl(String key, String password, String objectClass) throws SearchException {
    Instant startTime = OperationDurationUtil.instance().now();
    boolean result = false;
    if (password != null) {
        try {
            List<AttributeData> attributes = lookup(key, objectClass, USER_PASSWORD);
            Object userPasswordObj = null;
            for (AttributeData attribute : attributes) {
                if (StringHelper.equalsIgnoreCase(attribute.getName(), USER_PASSWORD)) {
                    userPasswordObj = attribute.getValue();
                }
            }
            String userPassword = null;
            if (userPasswordObj instanceof String) {
                userPassword = (String) userPasswordObj;
            }
            if (userPassword != null) {
                if (persistenceExtension == null) {
                    result = PasswordEncryptionHelper.compareCredentials(password, userPassword);
                } else {
                    result = persistenceExtension.compareHashedPasswords(password, userPassword);
                }
            }
        } catch (EntryConvertationException ex) {
            throw new SearchException(String.format("Failed to get '%s' attribute", USER_PASSWORD), ex);
        }
    }
    Duration duration = OperationDurationUtil.instance().duration(startTime);
    TableMapping tableMapping = connectionProvider.getTableMappingByKey(key, objectClass);
    OperationDurationUtil.instance().logDebug("SQL operation: bind, duration: {}, table: {}, key: {}", duration, tableMapping.getTableName(), key);
    return result;
}
Also used : Instant(java.time.Instant) SearchException(io.jans.orm.exception.operation.SearchException) TableMapping(io.jans.orm.sql.model.TableMapping) EntryConvertationException(io.jans.orm.exception.operation.EntryConvertationException) Duration(java.time.Duration) AttributeData(io.jans.orm.model.AttributeData)

Aggregations

TableMapping (io.jans.orm.sql.model.TableMapping)9 Duration (java.time.Duration)8 Instant (java.time.Instant)8 AttributeData (io.jans.orm.model.AttributeData)2 KeyConversionException (io.jans.orm.exception.KeyConversionException)1 EntryConvertationException (io.jans.orm.exception.operation.EntryConvertationException)1 SearchException (io.jans.orm.exception.operation.SearchException)1 EntryData (io.jans.orm.model.EntryData)1