use of io.gravitee.am.gateway.handler.common.jwt.JWTService in project gravitee-access-management by gravitee-io.
the class AuthenticationFlowHandlerTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
List<AuthenticationFlowStep> steps = new LinkedList<>();
steps.add(new MFAEnrollStep(RedirectHandler.create("/mfa/enroll"), ruleEngine, factorManager));
steps.add(new MFAChallengeStep(RedirectHandler.create("/mfa/challenge"), ruleEngine, factorManager));
AuthenticationFlowChainHandler authenticationFlowChainHandler = new AuthenticationFlowChainHandler(steps);
when(jwtService.encode(any(JWT.class), (CertificateProvider) eq(null))).thenReturn(Single.just("token"));
Factor factor = new Factor();
factor.setFactorType(FactorType.SMS);
when(factorManager.getFactor(anyString())).thenReturn(factor);
router.route("/login").order(Integer.MIN_VALUE).handler(new CookieSessionHandler(jwtService, certificateManager, userService, "am-cookie", 30 * 60 * 60));
router.route("/login").handler(authenticationFlowChainHandler).handler(rc -> rc.response().setStatusCode(200).end()).failureHandler(new ErrorHandler());
}
use of io.gravitee.am.gateway.handler.common.jwt.JWTService in project gravitee-access-management by gravitee-io.
the class CookieSessionHandler method handle.
@Override
public void handle(RoutingContext context) {
if (logger.isDebugEnabled()) {
String uri = context.request().absoluteURI();
if (!uri.startsWith("https:")) {
logger.debug("Using session cookies without https could make you susceptible to session hijacking: " + uri);
}
}
Cookie sessionCookie = context.getCookie(cookieName);
CookieSession session = new CookieSession(jwtService, certificateManager.defaultCertificateProvider(), timeout);
registerSession(context, session);
Single<CookieSession> sessionObs = Single.just(session);
if (sessionCookie != null) {
sessionObs = session.setValue(sessionCookie.getValue()).flatMap(currentSession -> {
String userId = currentSession.get(USER_ID_KEY);
if (!StringUtils.isEmpty(userId)) {
// Load the user and put it back in the context.
return userService.findById(userId).doOnSuccess(user -> context.getDelegate().setUser(new User(user))).flatMap(user -> userService.enhance(user).toMaybe()).map(user -> currentSession).switchIfEmpty(cleanupSession(currentSession)).onErrorResumeNext(cleanupSession(currentSession));
} else {
return Single.just(currentSession);
}
});
}
// Need to wait the session to be ready before invoking next.
sessionObs.doOnError(t -> logger.warn("Unable to restore the session", t)).doFinally(context::next).subscribe();
}
Aggregations