Search in sources :

Example 1 with AfterLoadEvent

use of org.springframework.data.mongodb.core.mapping.event.AfterLoadEvent in project service-authorization by reportportal.

the class AuthAttributesEventListener method onAfterLoad.

@Override
public void onAfterLoad(AfterLoadEvent<AuthConfigEntity> event) {
    Optional.ofNullable(event.getSource()).flatMap(dbo -> Optional.ofNullable(dbo.get("ldap"))).ifPresent(ldapDbo -> {
        DBObject ldap = ((DBObject) ldapDbo);
        Object managerPassword = ldap.get(MANAGER_PASSWORD_FIELD);
        if (null != managerPassword) {
            try {
                String decrypted = encryptor.decrypt((String) managerPassword);
                ldap.put(MANAGER_PASSWORD_FIELD, decrypted);
            } catch (Exception e) {
                LOGGER.error("Cannot decrypt password", e);
            // do nothing
            }
        }
    });
}
Also used : Encryptor(com.epam.reportportal.auth.util.Encryptor) AbstractMongoEventListener(org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener) AfterLoadEvent(org.springframework.data.mongodb.core.mapping.event.AfterLoadEvent) Component(org.springframework.stereotype.Component) Logger(org.slf4j.Logger) DBObject(com.mongodb.DBObject) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) MongoMappingEvent(org.springframework.data.mongodb.core.mapping.event.MongoMappingEvent) Optional(java.util.Optional) AuthConfigEntity(com.epam.reportportal.auth.store.entity.AuthConfigEntity) DBObject(com.mongodb.DBObject) DBObject(com.mongodb.DBObject)

Aggregations

AuthConfigEntity (com.epam.reportportal.auth.store.entity.AuthConfigEntity)1 Encryptor (com.epam.reportportal.auth.util.Encryptor)1 DBObject (com.mongodb.DBObject)1 Optional (java.util.Optional)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 AbstractMongoEventListener (org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener)1 AfterLoadEvent (org.springframework.data.mongodb.core.mapping.event.AfterLoadEvent)1 MongoMappingEvent (org.springframework.data.mongodb.core.mapping.event.MongoMappingEvent)1 Component (org.springframework.stereotype.Component)1