private void hashValues(Collection<PrismPropertyValue<ProtectedStringType>> values, CredentialsStorageMethodType storageMethod) throws SchemaException, EncryptionException { if (values == null) { return; } for (PrismPropertyValue<ProtectedStringType> pval: values) { ProtectedStringType ps = pval.getValue(); if (!ps.isHashed()) { protector.hash(ps); } } }
private void hashValues(Collection<PrismPropertyValue<ProtectedStringType>> pvals) throws SchemaException { if (pvals == null) { return; } for (PrismPropertyValue<ProtectedStringType> pval: pvals) { ProtectedStringType psVal = pval.getValue(); if (psVal == null) { return; } if (psVal.isHashed()) { return; } try { protector.hash(psVal); } catch (EncryptionException e) { throw new SchemaException("Cannot hash value", e); } } }
private void preparePasswordForStorage(PasswordType passwordType, RefinedObjectClassDefinition objectClassDefinition) throws SchemaException, EncryptionException { ProtectedStringType passwordValue = passwordType.getValue(); if (passwordValue == null) { return; } CachingStategyType cachingStategy = getPasswordCachingStrategy(objectClassDefinition); if (cachingStategy != null && cachingStategy != CachingStategyType.NONE) { if (!passwordValue.isHashed()) { protector.hash(passwordValue); } return; } else { ProvisioningUtil.cleanupShadowPassword(passwordType); } }
private void hashCredentialsPcvs(Collection<PrismContainerValue<CredentialsType>> values, CredentialsStorageMethodType storageMethod) throws SchemaException, EncryptionException { if (values == null) { return; } for (PrismContainerValue<CredentialsType> pval: values) { CredentialsType credentials = pval.getValue(); if (credentials != null && credentials.getPassword() != null) { ProtectedStringType passwordValue = credentials.getPassword().getValue(); if (passwordValue != null && !passwordValue.isHashed()) { protector.hash(passwordValue); } } } }
private void hashPasswordPcvs(Collection<PrismContainerValue<PasswordType>> values, CredentialsStorageMethodType storageMethod) throws SchemaException, EncryptionException { if (values == null) { return; } for (PrismContainerValue<PasswordType> pval: values) { PasswordType password = pval.getValue(); if (password != null && password.getValue() != null) { if (!password.getValue().isHashed()) { protector.hash(password.getValue()); } } } }
private void prepareProtectedStringForStorage(ProtectedStringType ps, CredentialsStorageTypeType storageType) throws SchemaException { try { switch (storageType) { case ENCRYPTION: if (ps.isEncrypted()) { break; } if (ps.isHashed()) { throw new SchemaException("Cannot store hashed value in an encrypted form"); } protector.encrypt(ps); break; case HASHING: if (ps.isHashed()) { break; } protector.hash(ps); break; case NONE: throw new SchemaException("Cannot store value on NONE storage form"); default: throw new SchemaException("Unknown storage type: "+storageType); } } catch (EncryptionException e) { throw new SystemException(e.getMessage(), e); } }
@Test public void testParseProtectedStringHashed() throws Exception { final String TEST_NAME = "testParseProtectedStringHashed"; displayTestTitle(TEST_NAME); // GIVEN ProtectedStringType protectedStringType = new ProtectedStringType(); protectedStringType.setClearValue("blabla"); Protector protector = PrismInternalTestUtil.createProtector(XMLCipher.AES_128); protector.hash(protectedStringType); PrismContext prismContext = PrismTestUtil.getPrismContext(); // WHEN MapXNodeImpl protectedStringTypeXNode = ((PrismContextImpl) prismContext).getBeanMarshaller().marshalProtectedDataType(protectedStringType, null); System.out.println("Protected string type XNode: " + protectedStringTypeXNode.debugDump()); // THEN ProtectedStringType unmarshalled = new ProtectedStringType(); prismContext.hacks().parseProtectedType(unmarshalled, protectedStringTypeXNode, prismContext, createDefaultParsingContext()); System.out.println("Unmarshalled value: " + unmarshalled); assertEquals("Unmarshalled value differs from the original", protectedStringType, unmarshalled); } }