org.pac4j.core.util.FindBest Java Examples

The following examples show how to use org.pac4j.core.util.FindBest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogoutHandler.java    From vertx-pac4j with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(final RoutingContext routingContext) {

    final LogoutLogic<Void, VertxWebContext> bestLogic = FindBest.logoutLogic(null, config, DefaultLogoutLogic.INSTANCE);
    final HttpActionAdapter<Void, VertxWebContext> bestAdapter = FindBest.httpActionAdapter(null, config, VertxHttpActionAdapter.INSTANCE);

    final VertxWebContext webContext = new VertxWebContext(routingContext, sessionStore);

    vertx.executeBlocking(future -> {
                bestLogic.perform(webContext, config, bestAdapter, defaultUrl, logoutUrlPattern, localLogout, destroySession, centralLogout);
                future.complete(null);
            },
            false,
            asyncResult -> {
                // If we succeeded we're all good here, the job is done either through approving, or redirect, or
                // forbidding
                // However, if an error occurred we need to handle this here
                if (asyncResult.failed()) {
                    routingContext.fail(new TechnicalException(asyncResult.cause()));
                }
            });

}
 
Example #2
Source File: CallbackHandler.java    From vertx-pac4j with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(RoutingContext event) {

    final CallbackLogic<Void, VertxWebContext> bestLogic = FindBest.callbackLogic(null, config, DefaultCallbackLogic.INSTANCE);
    final HttpActionAdapter<Void, VertxWebContext> 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, config, bestAdapter, defaultUrl, saveInSession, multiProfile, renewSession, defaultClient);
        future.complete(null);
    },
    false,
    asyncResult -> {
        // If we succeeded we're all good here, the job is done either through approving, or redirect, or
        // forbidding
        // However, if an error occurred we need to handle this here
        if (asyncResult.failed()) {
            event.fail(new TechnicalException(asyncResult.cause()));
        }
    });

}
 
Example #3
Source File: SecurityFilter.java    From jee-pac4j with Apache License 2.0 6 votes vote down vote up
@Override
protected final void internalFilter(final HttpServletRequest request, final HttpServletResponse response,
                                    final FilterChain filterChain) throws IOException, ServletException {

    final Config config = getSharedConfig();

    final SessionStore<JEEContext> bestSessionStore = FindBest.sessionStore(null, config, JEESessionStore.INSTANCE);
    final HttpActionAdapter<Object, JEEContext> bestAdapter = FindBest.httpActionAdapter(null, config, JEEHttpActionAdapter.INSTANCE);
    final SecurityLogic<Object, JEEContext> bestLogic = FindBest.securityLogic(securityLogic, config, DefaultSecurityLogic.INSTANCE);

    final JEEContext context = new JEEContext(request, response, bestSessionStore);
    bestLogic.perform(context, config, (ctx, profiles, parameters) -> {
        // if no profiles are loaded, pac4j is not concerned with this request
        filterChain.doFilter(profiles.isEmpty() ? request : new Pac4JHttpServletRequestWrapper(request, profiles), response);
        return null;
    }, bestAdapter, clients, authorizers, matchers, multiProfile);
}
 
Example #4
Source File: SecurityInterceptor.java    From spring-webmvc-pac4j with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {

    final SessionStore<JEEContext> bestSessionStore = FindBest.sessionStore(null, config, JEESessionStore.INSTANCE);
    final HttpActionAdapter<Boolean, JEEContext> bestAdapter = FindBest.httpActionAdapter(httpActionAdapter, config, JEEHttpActionAdapter.INSTANCE);
    final SecurityLogic<Boolean, JEEContext> bestLogic = FindBest.securityLogic(securityLogic, config, DefaultSecurityLogic.INSTANCE);

    final JEEContext context = (JEEContext) FindBest.webContextFactory(null, config, JEEContextFactory.INSTANCE)
            .newContext(request, response, bestSessionStore);
    final Object result = bestLogic.perform(context, config, (ctx, profiles, parameters) -> true, bestAdapter, clients, authorizers, matchers, multiProfile);
    if (result == null) {
        return false;
    }
    return Boolean.parseBoolean(result.toString());
}
 
Example #5
Source File: LogoutController.java    From spring-webmvc-pac4j with Apache License 2.0 5 votes vote down vote up
@RequestMapping("${pac4j.logout.path:/logout}")
public void logout(final HttpServletRequest request, final HttpServletResponse response) {

    final SessionStore<JEEContext> bestSessionStore = FindBest.sessionStore(null, config, JEESessionStore.INSTANCE);
    final HttpActionAdapter<Object, JEEContext> bestAdapter = FindBest.httpActionAdapter(null, config, JEEHttpActionAdapter.INSTANCE);
    final LogoutLogic<Object, JEEContext> bestLogic = FindBest.logoutLogic(logoutLogic, config, DefaultLogoutLogic.INSTANCE);

    final JEEContext context = (JEEContext) FindBest.webContextFactory(null, config, JEEContextFactory.INSTANCE)
            .newContext(request, response, bestSessionStore);
    bestLogic.perform(context, config, bestAdapter, this.defaultUrl, this.logoutUrlPattern,
            this.localLogout, this.destroySession, this.centralLogout);
}
 
Example #6
Source File: CallbackController.java    From spring-webmvc-pac4j with Apache License 2.0 5 votes vote down vote up
@RequestMapping("${pac4j.callback.path:/callback}")
public void callback(final HttpServletRequest request, final HttpServletResponse response) {

    final SessionStore<JEEContext> bestSessionStore = FindBest.sessionStore(null, config, JEESessionStore.INSTANCE);
    final HttpActionAdapter<Object, JEEContext> bestAdapter = FindBest.httpActionAdapter(null, config, JEEHttpActionAdapter.INSTANCE);
    final CallbackLogic<Object, JEEContext> bestLogic = FindBest.callbackLogic(callbackLogic, config, DefaultCallbackLogic.INSTANCE);

    final JEEContext context = (JEEContext) FindBest.webContextFactory(null, config, JEEContextFactory.INSTANCE)
            .newContext(request, response, bestSessionStore);
    bestLogic.perform(context, config, bestAdapter, this.defaultUrl, this.saveInSession, this.multiProfile,
            this.renewSession, this.defaultClient);
}
 
Example #7
Source File: SecurityHandler.java    From vertx-pac4j with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(final RoutingContext routingContext) {

    final SecurityLogic<Void, VertxWebContext> bestLogic = FindBest.securityLogic(null, config, DefaultSecurityLogic.INSTANCE);
    final HttpActionAdapter<Void, VertxWebContext> bestAdapter = FindBest.httpActionAdapter(null, config, VertxHttpActionAdapter.INSTANCE);

    final VertxWebContext webContext = new VertxWebContext(routingContext, sessionStore);

    vertx.executeBlocking(future -> bestLogic.perform(webContext, config,
        (ctx, 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,
        multiProfile),
    asyncResult -> {
        // If we succeeded we're all good here, the job is done either through approving, or redirect, or
        // forbidding
        // 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();
        }
    });

}
 
Example #8
Source File: Pac4jProducer.java    From jee-pac4j with Apache License 2.0 5 votes vote down vote up
/**
 * Factory method which produces a pac4j web context.
 *
 * @param httpServletRequest the http servlet request to be used for building the web context
 * @param httpServletResponse the http servlet response to be used for building the web context
 * @return a web context associated with the current servlet request
 */
@Produces
JEEContext getWebContext(final HttpServletRequest httpServletRequest,
                         final HttpServletResponse httpServletResponse) {
    logger.trace("Producing a pac4j web context...");
    final SessionStore<JEEContext> bestSessionStore = FindBest.sessionStore(null, Config.INSTANCE, JEESessionStore.INSTANCE);
    JEEContext jEEContext = new JEEContext(
            httpServletRequest,
            httpServletResponse,
            bestSessionStore
    );
    logger.trace("Returning a pac4j web context.");
    return jEEContext;
}
 
Example #9
Source File: LogoutFilter.java    From jee-pac4j with Apache License 2.0 5 votes vote down vote up
@Override
protected void internalFilter(final HttpServletRequest request, final HttpServletResponse response,
                                       final FilterChain chain) throws IOException, ServletException {

    final Config config = getSharedConfig();

    final SessionStore<JEEContext> bestSessionStore = FindBest.sessionStore(null, config, JEESessionStore.INSTANCE);
    final HttpActionAdapter<Object, JEEContext> bestAdapter = FindBest.httpActionAdapter(null, config, JEEHttpActionAdapter.INSTANCE);
    final LogoutLogic<Object, JEEContext> bestLogic = FindBest.logoutLogic(logoutLogic, config, DefaultLogoutLogic.INSTANCE);

    final JEEContext context = new JEEContext(request, response, bestSessionStore);
    bestLogic.perform(context, config, bestAdapter, this.defaultUrl, this.logoutUrlPattern, this.localLogout, this.destroySession, this.centralLogout);
}
 
Example #10
Source File: CallbackFilter.java    From jee-pac4j with Apache License 2.0 5 votes vote down vote up
@Override
protected void internalFilter(final HttpServletRequest request, final HttpServletResponse response,
                                       final FilterChain chain) throws IOException, ServletException {

    final Config config = getSharedConfig();

    final SessionStore<JEEContext> bestSessionStore = FindBest.sessionStore(null, config, JEESessionStore.INSTANCE);
    final HttpActionAdapter<Object, JEEContext> bestAdapter = FindBest.httpActionAdapter(null, config, JEEHttpActionAdapter.INSTANCE);
    final CallbackLogic<Object, JEEContext> bestLogic = FindBest.callbackLogic(callbackLogic, config, DefaultCallbackLogic.INSTANCE);

    final JEEContext context = new JEEContext(request, response, bestSessionStore);
    bestLogic.perform(context, config, bestAdapter, this.defaultUrl, this.saveInSession, this.multiProfile, this.renewSession, this.defaultClient);
}
 
Example #11
Source File: ComponentConfig.java    From spring-webmvc-pac4j with Apache License 2.0 4 votes vote down vote up
protected SessionStore<JEEContext> getSessionStore() {
    return FindBest.sessionStore(sessionStore, config, JEESessionStore.INSTANCE);
}