All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.unicon.cas.mfa.authentication.StubAuthenticationMethodTranslator Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 2.0.0-RC3
Show newest version
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());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy