@Test public void prepareAttrsForUser() { User bellini = userDAO.findByUsername("bellini"); ExternalResource ldap = resourceDAO.find("resource-ldap"); Provision provision = ldap.getProvision(AnyTypeKind.USER.name()).get(); assertNotEquals(CipherAlgorithm.AES, bellini.getCipherAlgorithm()); Pair<String, Set<Attribute>> attrs = mappingManager.prepareAttrsFromAny( bellini, "Password123", true, Boolean.TRUE, provision); assertEquals("bellini", attrs.getLeft()); assertEquals( "uid=bellini,ou=people,o=isp", AttributeUtil.getNameFromAttributes(attrs.getRight()).getNameValue()); assertEquals("Password123", SecurityUtil.decrypt(AttributeUtil.getPasswordValue(attrs.getRight()))); attrs = mappingManager.prepareAttrsFromAny( bellini, "Password123", false, Boolean.TRUE, provision); assertNull(AttributeUtil.getPasswordValue(attrs.getRight())); ldap.setRandomPwdIfNotProvided(true); ldap = resourceDAO.save(ldap); entityManager().flush(); String encPassword = bellini.getPassword(); attrs = mappingManager.prepareAttrsFromAny( bellini, null, true, Boolean.TRUE, provision); assertNotEquals(encPassword, SecurityUtil.decrypt(AttributeUtil.getPasswordValue(attrs.getRight()))); ldap.setRandomPwdIfNotProvided(false); resourceDAO.save(ldap); entityManager().flush(); attrs = mappingManager.prepareAttrsFromAny( bellini, null, true, Boolean.TRUE, provision); assertNull(AttributeUtil.getPasswordValue(attrs.getRight())); bellini.setPassword("newPassword123", CipherAlgorithm.AES); userDAO.save(bellini); entityManager().flush(); assertEquals(CipherAlgorithm.AES, bellini.getCipherAlgorithm()); attrs = mappingManager.prepareAttrsFromAny( bellini, null, true, Boolean.TRUE, provision); assertEquals("newPassword123", SecurityUtil.decrypt(AttributeUtil.getPasswordValue(attrs.getRight()))); }
@Transactional(readOnly = true) @Override public Pair<String, Set<Attribute>> prepareAttrsFromAny( final Any<?> any, final String password, final boolean changePwd, final Boolean enable, final Provision provision) { LOG.debug("Preparing resource attributes for {} with provision {} for attributes {}", any, provision, any.getPlainAttrs()); Set<Attribute> attributes = new HashSet<>(); String[] connObjectKeyValue = new String[1]; MappingUtils.getPropagationItems(provision.getMapping().getItems().stream()).forEach(mapItem -> { LOG.debug("Processing expression '{}'", mapItem.getIntAttrName()); try { String processedConnObjectKeyValue = processPreparedAttr( prepareAttr( provision, mapItem, any, password, AccountGetter.DEFAULT, AccountGetter.DEFAULT, PlainAttrGetter.DEFAULT), attributes); if (processedConnObjectKeyValue != null) { connObjectKeyValue[0] = processedConnObjectKeyValue; } } catch (Exception e) { LOG.error("Expression '{}' processing failed", mapItem.getIntAttrName(), e); } }); MappingUtils.getConnObjectKeyItem(provision).ifPresent(connObjectKeyItem -> { Attribute connObjectKeyAttr = AttributeUtil.find(connObjectKeyItem.getExtAttrName(), attributes); if (connObjectKeyAttr != null) { attributes.remove(connObjectKeyAttr); attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKeyValue[0])); } Name name = evaluateNAME(any, provision, connObjectKeyValue[0]); attributes.add(name); if (connObjectKeyAttr == null && connObjectKeyValue[0] != null && !connObjectKeyValue[0].equals(name.getNameValue())) { attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKeyValue[0])); } }); if (enable != null) { attributes.add(AttributeBuilder.buildEnabled(enable)); } if (!changePwd) { Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes); if (pwdAttr != null) { attributes.remove(pwdAttr); } } return Pair.of(connObjectKeyValue[0], attributes); }
MappingManagerImpl implements MappingManager { @Transactional(readOnly = true) @Override public Pair<String, Set<Attribute>> prepareAttrsFromAny( final Any<?> any, final String password, final boolean changePwd, final Boolean enable, final Provision provision) { LOG.debug("Preparing resource attributes for {} with provision {} for attributes {}", any, provision, any.getPlainAttrs()); Set<Attribute> attributes = new HashSet<>(); String[] connObjectKeyValue = new String[1]; MappingUtils.getPropagationItems(provision.getMapping().getItems().stream()).forEach(mapItem -> { LOG.debug("Processing expression '{}'", mapItem.getIntAttrName()); try { String processedConnObjectKeyValue = processPreparedAttr( prepareAttr( provision, mapItem, any, password, AccountGetter.DEFAULT, AccountGetter.DEFAULT, PlainAttrGetter.DEFAULT), attributes); if (processedConnObjectKeyValue != null) { connObjectKeyValue[0] = processedConnObjectKeyValue; } } catch (Exception e) { LOG.error("Expression '{}' processing failed", mapItem.getIntAttrName(), e); } }); MappingUtils.getConnObjectKeyItem(provision).ifPresent(connObjectKeyItem -> { Attribute connObjectKeyAttr = AttributeUtil.find(connObjectKeyItem.getExtAttrName(), attributes); if (connObjectKeyAttr != null) { attributes.remove(connObjectKeyAttr); attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKeyValue[0])); } Name name = evaluateNAME(any, provision, connObjectKeyValue[0]); attributes.add(name); if (connObjectKeyAttr == null && connObjectKeyValue[0] != null && !connObjectKeyValue[0].equals(name.getNameValue())) { attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKeyValue[0])); } }); if (enable != null) { attributes.add(AttributeBuilder.buildEnabled(enable)); } if (!changePwd) { Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes); if (pwdAttr != null) { attributes.remove(pwdAttr); } } return Pair.of(connObjectKeyValue[0], attributes); } }
MappingManagerImpl implements MappingManager { @Transactional(readOnly = true) @Override public Pair<String, Set<Attribute>> prepareAttrsFromAny( final Any<?> any, final String password, final boolean changePwd, final Boolean enable, final Provision provision) { LOG.debug("Preparing resource attributes for {} with provision {} for attributes {}", any, provision, any.getPlainAttrs()); Set<Attribute> attributes = new HashSet<>(); String[] connObjectKeyValue = new String[1]; MappingUtils.getPropagationItems(provision.getMapping().getItems().stream()).forEach(mapItem -> { LOG.debug("Processing expression '{}'", mapItem.getIntAttrName()); try { String processedConnObjectKeyValue = processPreparedAttr( prepareAttr( provision, mapItem, any, password, AccountGetter.DEFAULT, AccountGetter.DEFAULT, PlainAttrGetter.DEFAULT), attributes); if (processedConnObjectKeyValue != null) { connObjectKeyValue[0] = processedConnObjectKeyValue; } } catch (Exception e) { LOG.error("Expression '{}' processing failed", mapItem.getIntAttrName(), e); } }); MappingUtils.getConnObjectKeyItem(provision).ifPresent(connObjectKeyItem -> { Attribute connObjectKeyAttr = AttributeUtil.find(connObjectKeyItem.getExtAttrName(), attributes); if (connObjectKeyAttr != null) { attributes.remove(connObjectKeyAttr); attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKeyValue[0])); } Name name = evaluateNAME(any, provision, connObjectKeyValue[0]); attributes.add(name); if (connObjectKeyAttr == null && connObjectKeyValue[0] != null && !connObjectKeyValue[0].equals(name.getNameValue())) { attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKeyValue[0])); } }); if (enable != null) { attributes.add(AttributeBuilder.buildEnabled(enable)); } if (!changePwd) { Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes); if (pwdAttr != null) { attributes.remove(pwdAttr); } } return Pair.of(connObjectKeyValue[0], attributes); }  }
MappingManagerImpl implements MappingManager { @Transactional(readOnly = true) @Override public Pair<String, Set<Attribute>> prepareAttrsFromAny( final Any<?> any, final String password, final boolean changePwd, final Boolean enable, final Provision provision) { LOG.debug("Preparing resource attributes for {} with provision {} for attributes {}", any, provision, any.getPlainAttrs()); Set<Attribute> attributes = new HashSet<>(); String[] connObjectKeyValue = new String[1]; MappingUtils.getPropagationItems(provision.getMapping().getItems().stream()).forEach(mapItem -> { LOG.debug("Processing expression '{}'", mapItem.getIntAttrName()); try { String processedConnObjectKeyValue = processPreparedAttr( prepareAttr( provision, mapItem, any, password, AccountGetter.DEFAULT, AccountGetter.DEFAULT, PlainAttrGetter.DEFAULT), attributes); if (processedConnObjectKeyValue != null) { connObjectKeyValue[0] = processedConnObjectKeyValue; } } catch (Exception e) { LOG.error("Expression '{}' processing failed", mapItem.getIntAttrName(), e); } }); MappingUtils.getConnObjectKeyItem(provision).ifPresent(connObjectKeyItem -> { Attribute connObjectKeyAttr = AttributeUtil.find(connObjectKeyItem.getExtAttrName(), attributes); if (connObjectKeyAttr != null) { attributes.remove(connObjectKeyAttr); attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKeyValue[0])); } Name name = evaluateNAME(any, provision, connObjectKeyValue[0]); attributes.add(name); if (connObjectKeyAttr == null && connObjectKeyValue[0] != null && !connObjectKeyValue[0].equals(name.getNameValue())) { attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKeyValue[0])); } }); if (enable != null) { attributes.add(AttributeBuilder.buildEnabled(enable)); } if (!changePwd) { Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes); if (pwdAttr != null) { attributes.remove(pwdAttr); } } return Pair.of(connObjectKeyValue[0], attributes); }  @Transactional(readOnly = true) @Override Pair<String, Set<Attribute>> prepareAttrsFromAny(
            final Any<?> any,
            final String password,
            final boolean changePwd,
            final Boolean enable,
            final Provision provision); @Transactional(readOnly = true) @Override Set<Attribute> prepareAttrsFromLinkedAccount(
            final User user,
            final LinkedAccount account,
            final String password,
            final boolean changePwd,
            final Provision provision); @Override Pair<String, Set<Attribute>> prepareAttrsFromRealm(final Realm realm, final OrgUnit orgUnit); @Override Pair<String, Attribute> prepareAttr(
            final Provision provision,
            final Item item,
            final Any<?> any,
            final String password,
            final AccountGetter usernameAccountGetter,
            final AccountGetter passwordAccountGetter,
            final PlainAttrGetter plainAttrGetter); @Transactional(readOnly = true) @SuppressWarnings("unchecked") @Override Pair<AttrSchemaType, List<PlainAttrValue>> getIntValues(
            final Provision provision,
            final Item mapItem,
            final IntAttrName intAttrName,
            final AttrSchemaType schemaType,
            final Any<?> any,
            final AccountGetter usernameAccountGetter,
            final PlainAttrGetter plainAttrGetter); @Transactional(readOnly = true) @Override Optional<String> getConnObjectKeyValue(final Any<?> any, final Provision provision); @Transactional(readOnly = true) @Override Optional<String> getConnObjectKeyValue(final Realm realm, final OrgUnit orgUnit); @Transactional(readOnly = true) @Override void setIntValues(final Item mapItem, final Attribute attr, final AnyTO anyTO); @Override void setIntValues(final Item orgUnitItem, final Attribute attr, final RealmTO realmTO); @Transactional(readOnly = true) @Override boolean hasMustChangePassword(final Provision provision); }
MappingManagerImpl implements MappingManager { @Transactional(readOnly = true) @Override public Pair<String, Set<Attribute>> prepareAttrsFromAny( final Any<?> any, final String password, final boolean changePwd, final Boolean enable, final Provision provision) { LOG.debug("Preparing resource attributes for {} with provision {} for attributes {}", any, provision, any.getPlainAttrs()); Set<Attribute> attributes = new HashSet<>(); String[] connObjectKeyValue = new String[1]; MappingUtils.getPropagationItems(provision.getMapping().getItems().stream()).forEach(mapItem -> { LOG.debug("Processing expression '{}'", mapItem.getIntAttrName()); try { String processedConnObjectKeyValue = processPreparedAttr( prepareAttr( provision, mapItem, any, password, AccountGetter.DEFAULT, AccountGetter.DEFAULT, PlainAttrGetter.DEFAULT), attributes); if (processedConnObjectKeyValue != null) { connObjectKeyValue[0] = processedConnObjectKeyValue; } } catch (Exception e) { LOG.error("Expression '{}' processing failed", mapItem.getIntAttrName(), e); } }); MappingUtils.getConnObjectKeyItem(provision).ifPresent(connObjectKeyItem -> { Attribute connObjectKeyAttr = AttributeUtil.find(connObjectKeyItem.getExtAttrName(), attributes); if (connObjectKeyAttr != null) { attributes.remove(connObjectKeyAttr); attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKeyValue[0])); } Name name = evaluateNAME(any, provision, connObjectKeyValue[0]); attributes.add(name); if (connObjectKeyAttr == null && connObjectKeyValue[0] != null && !connObjectKeyValue[0].equals(name.getNameValue())) { attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKeyValue[0])); } }); if (enable != null) { attributes.add(AttributeBuilder.buildEnabled(enable)); } if (!changePwd) { Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes); if (pwdAttr != null) { attributes.remove(pwdAttr); } } return Pair.of(connObjectKeyValue[0], attributes); }  @Transactional(readOnly = true) @Override Pair<String, Set<Attribute>> prepareAttrsFromAny(
            final Any<?> any,
            final String password,
            final boolean changePwd,
            final Boolean enable,
            final Provision provision); @Transactional(readOnly = true) @Override Set<Attribute> prepareAttrsFromLinkedAccount(
            final User user,
            final LinkedAccount account,
            final String password,
            final boolean changePwd,
            final Provision provision); @Override Pair<String, Set<Attribute>> prepareAttrsFromRealm(final Realm realm, final OrgUnit orgUnit); @Override Pair<String, Attribute> prepareAttr(
            final Provision provision,
            final Item item,
            final Any<?> any,
            final String password,
            final AccountGetter usernameAccountGetter,
            final AccountGetter passwordAccountGetter,
            final PlainAttrGetter plainAttrGetter); @Transactional(readOnly = true) @SuppressWarnings("unchecked") @Override Pair<AttrSchemaType, List<PlainAttrValue>> getIntValues(
            final Provision provision,
            final Item mapItem,
            final IntAttrName intAttrName,
            final AttrSchemaType schemaType,
            final Any<?> any,
            final AccountGetter usernameAccountGetter,
            final PlainAttrGetter plainAttrGetter); @Transactional(readOnly = true) @Override Optional<String> getConnObjectKeyValue(final Any<?> any, final Provision provision); @Transactional(readOnly = true) @Override Optional<String> getConnObjectKeyValue(final Realm realm, final OrgUnit orgUnit); @Transactional(readOnly = true) @Override void setIntValues(final Item mapItem, final Attribute attr, final AnyTO anyTO); @Override void setIntValues(final Item orgUnitItem, final Attribute attr, final RealmTO realmTO); @Transactional(readOnly = true) @Override boolean hasMustChangePassword(final Provision provision);  }