Search in sources :

Example 1 with AbstractAuthentication

use of eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication in project CzechIdMng by bcvsolutions.

the class AuditableListener method onPreInsert.

@Override
public boolean onPreInsert(PreInsertEvent event) {
    if (event.getEntity() instanceof Auditable) {
        DateTime date = new DateTime();
        Auditable entity = (Auditable) event.getEntity();
        // 
        setValue(event.getState(), event, Auditable.PROPERTY_CREATED, date);
        entity.setCreated(date);
        // 
        AbstractAuthentication authentication = securityService.getAuthentication();
        IdmIdentityDto currentIdentity = authentication == null ? null : authentication.getCurrentIdentity();
        IdmIdentityDto originalIdentity = authentication == null ? null : authentication.getOriginalIdentity();
        if (entity.getCreator() == null) {
            String creator = currentIdentity == null ? securityService.getUsername() : currentIdentity.getUsername();
            setValue(event.getState(), event, Auditable.PROPERTY_CREATOR, creator);
            entity.setCreator(creator);
            // 
            UUID creatorId = currentIdentity == null ? null : currentIdentity.getId();
            setValue(event.getState(), event, Auditable.PROPERTY_CREATOR_ID, creatorId);
            entity.setCreatorId(creatorId);
        }
        // could be filled in wf (applicant) ...
        if (entity.getOriginalCreator() == null) {
            String originalCreator = originalIdentity == null ? null : originalIdentity.getUsername();
            setValue(event.getState(), event, Auditable.PROPERTY_ORIGINAL_CREATOR, originalCreator);
            entity.setOriginalCreator(originalCreator);
            // 
            UUID originalCreatorId = originalIdentity == null ? null : originalIdentity.getId();
            setValue(event.getState(), event, Auditable.PROPERTY_ORIGINAL_CREATOR_ID, originalCreatorId);
            entity.setOriginalCreatorId(originalCreatorId);
        }
    }
    return false;
}
Also used : Auditable(eu.bcvsolutions.idm.core.api.domain.Auditable) AbstractAuthentication(eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) DateTime(org.joda.time.DateTime)

Example 2 with AbstractAuthentication

use of eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication in project CzechIdMng by bcvsolutions.

the class DefaultSecurityServiceTest method testIsLoggedIn.

@Test
public void testIsLoggedIn() {
    // setup static authentication
    when(securityContext.getAuthentication()).thenReturn(AUTHENTICATION);
    // 
    AbstractAuthentication result = defaultSecurityService.getAuthentication();
    // 
    assertEquals(result.getCurrentUsername(), AUTHENTICATION.getCurrentUsername());
    assertEquals(result.getOriginalUsername(), AUTHENTICATION.getOriginalUsername());
    assertEquals(result.getAuthorities(), AUTHENTICATION.getAuthorities());
    assertEquals(result.getDetails(), AUTHENTICATION.getDetails());
}
Also used : AbstractAuthentication(eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 3 with AbstractAuthentication

use of eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication in project CzechIdMng by bcvsolutions.

the class AbstractWorkflowEventProcessor method processInstance.

/**
 * Execute wf - returns process instance
 *
 * @param variables
 * @return
 */
protected ProcessInstance processInstance(Map<String, Object> variables) {
    if (StringUtils.isEmpty(getWorkflowDefinitionKey())) {
        // wf is not configured
        return null;
    }
    // execute process
    AbstractAuthentication authentication = securityService.getAuthentication();
    IdmIdentityDto modifier = authentication == null ? null : authentication.getCurrentIdentity();
    return workflowService.startProcess(getWorkflowDefinitionKey(), modifier == null ? null : modifier.getClass().getSimpleName(), authentication == null ? null : authentication.getCurrentUsername(), modifier == null || modifier.getId() == null ? null : modifier.getId().toString(), variables);
}
Also used : AbstractAuthentication(eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 4 with AbstractAuthentication

use of eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication in project CzechIdMng by bcvsolutions.

the class DefaultSecurityServiceUnitTest method testIsLoggedIn.

@Test
public void testIsLoggedIn() {
    // setup static authentication
    when(securityContext.getAuthentication()).thenReturn(AUTHENTICATION);
    // 
    AbstractAuthentication result = defaultSecurityService.getAuthentication();
    // 
    assertEquals(result.getCurrentUsername(), AUTHENTICATION.getCurrentUsername());
    assertEquals(result.getOriginalUsername(), AUTHENTICATION.getOriginalUsername());
    assertEquals(result.getAuthorities(), AUTHENTICATION.getAuthorities());
    assertEquals(result.getDetails(), AUTHENTICATION.getDetails());
}
Also used : AbstractAuthentication(eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 5 with AbstractAuthentication

use of eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication in project CzechIdMng by bcvsolutions.

the class AbstractNotificationSender method send.

@Override
@Transactional
public List<N> send(String topic, IdmMessageDto message) {
    Assert.notNull(securityService, "Security service is required for this operation");
    Assert.notNull(topic, "Message topic can not be null.");
    Assert.notNull(message, "Message can not be null.");
    // 
    AbstractAuthentication auth = securityService.getAuthentication();
    IdmIdentityDto currentIdentityDto = auth == null ? null : auth.getCurrentIdentity();
    if (currentIdentityDto == null || currentIdentityDto.getId() == null) {
        LOG.warn("No identity is currently signed, swallowing the message: [{}], parameters: [{}].", message.getTextMessage(), message.getParameters());
        // system, guest, etc.
        return null;
    }
    return send(topic, message, Lists.newArrayList(currentIdentityDto));
}
Also used : AbstractAuthentication(eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AbstractAuthentication (eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication)12 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)8 Auditable (eu.bcvsolutions.idm.core.api.domain.Auditable)4 UUID (java.util.UUID)4 AuditSearchable (eu.bcvsolutions.idm.core.api.domain.AuditSearchable)2 Codeable (eu.bcvsolutions.idm.core.api.domain.Codeable)2 AbstractEntity (eu.bcvsolutions.idm.core.api.entity.AbstractEntity)2 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)2 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)2 ZonedDateTime (java.time.ZonedDateTime)2 DateTime (org.joda.time.DateTime)2 Test (org.junit.Test)2 IdmIdentityRole (eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole)1 IdmRoleGuarantee (eu.bcvsolutions.idm.core.model.entity.IdmRoleGuarantee)1 IdmRoleGuaranteeRole (eu.bcvsolutions.idm.core.model.entity.IdmRoleGuaranteeRole)1 LocalDate (java.time.LocalDate)1 PrePersist (javax.persistence.PrePersist)1 PreUpdate (javax.persistence.PreUpdate)1 Predicate (javax.persistence.criteria.Predicate)1 Transactional (org.springframework.transaction.annotation.Transactional)1