@Test public void prepareAttrsForLinkedAccount() { User vivaldi = userDAO.findByUsername("vivaldi"); ExternalResource ldap = resourceDAO.find("resource-ldap"); Provision provision = ldap.getProvision(AnyTypeKind.USER.name()).get(); LinkedAccount account = entityFactory.newEntity(LinkedAccount.class); account.setConnObjectKeyValue("admin"); account.setResource(ldap); account.setOwner(vivaldi); account.setPassword("Password321", CipherAlgorithm.AES); vivaldi.add(account); vivaldi = userDAO.save(vivaldi); entityManager().flush(); Set<Attribute> attrs = mappingManager.prepareAttrsFromLinkedAccount( vivaldi, account, "Password123", true, provision); assertEquals("admin", AttributeUtil.getStringValue(AttributeUtil.find("cn", attrs))); assertEquals("Password321", SecurityUtil.decrypt(AttributeUtil.getPasswordValue(attrs))); account.setEncodedPassword(null, null); attrs = mappingManager.prepareAttrsFromLinkedAccount( vivaldi, account, "Password123", true, provision); assertEquals("Password123", SecurityUtil.decrypt(AttributeUtil.getPasswordValue(attrs))); attrs = mappingManager.prepareAttrsFromLinkedAccount( vivaldi, account, "Password123", false, provision); assertNull(AttributeUtil.getPasswordValue(attrs)); ldap.setRandomPwdIfNotProvided(true); ldap = resourceDAO.save(ldap); entityManager().flush(); String encPassword = vivaldi.getPassword(); attrs = mappingManager.prepareAttrsFromLinkedAccount( vivaldi, account, null, true, provision); assertNotEquals(encPassword, SecurityUtil.decrypt(AttributeUtil.getPasswordValue(attrs))); ldap.setRandomPwdIfNotProvided(false); resourceDAO.save(ldap); entityManager().flush(); attrs = mappingManager.prepareAttrsFromLinkedAccount( vivaldi, account, null, true, provision); assertNull(AttributeUtil.getPasswordValue(attrs)); }
@Transactional(readOnly = true) @Override public Set<Attribute> prepareAttrsFromLinkedAccount( final User user, final LinkedAccount account, final String password, final boolean changePwd, final Provision provision) { LOG.debug("Preparing resource attributes for linked account {} of user {} with provision {} " + "for user attributes {} with override {}", account, user, provision, user.getPlainAttrs(), account.getPlainAttrs()); Set<Attribute> attributes = new HashSet<>(); MappingUtils.getPropagationItems(provision.getMapping().getItems().stream()).forEach(mapItem -> { LOG.debug("Processing expression '{}'", mapItem.getIntAttrName()); try { processPreparedAttr( prepareAttr( provision, mapItem, user, password, acct -> account.getUsername() == null ? AccountGetter.DEFAULT.apply(acct) : account, acct -> account.getPassword() == null ? AccountGetter.DEFAULT.apply(acct) : account, (attributable, schema) -> { PlainAttr<?> result = null; if (attributable instanceof User) { Optional<? extends LAPlainAttr> accountAttr = account.getPlainAttr(schema); if (accountAttr.isPresent()) { result = accountAttr.get(); } } if (result == null) { result = PlainAttrGetter.DEFAULT.apply(attributable, schema); } return result; }), attributes); } catch (Exception e) { LOG.error("Expression '{}' processing failed", mapItem.getIntAttrName(), e); } }); String connObjectKey = account.getConnObjectKeyValue(); MappingUtils.getConnObjectKeyItem(provision).ifPresent(connObjectKeyItem -> { Attribute connObjectKeyExtAttr = AttributeUtil.find(connObjectKeyItem.getExtAttrName(), attributes); if (connObjectKeyExtAttr != null) { attributes.remove(connObjectKeyExtAttr); attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKey)); } Name name = evaluateNAME(user, provision, connObjectKey); attributes.add(name); if (!connObjectKey.equals(name.getNameValue()) && connObjectKeyExtAttr == null) { attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKey)); } }); if (account.isSuspended() != null) { attributes.add(AttributeBuilder.buildEnabled(!BooleanUtils.negate(account.isSuspended()))); } if (!changePwd) { Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes); if (pwdAttr != null) { attributes.remove(pwdAttr); } } return attributes; }
MappingManagerImpl implements MappingManager { @Transactional(readOnly = true) @Override public Set<Attribute> prepareAttrsFromLinkedAccount( final User user, final LinkedAccount account, final String password, final boolean changePwd, final Provision provision) { LOG.debug("Preparing resource attributes for linked account {} of user {} with provision {} " + "for user attributes {} with override {}", account, user, provision, user.getPlainAttrs(), account.getPlainAttrs()); Set<Attribute> attributes = new HashSet<>(); MappingUtils.getPropagationItems(provision.getMapping().getItems().stream()).forEach(mapItem -> { LOG.debug("Processing expression '{}'", mapItem.getIntAttrName()); try { processPreparedAttr( prepareAttr( provision, mapItem, user, password, acct -> account.getUsername() == null ? AccountGetter.DEFAULT.apply(acct) : account, acct -> account.getPassword() == null ? AccountGetter.DEFAULT.apply(acct) : account, (attributable, schema) -> { PlainAttr<?> result = null; if (attributable instanceof User) { Optional<? extends LAPlainAttr> accountAttr = account.getPlainAttr(schema); if (accountAttr.isPresent()) { result = accountAttr.get(); } } if (result == null) { result = PlainAttrGetter.DEFAULT.apply(attributable, schema); } return result; }), attributes); } catch (Exception e) { LOG.error("Expression '{}' processing failed", mapItem.getIntAttrName(), e); } }); String connObjectKey = account.getConnObjectKeyValue(); MappingUtils.getConnObjectKeyItem(provision).ifPresent(connObjectKeyItem -> { Attribute connObjectKeyExtAttr = AttributeUtil.find(connObjectKeyItem.getExtAttrName(), attributes); if (connObjectKeyExtAttr != null) { attributes.remove(connObjectKeyExtAttr); attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKey)); } Name name = evaluateNAME(user, provision, connObjectKey); attributes.add(name); if (!connObjectKey.equals(name.getNameValue()) && connObjectKeyExtAttr == null) { attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKey)); } }); if (account.isSuspended() != null) { attributes.add(AttributeBuilder.buildEnabled(!BooleanUtils.negate(account.isSuspended()))); } if (!changePwd) { Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes); if (pwdAttr != null) { attributes.remove(pwdAttr); } } return attributes; } }
MappingManagerImpl implements MappingManager { @Transactional(readOnly = true) @Override public Set<Attribute> prepareAttrsFromLinkedAccount( final User user, final LinkedAccount account, final String password, final boolean changePwd, final Provision provision) { LOG.debug("Preparing resource attributes for linked account {} of user {} with provision {} " + "for user attributes {} with override {}", account, user, provision, user.getPlainAttrs(), account.getPlainAttrs()); Set<Attribute> attributes = new HashSet<>(); MappingUtils.getPropagationItems(provision.getMapping().getItems().stream()).forEach(mapItem -> { LOG.debug("Processing expression '{}'", mapItem.getIntAttrName()); try { processPreparedAttr( prepareAttr( provision, mapItem, user, password, acct -> account.getUsername() == null ? AccountGetter.DEFAULT.apply(acct) : account, acct -> account.getPassword() == null ? AccountGetter.DEFAULT.apply(acct) : account, (attributable, schema) -> { PlainAttr<?> result = null; if (attributable instanceof User) { Optional<? extends LAPlainAttr> accountAttr = account.getPlainAttr(schema); if (accountAttr.isPresent()) { result = accountAttr.get(); } } if (result == null) { result = PlainAttrGetter.DEFAULT.apply(attributable, schema); } return result; }), attributes); } catch (Exception e) { LOG.error("Expression '{}' processing failed", mapItem.getIntAttrName(), e); } }); String connObjectKey = account.getConnObjectKeyValue(); MappingUtils.getConnObjectKeyItem(provision).ifPresent(connObjectKeyItem -> { Attribute connObjectKeyExtAttr = AttributeUtil.find(connObjectKeyItem.getExtAttrName(), attributes); if (connObjectKeyExtAttr != null) { attributes.remove(connObjectKeyExtAttr); attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKey)); } Name name = evaluateNAME(user, provision, connObjectKey); attributes.add(name); if (!connObjectKey.equals(name.getNameValue()) && connObjectKeyExtAttr == null) { attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKey)); } }); if (account.isSuspended() != null) { attributes.add(AttributeBuilder.buildEnabled(!BooleanUtils.negate(account.isSuspended()))); } if (!changePwd) { Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes); if (pwdAttr != null) { attributes.remove(pwdAttr); } } return attributes; }  }
MappingManagerImpl implements MappingManager { @Transactional(readOnly = true) @Override public Set<Attribute> prepareAttrsFromLinkedAccount( final User user, final LinkedAccount account, final String password, final boolean changePwd, final Provision provision) { LOG.debug("Preparing resource attributes for linked account {} of user {} with provision {} " + "for user attributes {} with override {}", account, user, provision, user.getPlainAttrs(), account.getPlainAttrs()); Set<Attribute> attributes = new HashSet<>(); MappingUtils.getPropagationItems(provision.getMapping().getItems().stream()).forEach(mapItem -> { LOG.debug("Processing expression '{}'", mapItem.getIntAttrName()); try { processPreparedAttr( prepareAttr( provision, mapItem, user, password, acct -> account.getUsername() == null ? AccountGetter.DEFAULT.apply(acct) : account, acct -> account.getPassword() == null ? AccountGetter.DEFAULT.apply(acct) : account, (attributable, schema) -> { PlainAttr<?> result = null; if (attributable instanceof User) { Optional<? extends LAPlainAttr> accountAttr = account.getPlainAttr(schema); if (accountAttr.isPresent()) { result = accountAttr.get(); } } if (result == null) { result = PlainAttrGetter.DEFAULT.apply(attributable, schema); } return result; }), attributes); } catch (Exception e) { LOG.error("Expression '{}' processing failed", mapItem.getIntAttrName(), e); } }); String connObjectKey = account.getConnObjectKeyValue(); MappingUtils.getConnObjectKeyItem(provision).ifPresent(connObjectKeyItem -> { Attribute connObjectKeyExtAttr = AttributeUtil.find(connObjectKeyItem.getExtAttrName(), attributes); if (connObjectKeyExtAttr != null) { attributes.remove(connObjectKeyExtAttr); attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKey)); } Name name = evaluateNAME(user, provision, connObjectKey); attributes.add(name); if (!connObjectKey.equals(name.getNameValue()) && connObjectKeyExtAttr == null) { attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKey)); } }); if (account.isSuspended() != null) { attributes.add(AttributeBuilder.buildEnabled(!BooleanUtils.negate(account.isSuspended()))); } if (!changePwd) { Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes); if (pwdAttr != null) { attributes.remove(pwdAttr); } } return 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 Set<Attribute> prepareAttrsFromLinkedAccount( final User user, final LinkedAccount account, final String password, final boolean changePwd, final Provision provision) { LOG.debug("Preparing resource attributes for linked account {} of user {} with provision {} " + "for user attributes {} with override {}", account, user, provision, user.getPlainAttrs(), account.getPlainAttrs()); Set<Attribute> attributes = new HashSet<>(); MappingUtils.getPropagationItems(provision.getMapping().getItems().stream()).forEach(mapItem -> { LOG.debug("Processing expression '{}'", mapItem.getIntAttrName()); try { processPreparedAttr( prepareAttr( provision, mapItem, user, password, acct -> account.getUsername() == null ? AccountGetter.DEFAULT.apply(acct) : account, acct -> account.getPassword() == null ? AccountGetter.DEFAULT.apply(acct) : account, (attributable, schema) -> { PlainAttr<?> result = null; if (attributable instanceof User) { Optional<? extends LAPlainAttr> accountAttr = account.getPlainAttr(schema); if (accountAttr.isPresent()) { result = accountAttr.get(); } } if (result == null) { result = PlainAttrGetter.DEFAULT.apply(attributable, schema); } return result; }), attributes); } catch (Exception e) { LOG.error("Expression '{}' processing failed", mapItem.getIntAttrName(), e); } }); String connObjectKey = account.getConnObjectKeyValue(); MappingUtils.getConnObjectKeyItem(provision).ifPresent(connObjectKeyItem -> { Attribute connObjectKeyExtAttr = AttributeUtil.find(connObjectKeyItem.getExtAttrName(), attributes); if (connObjectKeyExtAttr != null) { attributes.remove(connObjectKeyExtAttr); attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKey)); } Name name = evaluateNAME(user, provision, connObjectKey); attributes.add(name); if (!connObjectKey.equals(name.getNameValue()) && connObjectKeyExtAttr == null) { attributes.add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKey)); } }); if (account.isSuspended() != null) { attributes.add(AttributeBuilder.buildEnabled(!BooleanUtils.negate(account.isSuspended()))); } if (!changePwd) { Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes); if (pwdAttr != null) { attributes.remove(pwdAttr); } } return 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);  }