Search in sources :

Example 1 with Session

use of io.vertx.reactivex.ext.web.Session in project api-framework by vinscom.

the class LoadUserFromSessionRouteBuillder method handle.

public void handle(RoutingContext pRoutingContext) {
    Session session = pRoutingContext.session();
    if (session != null && getOAuth2Auth() != null) {
        JsonObject principal = session.get(FrameworkConstants.Session.PRINCIPAL);
        if (principal != null) {
            OAuth2AuthProviderImpl provider = (OAuth2AuthProviderImpl) getOAuth2Auth().getDelegate();
            try {
                OAuth2TokenImpl token = new OAuth2TokenImpl(provider, principal);
                pRoutingContext.setUser(new AccessToken(token));
            } catch (RuntimeException e) {
                getLog().error(e);
                pRoutingContext.fail(401);
                return;
            }
        }
    }
    pRoutingContext.next();
}
Also used : AccessToken(io.vertx.reactivex.ext.auth.oauth2.AccessToken) JsonObject(io.vertx.core.json.JsonObject) OAuth2AuthProviderImpl(io.vertx.ext.auth.oauth2.impl.OAuth2AuthProviderImpl) OAuth2TokenImpl(io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl) Session(io.vertx.reactivex.ext.web.Session)

Example 2 with Session

use of io.vertx.reactivex.ext.web.Session in project api-framework by vinscom.

the class OIDCCallbackRouteBuilder method handle.

public void handle(RoutingContext pRoutingCoutext) {
    JsonObject tokenConfig = getTokenConfig(pRoutingCoutext);
    getOAuth2Auth().getDelegate().authenticate(tokenConfig, (response) -> {
        if (response.succeeded()) {
            Session session = pRoutingCoutext.session().regenerateId();
            session.put(FrameworkConstants.Session.PRINCIPAL, response.result().principal());
            getLog().debug(() -> "Success URL:" + getSuccessURL(pRoutingCoutext));
            pRoutingCoutext.response().putHeader(HttpHeaders.LOCATION, getSuccessURL(pRoutingCoutext)).setStatusCode(302).end();
        } else {
            getLog().error(response.cause());
            getLog().debug(() -> "Fail URL:" + getFailURL(pRoutingCoutext));
            pRoutingCoutext.response().putHeader(HttpHeaders.LOCATION, getFailURL(pRoutingCoutext)).setStatusCode(302).end();
        }
    });
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Session(io.vertx.reactivex.ext.web.Session)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)2 Session (io.vertx.reactivex.ext.web.Session)2 OAuth2AuthProviderImpl (io.vertx.ext.auth.oauth2.impl.OAuth2AuthProviderImpl)1 OAuth2TokenImpl (io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl)1 AccessToken (io.vertx.reactivex.ext.auth.oauth2.AccessToken)1