org.jooby.Request.ifSession()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(446)

本文整理了Java中org.jooby.Request.ifSession方法的一些代码示例,展示了Request.ifSession的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.ifSession方法的具体详情如下:
包路径:org.jooby.Request
类名称:Request
方法名:ifSession

Request.ifSession介绍

暂无

代码示例

代码示例来源:origin: jooby-project/jooby

@Override
public Optional<Session> ifSession() {
 return req.ifSession();
}

代码示例来源:origin: jooby-project/jooby

@Override public boolean destroySession(WebContext ctx) {
 req.ifSession().ifPresent(Session::destroy);
 return true;
}

代码示例来源:origin: jooby-project/jooby

@Override public boolean renewSession(WebContext ctx) {
 req.ifSession().ifPresent(Session::renewId);
 return true;
}

代码示例来源:origin: jooby-project/jooby

@Override public Object get(WebContext context, String key) {
 return req.ifSession()
   .map(session -> {
    String value = session.get(key).toOptional().orElse(null);
    return strToObject(value);
   }).orElse(null);
}

代码示例来源:origin: jooby-project/jooby

static Provider profileProvider(AtomicReference<Registry> registry, Class profile,
   Function<Request, UserProfile> unauthenticated) {
  return () -> {
   Request req = registry.get().require(Request.class);
   ProfileManager pm = req.require(ProfileManager.class);
   Object result = pm.getAll(req.ifSession().isPresent()).stream()
     .filter(profile::isInstance)
     .findFirst()
     .orElse(null);
   if (result == null) {
    if (unauthenticated == null) {
     throw new Err(Status.FORBIDDEN, "Not found: " + profile.getSimpleName());
    }
    result = unauthenticated.apply(req);
   }
   return result;
  };
 }
}

代码示例来源:origin: jooby-project/jooby

@Override public void set(WebContext context, String key, Object value) {
 if (value == null) {
  req.ifSession().ifPresent(session -> session.unset(key));
 } else {
  req.session().set(key, objToStr(value));
 }
}

代码示例来源:origin: jooby-project/jooby

@SuppressWarnings("unchecked")
@Override
public void handle(final Request req, final Response rsp) throws Throwable {
 // DON'T create a session for JWT/param/header auth (a.k.a stateless)
 Optional<Session> ifSession = req.ifSession();
 if (ifSession.isPresent()) {
  Session session = ifSession.get();
  Optional<String> profileId = session.unset(Auth.ID).toOptional();
  if (profileId.isPresent()) {
   Optional<CommonProfile> profile = req.require(AuthStore.class).unset(profileId.get());
   log.debug("logout {}", profile);
   session.destroy();
  }
 } else {
  log.debug("nothing to logout from session");
 }
 String redirectTo = req.<String> ifGet("auth.logout.redirectTo").orElse(this.redirectTo);
 rsp.redirect(redirectTo);
}

代码示例来源:origin: jooby-project/jooby

private Route.After saveCookie() {
 return (req, rsp, result) -> {
  req.ifSession().ifPresent(session -> {
   Optional<String> value = req.cookie(cookie.name().get()).toOptional();
   Map<String, String> initial = value
     .map(this::attributes)
     .orElse(Collections.emptyMap());
   Map<String, String> attributes = session.attributes();
   // is dirty?
   boolean dirty = !initial.equals(attributes);
   log.debug("session dirty: {}", dirty);
   if (dirty) {
    log.debug("saving session cookie");
    String encoded = Cookie.URL_ENCODER.apply(attributes);
    String signed = Cookie.Signature.sign(encoded, secret);
    rsp.cookie(new Cookie.Definition(cookie).value(signed));
   } else if (timeout > 0) {
    // touch session
    value.ifPresent(raw -> rsp.cookie(new Cookie.Definition(cookie).value(raw)));
   }
  });
  return result;
 };
}

代码示例来源:origin: jooby-project/jooby

@Override public void handle(Request req, Response rsp, Route.Chain chain) throws Throwable {
 try {
  WebContext context = req.require(WebContext.class);
  /** 1: don't save authentication urls: */
  String existingRequestedUrl = (String) context
    .getSessionAttribute(Pac4jConstants.REQUESTED_URL);
  boolean resetRequestedUrl = excludes.stream()
    .filter(it -> !it.endsWith("/**") && req.matches(it))
    .findFirst()
    .isPresent();
  conf.getSecurityLogic()
    .perform(context, conf, new Pac4jGrantAccessAdapter(req, rsp, chain),
      conf.getHttpActionAdapter(), clients, authorizers, matchers, multiProfile);
  /** 2: don't save authentication urls: */
  if (resetRequestedUrl && req.ifSession().isPresent()) {
   //        log.info("ignoring {} by {}", ctx.g, existingRequestedUrl);
   context.setSessionAttribute(Pac4jConstants.REQUESTED_URL, existingRequestedUrl);
  }
 } catch (TechnicalException x) {
  Throwable cause = x.getCause();
  if (!(cause instanceof Err)) {
   // Pac4j wrap everything as TechnicalException, it makes stacktrace ugly, so we rethrow
   // Err
   cause = x;
  }
  throw cause;
 }
 //    }
}

代码示例来源:origin: jooby-project/jooby

req.ifSession().ifPresent(s -> envdata.put("session", dump(s::attributes)));

代码示例来源:origin: org.jooby/jooby

@Override
public Optional<Session> ifSession() {
 return req.ifSession();
}

代码示例来源:origin: org.jooby/jooby-pac4j

@SuppressWarnings("unchecked")
@Override
public void handle(final Request req, final Response rsp) throws Throwable {
 // DON'T create a session for JWT/param/header auth (a.k.a stateless)
 Optional<Session> ifSession = req.ifSession();
 if (ifSession.isPresent()) {
  Session session = ifSession.get();
  Optional<String> profileId = session.unset(Auth.ID).toOptional();
  if (profileId.isPresent()) {
   Optional<CommonProfile> profile = req.require(AuthStore.class).unset(profileId.get());
   log.debug("logout {}", profile);
   session.destroy();
  }
 } else {
  log.debug("nothing to logout from session");
 }
 String redirectTo = req.<String> ifGet("auth.logout.redirectTo").orElse(this.redirectTo);
 rsp.redirect(redirectTo);
}

代码示例来源:origin: org.jooby/jooby

private Route.After saveCookie() {
 return (req, rsp, result) -> {
  req.ifSession().ifPresent(session -> {
   Optional<String> value = req.cookie(cookie.name().get()).toOptional();
   Map<String, String> initial = value
     .map(this::attributes)
     .orElse(Collections.emptyMap());
   Map<String, String> attributes = session.attributes();
   // is dirty?
   boolean dirty = !initial.equals(attributes);
   log.debug("session dirty: {}", dirty);
   if (dirty) {
    log.debug("saving session cookie");
    String encoded = Cookie.URL_ENCODER.apply(attributes);
    String signed = Cookie.Signature.sign(encoded, secret);
    rsp.cookie(new Cookie.Definition(cookie).value(signed));
   } else if (timeout > 0) {
    // touch session
    value.ifPresent(raw -> rsp.cookie(new Cookie.Definition(cookie).value(raw)));
   }
  });
  return result;
 };
}

代码示例来源:origin: org.jooby/jooby-whoops

req.ifSession().ifPresent(s -> envdata.put("session", dump(s::attributes)));

相关文章