Search in sources :

Example 1 with AuthConfigEntity

use of com.epam.reportportal.auth.store.entity.AuthConfigEntity in project service-authorization by reportportal.

the class AuthAttributesEventListenerTest method testPassEncryption.

@Test
public void testPassEncryption() {
    LdapConfig ldapConfig = new LdapConfig();
    ldapConfig.setManagerPassword(encryptor.encrypt("managerPassword"));
    ldapConfig.setUserDnPattern("userDnPattern");
    repository.updateLdap(ldapConfig);
    AuthConfigEntity entity = new AuthConfigEntity();
    entity.setLdap(ldapConfig);
    AuthConfigEntity dbEntity = repository.findDefault();
    Assert.assertThat(dbEntity.getLdap().getManagerPassword(), Matchers.is("managerPassword"));
}
Also used : LdapConfig(com.epam.reportportal.auth.store.entity.ldap.LdapConfig) AuthConfigEntity(com.epam.reportportal.auth.store.entity.AuthConfigEntity) Test(org.junit.Test)

Example 2 with AuthConfigEntity

use of com.epam.reportportal.auth.store.entity.AuthConfigEntity in project service-authorization by reportportal.

the class AuthConfigRepositoryImpl method createDefaultProfileIfAbsent.

@Override
public void createDefaultProfileIfAbsent() {
    if (null == mongoOperations.findOne(findDefaultQuery(), AuthConfigEntity.class)) {
        AuthConfigEntity entity = new AuthConfigEntity();
        entity.setId(AuthConfigRepository.DEFAULT_PROFILE);
        mongoOperations.save(entity);
    }
}
Also used : AuthConfigEntity(com.epam.reportportal.auth.store.entity.AuthConfigEntity)

Example 3 with AuthConfigEntity

use of com.epam.reportportal.auth.store.entity.AuthConfigEntity 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)3 LdapConfig (com.epam.reportportal.auth.store.entity.ldap.LdapConfig)1 Encryptor (com.epam.reportportal.auth.util.Encryptor)1 DBObject (com.mongodb.DBObject)1 Optional (java.util.Optional)1 Test (org.junit.Test)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