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

net.unicon.cas.mfa.authentication.CasMultiFactorApplicationContextAware 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 org.jasig.cas.web.support.ArgumentExtractor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.webflow.engine.builder.support.FlowBuilderServices;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * Initialize the application context with the needed mfa configuration
 * as much as possible to simplify adding mfa into an existing overlay.
 *
 * @author Misagh Moayyed
 */
@Component
public final class CasMultiFactorApplicationContextAware implements InitializingBean {
    private static final Logger LOGGER = LoggerFactory.getLogger(CasMultiFactorApplicationContextAware.class);

    @Autowired
    private FlowBuilderServices flowBuilderServices;

    @Autowired
    @Qualifier("mfaRequestsCollectingArgumentExtractor")
    private ArgumentExtractor mfaRequestsCollectingArgumentExtractor;

    @Override
    @PostConstruct
    public void afterPropertiesSet() throws Exception {
        try {
            LOGGER.debug("Configuring application context for multifactor authentication...");
            addMultifactorArgumentExtractorConfiguration();
            LOGGER.debug("Configured application context for multifactor authentication.");

        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
    }

    /**
     * Add multifactor argument extractor configuration.
     */
    private void addMultifactorArgumentExtractorConfiguration() {
        LOGGER.debug("Configuring application context with [{}]",
                mfaRequestsCollectingArgumentExtractor.getClass().getName());

        final List list = this.flowBuilderServices.getApplicationContext().getBean("argumentExtractors", List.class);
        list.add(0, mfaRequestsCollectingArgumentExtractor);
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy