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;
}
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());
}
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);
}
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());
}
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));
}
Aggregations