@Override public String generate(final List<PasswordPolicy> policies) throws InvalidPasswordRuleConf { List<DefaultPasswordRuleConf> defaultRuleConfs = new ArrayList<>(); policies.stream().forEach(policy -> policy.getRules().forEach(impl -> { try { ImplementationManager.buildPasswordRule(impl).ifPresent(rule -> { if (rule.getConf() instanceof DefaultPasswordRuleConf) { defaultRuleConfs.add((DefaultPasswordRuleConf) rule.getConf()); } }); } catch (Exception e) { LOG.error("Invalid {}, ignoring...", impl, e); } })); DefaultPasswordRuleConf ruleConf = merge(defaultRuleConfs); check(ruleConf); return generate(ruleConf); }
int maxPPSpecHistory = 0; for (PasswordPolicy policy : getPasswordPolicies(user)) { if (user.getPassword() == null && !policy.isAllowNullPassword()) { throw new PasswordPolicyException("Password mandatory"); for (Implementation impl : policy.getRules()) { ImplementationManager.buildPasswordRule(impl).ifPresent(rule -> rule.enforce(user)); if (policy.getHistoryLength() > 0) { List<String> pwdHistory = user.getPasswordHistory(); matching = pwdHistory.subList(policy.getHistoryLength() >= pwdHistory.size() ? 0 : pwdHistory.size() - policy.getHistoryLength(), pwdHistory.size()).stream(). map(old -> ENCRYPTOR.verify(user.getClearPassword(), user.getCipherAlgorithm(), old)). reduce(matching, (accumulator, item) -> accumulator | item); if (policy.getHistoryLength() > maxPPSpecHistory) { maxPPSpecHistory = policy.getHistoryLength();
PasswordPolicyTO passwordPolicyTO = PasswordPolicyTO.class.cast(policyTO); passwordPolicy.setAllowNullPassword(passwordPolicyTO.isAllowNullPassword()); passwordPolicy.setHistoryLength(passwordPolicyTO.getHistoryLength()); LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", ruleKey); } else { passwordPolicy.add(rule); passwordPolicy.getRules(). removeIf(implementation -> !passwordPolicyTO.getRules().contains(implementation.getKey())); } else if (policyTO instanceof AccountPolicyTO) {
@Override public RealmTO getRealmTO(final Realm realm, final boolean admin) { RealmTO realmTO = new RealmTO(); realmTO.setKey(realm.getKey()); realmTO.setName(realm.getName()); realmTO.setParent(realm.getParent() == null ? null : realm.getParent().getKey()); realmTO.setFullPath(realm.getFullPath()); if (admin) { realmTO.setAccountPolicy(realm.getAccountPolicy() == null ? null : realm.getAccountPolicy().getKey()); realmTO.setPasswordPolicy(realm.getPasswordPolicy() == null ? null : realm.getPasswordPolicy().getKey()); realm.getActions().forEach(action -> { realmTO.getActions().add(action.getKey()); }); realm.getTemplates().forEach(template -> { realmTO.getTemplates().put(template.getAnyType().getKey(), template.get()); }); realm.getResources().forEach(resource -> { realmTO.getResources().add(resource.getKey()); }); } return realmTO; }
policyTO = (T) passwordPolicyTO; passwordPolicyTO.setAllowNullPassword(passwordPolicy.isAllowNullPassword()); passwordPolicyTO.setHistoryLength(passwordPolicy.getHistoryLength()); passwordPolicy.getRules().stream().map(Entity::getKey).collect(Collectors.toList())); } else if (policy instanceof AccountPolicy) { AccountPolicy accountPolicy = AccountPolicy.class.cast(policy);
? null : resource.getPasswordPolicy().getKey());
@Override public String generate(final List<PasswordPolicy> policies) throws InvalidPasswordRuleConf { List<DefaultPasswordRuleConf> defaultRuleConfs = new ArrayList<>(); policies.stream().forEach(policy -> policy.getRules().forEach(impl -> { try { ImplementationManager.buildPasswordRule(impl).ifPresent(rule -> { if (rule.getConf() instanceof DefaultPasswordRuleConf) { defaultRuleConfs.add((DefaultPasswordRuleConf) rule.getConf()); } }); } catch (Exception e) { LOG.error("Invalid {}, ignoring...", impl, e); } })); DefaultPasswordRuleConf ruleConf = merge(defaultRuleConfs); check(ruleConf); return generate(ruleConf); }