Search in sources :

Example 1 with HttpActionAdapter

use of org.pac4j.core.http.adapter.HttpActionAdapter in project buji-pac4j by bujiio.

the class SecurityFilter method doFilter.

@Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
    final SessionStore bestSessionStore = FindBest.sessionStore(null, config, ShiroSessionStore.INSTANCE);
    final HttpActionAdapter bestAdapter = FindBest.httpActionAdapter(null, config, JEEHttpActionAdapter.INSTANCE);
    final SecurityLogic bestLogic = FindBest.securityLogic(securityLogic, config, DefaultSecurityLogic.INSTANCE);
    final WebContext context = FindBest.webContextFactory(null, config, JEEContextFactory.INSTANCE).newContext(servletRequest, servletResponse);
    bestLogic.perform(context, bestSessionStore, config, (ctx, session, profiles, parameters) -> {
        filterChain.doFilter(servletRequest, servletResponse);
        return null;
    }, bestAdapter, clients, authorizers, matchers);
}
Also used : SessionStore(org.pac4j.core.context.session.SessionStore) ShiroSessionStore(io.buji.pac4j.context.ShiroSessionStore) WebContext(org.pac4j.core.context.WebContext) DefaultSecurityLogic(org.pac4j.core.engine.DefaultSecurityLogic) SecurityLogic(org.pac4j.core.engine.SecurityLogic) HttpActionAdapter(org.pac4j.core.http.adapter.HttpActionAdapter) JEEHttpActionAdapter(org.pac4j.core.http.adapter.JEEHttpActionAdapter)

Example 2 with HttpActionAdapter

use of org.pac4j.core.http.adapter.HttpActionAdapter in project buji-pac4j by bujiio.

the class CallbackFilter method doFilter.

@Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
    final SessionStore bestSessionStore = FindBest.sessionStore(null, config, ShiroSessionStore.INSTANCE);
    final HttpActionAdapter bestAdapter = FindBest.httpActionAdapter(httpActionAdapter, config, JEEHttpActionAdapter.INSTANCE);
    final CallbackLogic bestLogic = FindBest.callbackLogic(callbackLogic, config, DefaultCallbackLogic.INSTANCE);
    final WebContext context = FindBest.webContextFactory(null, config, JEEContextFactory.INSTANCE).newContext(servletRequest, servletResponse);
    bestLogic.perform(context, bestSessionStore, config, bestAdapter, defaultUrl, false, defaultClient);
}
Also used : SessionStore(org.pac4j.core.context.session.SessionStore) ShiroSessionStore(io.buji.pac4j.context.ShiroSessionStore) DefaultCallbackLogic(org.pac4j.core.engine.DefaultCallbackLogic) CallbackLogic(org.pac4j.core.engine.CallbackLogic) WebContext(org.pac4j.core.context.WebContext) HttpActionAdapter(org.pac4j.core.http.adapter.HttpActionAdapter) JEEHttpActionAdapter(org.pac4j.core.http.adapter.JEEHttpActionAdapter)

Example 3 with HttpActionAdapter

use of org.pac4j.core.http.adapter.HttpActionAdapter in project vertx-pac4j by pac4j.

the class CallbackHandler method handle.

@Override
public void handle(RoutingContext event) {
    final CallbackLogic bestLogic = FindBest.callbackLogic(null, config, DefaultCallbackLogic.INSTANCE);
    final HttpActionAdapter bestAdapter = FindBest.httpActionAdapter(null, config, VertxHttpActionAdapter.INSTANCE);
    // Can we complete the authentication process here?
    final VertxWebContext webContext = new VertxWebContext(event, sessionStore);
    vertx.executeBlocking(future -> {
        bestLogic.perform(webContext, sessionStore, config, bestAdapter, defaultUrl, renewSession, defaultClient);
        future.complete(null);
    }, false, asyncResult -> {
        // forbidding. However, if an error occurred we need to handle this here
        if (asyncResult.failed()) {
            event.fail(new TechnicalException(asyncResult.cause()));
        }
    });
}
Also used : DefaultCallbackLogic(org.pac4j.core.engine.DefaultCallbackLogic) CallbackLogic(org.pac4j.core.engine.CallbackLogic) TechnicalException(org.pac4j.core.exception.TechnicalException) VertxWebContext(org.pac4j.vertx.VertxWebContext) HttpActionAdapter(org.pac4j.core.http.adapter.HttpActionAdapter) VertxHttpActionAdapter(org.pac4j.vertx.http.VertxHttpActionAdapter)

Example 4 with HttpActionAdapter

use of org.pac4j.core.http.adapter.HttpActionAdapter in project vertx-pac4j by pac4j.

the class LogoutHandler method handle.

@Override
public void handle(final RoutingContext routingContext) {
    final LogoutLogic bestLogic = FindBest.logoutLogic(null, config, DefaultLogoutLogic.INSTANCE);
    final HttpActionAdapter bestAdapter = FindBest.httpActionAdapter(null, config, VertxHttpActionAdapter.INSTANCE);
    final VertxWebContext webContext = new VertxWebContext(routingContext, sessionStore);
    vertx.executeBlocking(future -> {
        bestLogic.perform(webContext, sessionStore, config, bestAdapter, defaultUrl, logoutUrlPattern, localLogout, destroySession, centralLogout);
        future.complete(null);
    }, false, asyncResult -> {
        // However, if an error occurred we need to handle this here
        if (asyncResult.failed()) {
            routingContext.fail(new TechnicalException(asyncResult.cause()));
        }
    });
}
Also used : DefaultLogoutLogic(org.pac4j.core.engine.DefaultLogoutLogic) LogoutLogic(org.pac4j.core.engine.LogoutLogic) TechnicalException(org.pac4j.core.exception.TechnicalException) VertxWebContext(org.pac4j.vertx.VertxWebContext) HttpActionAdapter(org.pac4j.core.http.adapter.HttpActionAdapter) VertxHttpActionAdapter(org.pac4j.vertx.http.VertxHttpActionAdapter)

Example 5 with HttpActionAdapter

use of org.pac4j.core.http.adapter.HttpActionAdapter in project vertx-pac4j by pac4j.

the class SecurityHandler method authenticate.

@Override
public void authenticate(RoutingContext routingContext, Handler<AsyncResult<User>> handler) {
    final SecurityLogic bestLogic = FindBest.securityLogic(null, config, DefaultSecurityLogic.INSTANCE);
    final HttpActionAdapter bestAdapter = FindBest.httpActionAdapter(null, config, VertxHttpActionAdapter.INSTANCE);
    final VertxWebContext webContext = new VertxWebContext(routingContext, sessionStore);
    vertx.executeBlocking(future -> bestLogic.perform(webContext, sessionStore, config, (ctx, store, profiles, parameters) -> {
        // This is what should occur if we are authenticated and authorized to view the requested
        // resource
        future.complete();
        return null;
    }, bestAdapter, clientNames, authorizerName, matcherName), asyncResult -> {
        // However, if an error occurred we need to handle this here
        if (asyncResult.failed()) {
            unexpectedFailure(routingContext, asyncResult.cause());
        } else {
            LOG.info("Authorised to view resource " + routingContext.request().path());
            routingContext.next();
        }
    });
}
Also used : VertxWebContext(org.pac4j.vertx.VertxWebContext) Pac4jAuthProvider(org.pac4j.vertx.auth.Pac4jAuthProvider) AuthenticationHandlerImpl(io.vertx.ext.web.handler.impl.AuthenticationHandlerImpl) VertxProfileManager(org.pac4j.vertx.VertxProfileManager) Vertx(io.vertx.core.Vertx) DefaultSecurityLogic(org.pac4j.core.engine.DefaultSecurityLogic) RoutingContext(io.vertx.ext.web.RoutingContext) SessionStore(org.pac4j.core.context.session.SessionStore) LoggerFactory(io.vertx.core.logging.LoggerFactory) FindBest(org.pac4j.core.util.FindBest) HttpActionAdapter(org.pac4j.core.http.adapter.HttpActionAdapter) User(io.vertx.ext.auth.User) SecurityLogic(org.pac4j.core.engine.SecurityLogic) VertxHttpActionAdapter(org.pac4j.vertx.http.VertxHttpActionAdapter) Config(org.pac4j.core.config.Config) CommonHelper(org.pac4j.core.util.CommonHelper) AsyncResult(io.vertx.core.AsyncResult) TechnicalException(org.pac4j.core.exception.TechnicalException) Handler(io.vertx.core.Handler) Logger(io.vertx.core.logging.Logger) VertxSessionStore(org.pac4j.vertx.context.session.VertxSessionStore) DefaultSecurityLogic(org.pac4j.core.engine.DefaultSecurityLogic) SecurityLogic(org.pac4j.core.engine.SecurityLogic) VertxWebContext(org.pac4j.vertx.VertxWebContext) HttpActionAdapter(org.pac4j.core.http.adapter.HttpActionAdapter) VertxHttpActionAdapter(org.pac4j.vertx.http.VertxHttpActionAdapter)

Aggregations

HttpActionAdapter (org.pac4j.core.http.adapter.HttpActionAdapter)22 SessionStore (org.pac4j.core.context.session.SessionStore)15 WebContext (org.pac4j.core.context.WebContext)13 CallbackLogic (org.pac4j.core.engine.CallbackLogic)7 DefaultCallbackLogic (org.pac4j.core.engine.DefaultCallbackLogic)7 JEESessionStore (org.pac4j.jee.context.session.JEESessionStore)7 DefaultLogoutLogic (org.pac4j.core.engine.DefaultLogoutLogic)6 DefaultSecurityLogic (org.pac4j.core.engine.DefaultSecurityLogic)6 LogoutLogic (org.pac4j.core.engine.LogoutLogic)6 SecurityLogic (org.pac4j.core.engine.SecurityLogic)6 JEEHttpActionAdapter (org.pac4j.core.http.adapter.JEEHttpActionAdapter)6 TechnicalException (org.pac4j.core.exception.TechnicalException)5 JEEHttpActionAdapter (org.pac4j.jee.http.adapter.JEEHttpActionAdapter)4 ShiroSessionStore (io.buji.pac4j.context.ShiroSessionStore)3 JEEContext (org.pac4j.core.context.JEEContext)3 JEESessionStore (org.pac4j.core.context.session.JEESessionStore)3 PlayWebContext (org.pac4j.play.PlayWebContext)3 PlayHttpActionAdapter (org.pac4j.play.http.PlayHttpActionAdapter)3 VertxWebContext (org.pac4j.vertx.VertxWebContext)3 VertxHttpActionAdapter (org.pac4j.vertx.http.VertxHttpActionAdapter)3