net.unicon.cas.mfa.util.MultiFactorUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cas-mfa-java Show documentation
Show all versions of cas-mfa-java Show documentation
This module is intended to include all the Java you need to add to a CAS implementation
to take advantage of the extended multifactor authentication features in this project.
package net.unicon.cas.mfa.util;
import net.unicon.cas.mfa.web.support.MultiFactorAuthenticationSupportingWebApplicationService;
import org.apache.commons.lang.StringUtils;
import org.jasig.cas.authentication.Authentication;
import org.jasig.cas.validation.Assertion;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Utility methods to ease implementation of multifactor behavior.
* @author Misagh Moayyed
*/
public final class MultiFactorUtils {
/**
* Private constructor.
*/
private MultiFactorUtils() {
}
/**
* Generate the string the indicates the list of satisfied authentication methods.
* Methods are separated by a space.
* @param assertion the assertion carrying the methods.
* @return the space-delimited list of authentication methods, or null if none is available
*/
public static String getFulfilledAuthenticationMethodsAsString(final Assertion assertion) {
final Authentication authentication = getAuthenticationFromAssertion(assertion);
return getFulfilledAuthenticationMethodsAsString(authentication);
}
/**
* Generate the string the indicates the list of satisfied authentication methods.
* Methods are separated by a space.
* @param authentication the authentication carrying the methods.
* @return the space-delimited list of authentication methods, or null if none is available
*/
public static String getFulfilledAuthenticationMethodsAsString(final Authentication authentication) {
final Set previouslyAchievedAuthenticationMethods = getSatisfiedAuthenticationMethods(authentication);
if (previouslyAchievedAuthenticationMethods.size() > 0) {
return StringUtils.join(previouslyAchievedAuthenticationMethods, " ");
}
return null;
}
/**
* Convert the object given into a {@link Collection} instead.
* @param obj the object to convert into a collection
* @return The collection instance containing the object provided
*/
@SuppressWarnings("unchecked")
public static Set