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

com.github.lontime.extpac4j.provider.SpringProvider Maven / Gradle / Ivy

The newest version!
package com.github.lontime.extpac4j.provider;

import java.util.List;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import org.pac4j.core.context.JEEContext;
import org.pac4j.core.context.WebContextFactory;
import org.pac4j.core.context.session.SessionStore;
import org.pac4j.core.engine.CallbackLogic;
import org.pac4j.core.engine.LogoutLogic;
import org.pac4j.core.http.adapter.HttpActionAdapter;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.core.profile.factory.ProfileManagerFactory;

/**
 * SpringProvider.
 * @author lontime
 * @since 1.0
 */
public class SpringProvider extends AbstractProvider {

    public static SpringProvider create() {
        return new SpringProvider();
    }

    @Override
    public String getName() {
        return "spring[pac4j]";
    }

    @Override
    public List getUserProfiles(SessionStore localSessionStore,
                                             WebContextFactory localContextFactory,
                                             ProfileManagerFactory localProfileManagerFactory) {
        final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        if (requestAttributes instanceof ServletRequestAttributes) {
            ServletRequestAttributes attributes = (ServletRequestAttributes) requestAttributes;
            return super.getUserProfiles(attributes.getRequest(), attributes.getResponse(),
                    localSessionStore, localContextFactory, localProfileManagerFactory);
        }
        return super.getUserProfiles();
    }

    @Override
    public void callback(HttpActionAdapter localAdapter,
                         SessionStore localSessionStore,
                         WebContextFactory localContextFactory,
                         CallbackLogic localCallbackLogic) {
        final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        if (requestAttributes instanceof ServletRequestAttributes) {
            ServletRequestAttributes attributes = (ServletRequestAttributes) requestAttributes;
           super.callback(attributes.getRequest(), attributes.getResponse(), localAdapter,
                   localSessionStore, localContextFactory, localCallbackLogic);
        }
    }

    @Override
    public void logout(HttpActionAdapter localAdapter,
                       SessionStore localSessionStore,
                       WebContextFactory localContextFactory,
                       LogoutLogic localLogoutLogic) {
        final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        if (requestAttributes instanceof ServletRequestAttributes) {
            ServletRequestAttributes attributes = (ServletRequestAttributes) requestAttributes;
            super.logout(attributes.getRequest(), attributes.getResponse(), localAdapter,
                    localSessionStore, localContextFactory, localLogoutLogic);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy