use of org.identityconnectors.common.security.GuardedString in project midpoint by Evolveum.
the class AbstractObjectDummyConnector method getString.
protected String getString(GuardedString guardedString) {
if (guardedString == null) {
return null;
}
final String[] passwdArray = { null };
guardedString.access(new Accessor() {
@Override
public void access(char[] passwdChars) {
String password = new String(passwdChars);
checkPasswordPolicies(password);
passwdArray[0] = password;
}
});
return passwdArray[0];
}
use of org.identityconnectors.common.security.GuardedString in project midpoint by Evolveum.
the class ConnectorFactoryConnIdImpl method selfTestGuardedString.
private void selfTestGuardedString(OperationResult parentTestResult) {
OperationResult result = parentTestResult.createSubresult(ConnectorFactoryConnIdImpl.class + ".selfTestGuardedString");
OperationResult subresult = result.createSubresult(ConnectorFactoryConnIdImpl.class + ".selfTestGuardedString.encryptorReflection");
EncryptorFactory encryptorFactory = EncryptorFactory.getInstance();
subresult.addReturn("encryptorFactoryImpl", encryptorFactory.getClass());
LOGGER.debug("Encryptor factory implementation class: {}", encryptorFactory.getClass());
Encryptor encryptor = EncryptorFactory.getInstance().newRandomEncryptor();
subresult.addReturn("encryptorImpl", encryptor.getClass());
LOGGER.debug("Encryptor implementation class: {}", encryptor.getClass());
if (encryptor.getClass().getName().equals("org.identityconnectors.common.security.impl.EncryptorImpl")) {
// let's do some reflection magic to have a look inside
try {
LOGGER.trace("Encryptor fields: {}", Arrays.asList(encryptor.getClass().getDeclaredFields()));
Field keyField = encryptor.getClass().getDeclaredField("key");
keyField.setAccessible(true);
Key key = (Key) keyField.get(encryptor);
subresult.addReturn("keyAlgorithm", key.getAlgorithm());
subresult.addReturn("keyLength", key.getEncoded().length * 8);
subresult.addReturn("keyFormat", key.getFormat());
subresult.recordSuccess();
} catch (IllegalArgumentException | SecurityException | NoSuchFieldException | IllegalAccessException e) {
subresult.recordPartialError("Reflection introspection failed", e);
}
}
OperationResult encryptorSubresult = result.createSubresult(ConnectorFactoryConnIdImpl.class + ".selfTestGuardedString.encryptor");
try {
String plainString = "Scurvy seadog";
byte[] encryptedBytes = encryptor.encrypt(plainString.getBytes());
byte[] decryptedBytes = encryptor.decrypt(encryptedBytes);
String decryptedString = new String(decryptedBytes);
if (!plainString.equals(decryptedString)) {
encryptorSubresult.recordFatalError("Encryptor roundtrip failed; encrypted=" + plainString + ", decrypted=" + decryptedString);
} else {
encryptorSubresult.recordSuccess();
}
} catch (Throwable e) {
LOGGER.error("Encryptor operation error: {}", e.getMessage(), e);
encryptorSubresult.recordFatalError("Encryptor operation error: " + e.getMessage(), e);
}
final OperationResult guardedStringSubresult = result.createSubresult(ConnectorFactoryConnIdImpl.class + ".selfTestGuardedString.guardedString");
// try to encrypt and decrypt GuardedString
try {
final String origString = "Shiver me timbers";
// This should encrypt it
GuardedString guardedString = new GuardedString(origString.toCharArray());
// and this should decrypt it
guardedString.access(new GuardedString.Accessor() {
@Override
public void access(char[] decryptedChars) {
if (!(new String(decryptedChars)).equals(origString)) {
guardedStringSubresult.recordFatalError("GuardedString roundtrip failed; encrypted=" + origString + ", decrypted=" + (new String(decryptedChars)));
}
}
});
guardedStringSubresult.recordSuccessIfUnknown();
} catch (Throwable e) {
LOGGER.error("GuardedString operation error: {}", e.getMessage(), e);
guardedStringSubresult.recordFatalError("GuardedString operation error: " + e.getMessage(), e);
}
result.computeStatus();
}
use of org.identityconnectors.common.security.GuardedString in project midpoint by Evolveum.
the class DeltaModificationConverter method collectPassword.
@Override
protected void collectPassword(PropertyDelta<ProtectedStringType> passwordDelta) throws SchemaException {
if (isSelfPasswordChange(passwordDelta)) {
AttributeDeltaBuilder deltaBuilder = new AttributeDeltaBuilder();
deltaBuilder.setName(OperationalAttributes.PASSWORD_NAME);
PrismProperty<ProtectedStringType> newPasswordProperty = passwordDelta.getPropertyNewMatchingPath();
GuardedString newPasswordGs = passwordToGuardedString(newPasswordProperty.getRealValue(), "new password");
deltaBuilder.addValueToAdd(newPasswordGs);
ProtectedStringType oldPasswordPs = passwordDelta.getEstimatedOldValues().iterator().next().getRealValue();
GuardedString oldPasswordGs = passwordToGuardedString(oldPasswordPs, "old password");
deltaBuilder.addValueToRemove(oldPasswordGs);
attributesDelta.add(deltaBuilder.build());
} else {
super.collectPassword(passwordDelta);
}
}
use of org.identityconnectors.common.security.GuardedString in project CzechIdMng by bcvsolutions.
the class CrossDomainAdUserConnectorTypeTest method testConnectorConfigurationLoginInformations.
@Test
public void testConnectorConfigurationLoginInformations() {
ConnectorType connectorType = connectorManager.getConnectorType(MockCrossDomainAdUserConnectorType.NAME);
SysSystemDto systemDto = initSystem(connectorType);
SysSystemAttributeMappingFilter filter = new SysSystemAttributeMappingFilter();
filter.setSystemId(systemDto.getId());
filter.setName(MockCrossDomainAdUserConnectorType.LDAP_GROUPS_ATTRIBUTE);
List<SysSystemAttributeMappingDto> attributes = attributeMappingService.find(filter, null).getContent();
assertEquals(1, attributes.size());
SysSystemAttributeMappingDto ldapGroupsAttribute = attributes.stream().findFirst().get();
// Creates cross-domain group.
SysSystemGroupDto groupSystemDto = new SysSystemGroupDto();
groupSystemDto.setCode(getHelper().createName());
groupSystemDto.setType(SystemGroupType.CROSS_DOMAIN);
groupSystemDto = systemGroupService.save(groupSystemDto);
SysSystemGroupSystemDto systemGroupSystemOne = new SysSystemGroupSystemDto();
systemGroupSystemOne.setSystemGroup(groupSystemDto.getId());
systemGroupSystemOne.setMergeAttribute(ldapGroupsAttribute.getId());
systemGroupSystemOne.setSystem(systemDto.getId());
systemGroupSystemService.save(systemGroupSystemOne);
IcConnectorConfiguration connectorConfiguration = connectorType.getConnectorConfiguration(systemDto);
Object otherSystemInGroupsObj = connectorConfiguration.getSystemOperationOptions().get(MockCrossDomainAdUserConnectorType.CROSS_DOMAIN_SYSTEM_IDS);
// No others systems are in cross-domain groups.
assertNotNull(otherSystemInGroupsObj);
assertTrue(((String) otherSystemInGroupsObj).isEmpty());
SysSystemDto otherSystemDto = initSystem(connectorType);
filter.setSystemId(otherSystemDto.getId());
filter.setName(MockCrossDomainAdUserConnectorType.LDAP_GROUPS_ATTRIBUTE);
attributes = attributeMappingService.find(filter, null).getContent();
assertEquals(1, attributes.size());
ldapGroupsAttribute = attributes.stream().findFirst().get();
SysSystemGroupSystemDto systemGroupSystemTwo = new SysSystemGroupSystemDto();
systemGroupSystemTwo.setSystemGroup(groupSystemDto.getId());
systemGroupSystemTwo.setMergeAttribute(ldapGroupsAttribute.getId());
systemGroupSystemTwo.setSystem(otherSystemDto.getId());
systemGroupSystemTwo = systemGroupSystemService.save(systemGroupSystemTwo);
connectorConfiguration = connectorType.getConnectorConfiguration(systemDto);
otherSystemInGroupsObj = connectorConfiguration.getSystemOperationOptions().get(MockCrossDomainAdUserConnectorType.CROSS_DOMAIN_SYSTEM_IDS);
// One other system is in cross-domain groups.
assertNotNull(otherSystemInGroupsObj);
String[] otherSystemInGroupsSplited = ((String) otherSystemInGroupsObj).split(",");
assertEquals(1, otherSystemInGroupsSplited.length);
assertEquals(otherSystemDto.getId().toString(), otherSystemInGroupsSplited[0]);
IcConnectorConfiguration connectorConfigurationOtherSystem = systemService.getConnectorConfiguration(otherSystemDto);
// Check host property.
IcConfigurationProperty hostProperty = connectorConfigurationOtherSystem.getConfigurationProperties().getProperties().stream().filter(property -> MockCrossDomainAdUserConnectorType.HOST.equals(property.getName())).findFirst().get();
String host = (String) connectorConfiguration.getSystemOperationOptions().get(MessageFormat.format(MockCrossDomainAdUserConnectorType.CROSS_DOMAIN_HOST_PATTERN, otherSystemDto.getId().toString()));
assertEquals(hostProperty.getValue(), host);
// Check user property.
IcConfigurationProperty userProperty = connectorConfigurationOtherSystem.getConfigurationProperties().getProperties().stream().filter(property -> MockCrossDomainAdUserConnectorType.PRINCIPAL.equals(property.getName())).findFirst().get();
String user = (String) connectorConfiguration.getSystemOperationOptions().get(MessageFormat.format(MockCrossDomainAdUserConnectorType.CROSS_DOMAIN_USER_PATTERN, otherSystemDto.getId().toString()));
assertEquals(userProperty.getValue(), user);
// Check password property.
IcConfigurationProperty passwordProperty = connectorConfigurationOtherSystem.getConfigurationProperties().getProperties().stream().filter(property -> MockCrossDomainAdUserConnectorType.CREDENTIALS.equals(property.getName())).findFirst().get();
GuardedString password = (GuardedString) connectorConfiguration.getSystemOperationOptions().get(MessageFormat.format(MockCrossDomainAdUserConnectorType.CROSS_DOMAIN_PASSWORD_PATTERN, otherSystemDto.getId().toString()));
assertEquals((SecurityUtil.decrypt((GuardedString) passwordProperty.getValue())), SecurityUtil.decrypt(password));
// Clean
systemGroupService.delete(groupSystemDto);
assertNull(systemGroupSystemService.get(systemGroupSystemTwo));
systemService.delete(systemDto);
}
Aggregations