use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityServiceIntegrationTest method testCreateDefaultContract.
/**
* When identity is created, then default contract have to be created too.
*/
@Test
public void testCreateDefaultContract() {
IdmIdentityDto identity = new IdmIdentityDto();
String username = "contract_test_" + System.currentTimeMillis();
identity.setUsername(username);
// confidential storage
identity.setPassword(new GuardedString("heslo"));
identity.setFirstName("Test");
identity.setLastName("Identity");
identity = identityService.save(identity);
//
List<IdmIdentityContractDto> contracts = identityContractService.findAllByIdentity(identity.getId());
assertEquals(1, contracts.size());
//
IdmIdentityContractDto defaultContract = identityContractService.prepareMainContract(identity.getId());
assertEquals(defaultContract.getIdentity(), contracts.get(0).getIdentity());
assertEquals(defaultContract.getPosition(), contracts.get(0).getPosition());
assertEquals(defaultContract.getWorkPosition(), contracts.get(0).getWorkPosition());
}
use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityServiceIntegrationTest method testSkipDefaultContract.
/**
* When identity is created with the event property
* IdmIdentityContractService.SKIP_CREATION_OF_DEFAULT_POSITION = TRUE, then
* default contract haven't to be created.
*/
@Test
public void testSkipDefaultContract() {
IdmIdentityDto identity = new IdmIdentityDto();
String username = "contract_test_" + System.currentTimeMillis();
identity.setUsername(username);
// confidential storage
identity.setPassword(new GuardedString("heslo"));
identity.setFirstName("Test");
identity.setLastName("Identity");
EntityEvent<IdmIdentityDto> event = new IdentityEvent(IdentityEventType.CREATE, identity, ImmutableMap.of(// In the identity sync are creation of the default contract skipped.
IdmIdentityContractService.SKIP_CREATION_OF_DEFAULT_POSITION, Boolean.TRUE));
identity = identityService.publish(event).getContent();
//
List<IdmIdentityContractDto> contracts = identityContractService.findAllByIdentity(identity.getId());
assertEquals(0, contracts.size());
}
use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceItegrationTest method createTestOwner.
private FormableEntity createTestOwner(String name) {
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername(name + "_" + System.currentTimeMillis());
identity.setPassword(new GuardedString("heslo"));
identity.setFirstName("Test");
identity.setLastName("Identity");
identity = identityService.save(identity);
return identityRepository.findOne(identity.getId());
}
use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class IdentitySetPasswordProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
IdmIdentityDto previousIdentity = event.getOriginalSource();
IdmIdentityDto newIdentity = event.getContent();
if (stateStarting(previousIdentity, newIdentity) && hasAccount(newIdentity)) {
// change password for all systems
PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
//
// public password change password for all system including idm
passwordChangeDto.setAll(true);
passwordChangeDto.setIdm(true);
// TODO: how to generate password for all system policies
GuardedString password = new GuardedString(passwordPolicyService.generatePasswordByDefault());
passwordChangeDto.setNewPassword(password);
//
List<OperationResult> results = identityService.passwordChange(newIdentity, passwordChangeDto);
//
List<IdmAccountDto> successAccounts = new ArrayList<>();
List<OperationResult> failureResults = new ArrayList<>();
List<String> systemNames = new ArrayList<>();
results.forEach(result -> {
if (result.getModel() != null) {
boolean success = result.getModel().getStatusEnum().equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name());
if (success) {
IdmAccountDto account = (IdmAccountDto) result.getModel().getParameters().get(IdmAccountDto.PARAMETER_NAME);
systemNames.add(account.getSystemName());
successAccounts.add(account);
} else {
// exception is logged before
failureResults.add(result);
}
}
});
// send notification if at least one system success
if (!successAccounts.isEmpty()) {
notificationManager.send(CoreModuleDescriptor.TOPIC_PASSWORD_CHANGED, new IdmMessageDto.Builder().setLevel(NotificationLevel.SUCCESS).addParameter("successSystemNames", StringUtils.join(systemNames, ", ")).addParameter("successAccounts", successAccounts).addParameter("failureResults", failureResults).addParameter("name", identityService.getNiceLabel(newIdentity)).addParameter("password", password).build(), newIdentity);
}
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class ProvisioningSendNotificationProcessor method process.
@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
SysProvisioningOperationDto provisioningOperation = event.getContent();
String uid = provisioningOperationService.getByProvisioningOperation(provisioningOperation).getUid();
IdmIdentityDto identity = null;
if (provisioningOperation.getEntityIdentifier() != null && SystemEntityType.IDENTITY == provisioningOperation.getEntityType()) {
identity = identityService.get(provisioningOperation.getEntityIdentifier());
}
// TODO: identity or email null, send message to actual log user?
if (identity != null && identity.getState() != IdentityState.CREATED) {
for (IcAttribute attribute : provisioningOperationService.getFullConnectorObject(provisioningOperation).getAttributes()) {
// TODO: send password always, when create?
if (attribute instanceof IcPasswordAttribute && attribute.getValue() != null) {
GuardedString password = ((IcPasswordAttribute) attribute).getPasswordValue();
//
// send message with new password to identity, topic has connection to templates
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
notificationManager.send(AccModuleDescriptor.TOPIC_NEW_PASSWORD, new IdmMessageDto.Builder().setLevel(NotificationLevel.SUCCESS).addParameter("systemName", system.getName()).addParameter("uid", uid).addParameter("password", password).build(), identity);
break;
}
}
}
return new DefaultEventResult<>(event, this);
}
Aggregations