@Override public boolean isSatisfiedBy(final Authentication authn, final Set<AuthenticationHandler> authenticationHandlers) { LOGGER.debug("Successful authentications: [{}], credentials: [{}]", authn.getSuccesses().keySet(), authn.getCredentials()); if (authn.getSuccesses().size() != authn.getCredentials().size()) { LOGGER.warn("Number of successful authentications, [{}], does not match the number of provided credentials, [{}].", authn.getSuccesses().size(), authn.getCredentials().size()); return false; } LOGGER.debug("Authentication policy is satisfied."); return true; } }
/** * Locate matching credential type boolean. * * @param authentication the authentication * @param credentialClassType the credential class type * @return the boolean */ protected boolean locateMatchingCredentialType(final Authentication authentication, final String credentialClassType) { return StringUtils.isNotBlank(credentialClassType) && authentication.getCredentials() .stream() .anyMatch(e -> e.getCredentialClass().getName().matches(credentialClassType)); }
@Override public boolean isSatisfiedBy(final Authentication authn, final Set<AuthenticationHandler> authenticationHandlers) throws Exception { if (this.tryAll) { val sum = authn.getSuccesses().size() + authn.getFailures().size(); if (authn.getCredentials().size() != sum) { LOGGER.warn("Number of provided credentials [{}] does not match the sum of authentication successes and failures [{}]", authn.getCredentials().size(), sum); return false; } LOGGER.debug("Authentication policy is satisfied with all authentication transactions"); return true; } if (!authn.getSuccesses().isEmpty()) { LOGGER.debug("Authentication policy is satisfied having found at least one authentication transactions"); return true; } LOGGER.warn("Authentication policy has failed to find a successful authentication transaction"); return false; } }
val sum = authn.getSuccesses().size() + authn.getFailures().size(); if (this.tryAll) { credsOk = authn.getCredentials().size() == sum; + "Successful authentication handlers are [{}]", authn.getCredentials().size(), sum, authn.getSuccesses().keySet()); return false;
private static void buildAuthenticationHistory(final Set<Authentication> authentications, final Map<String, Object> authenticationAttributes, final Map<String, Object> principalAttributes, final AuthenticationBuilder authenticationBuilder) { LOGGER.trace("Collecting authentication history based on [{}] authentication events", authentications.size()); authentications.forEach(authn -> { val authenticatedPrincipal = authn.getPrincipal(); LOGGER.debug("Evaluating authentication principal [{}] for inclusion in result", authenticatedPrincipal); principalAttributes.putAll(CoreAuthenticationUtils.mergeAttributes(principalAttributes, authenticatedPrincipal.getAttributes())); LOGGER.debug("Collected principal attributes [{}] for inclusion in this result for principal [{}]", principalAttributes, authenticatedPrincipal.getId()); authenticationAttributes.putAll(CoreAuthenticationUtils.mergeAttributes(authenticationAttributes, authn.getAttributes())); LOGGER.debug("Finalized authentication attributes [{}] for inclusion in this authentication result", authenticationAttributes); authenticationBuilder .addSuccesses(authn.getSuccesses()) .addFailures(authn.getFailures()) .addCredentials(authn.getCredentials()); }); }
/** * Creates a new builder initialized with data from the given authentication source. * * @param source Authentication source. * @return New builder instance initialized with all fields in the given authentication source. */ public static AuthenticationBuilder newInstance(final Authentication source) { val builder = new DefaultAuthenticationBuilder(source.getPrincipal()); builder.setAuthenticationDate(source.getAuthenticationDate()); builder.setCredentials(source.getCredentials()); builder.setSuccesses(source.getSuccesses()); builder.setFailures(source.getFailures()); builder.setAttributes(source.getAttributes()); return builder; }