net.unicon.cas.mfa.authentication.StubAuthenticationMethodTranslator 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.authentication;
import net.unicon.cas.mfa.web.support.UnrecognizedAuthenticationMethodException;
import org.jasig.cas.authentication.principal.WebApplicationService;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
/**
* A stub translator that receives its legend as a map. The key for the map
* should be the set of received authentication methods, and the value is a single
* string to define the new authentication method name.
*
* If no
* @author Misagh Moayyed
*/
public class StubAuthenticationMethodTranslator implements AuthenticationMethodTranslator {
private final Map, String> translationMap;
private boolean ignoreIfNoMatchIsFound = true;
/**
* Instantiates a new Stub authentication method translator.
*/
public StubAuthenticationMethodTranslator() {
this(Collections.EMPTY_MAP);
}
/**
* Instantiates a new Sutb authentication method translator.
*
* @param translationMap the translation map
*/
public StubAuthenticationMethodTranslator(final Map, String> translationMap) {
this.translationMap = translationMap;
}
public void setIgnoreIfNoMatchIsFound(final boolean ignoreIfNoMatchIsFound) {
this.ignoreIfNoMatchIsFound = ignoreIfNoMatchIsFound;
}
@Override
public String translate(final WebApplicationService targetService, final String receivedAuthenticationMethod) {
final Set> keys = this.translationMap.keySet();
for (final Set keyset : keys) {
if (keyset.contains(receivedAuthenticationMethod)) {
return this.translationMap.get(keyset);
}
}
if (this.ignoreIfNoMatchIsFound) {
return receivedAuthenticationMethod;
}
throw new UnrecognizedAuthenticationMethodException(receivedAuthenticationMethod, targetService.getId());
}
}