public static Map<String, Serializable> initAndDeserializeToken(Req req) { String token = req.cookie(TOKEN, null); if (U.isEmpty(token)) { token = req.data(TOKEN, null); } return Tokens.deserialize(token); }
public static void saveTokenBeforeRenderingHeaders(Req req, Map<String, Serializable> tokenData) { String token = Tokens.serialize(tokenData); setResponseTokenCookie(req.response(), token); }
public static TokenAuthData getAuth(Req req) { TokenAuthData auth = req.hasToken() ? Tokens.getAuth(req.token()) : null; // check if the route is outside of scope if (auth != null && U.notEmpty(auth.scope) && !auth.scope.contains(req.verb() + " " + req.path())) auth = null; return auth; }
public static TokenAuthData getAuth(Map<String, ? extends Serializable> token) { TokenAuthData data = new TokenAuthData(); data.user = (String) token.get(_USER); data.scope = scope((String) token.get(_SCOPE)); data.expires = (Long) token.get(_EXPIRES); if (data.expires == null || data.expires > U.time()) { return data; } else { return null; // expired } }
public static String serialize(Map<String, ? extends Serializable> token) { if (U.notEmpty(token)) { byte[] tokenBytes = serializeToken(token); byte[] tokenEncrypted = Crypto.encrypt(tokenBytes); return Str.toWebSafeBase64(tokenEncrypted); } else { return ""; } }
@Override public AuthResponse execute(Req req, Resp resp) { AuthResponse auth = new AuthResponse(); String username = req.data("username"); String password = req.data("password"); auth.success = resp.login(username, password); auth.token = auth.success ? Tokens.serialize(req.token()) : ""; return auth; }
public static String convertTokenToUser(String token) { return Tokens.deserialize(token).get(Tokens._USER).toString(); } }
public static TokenAuthData getAuth(Req req) { TokenAuthData auth = req.hasToken() ? Tokens.getAuth(req.token()) : null; // check if the route is outside of scope if (auth != null && U.notEmpty(auth.scope) && !auth.scope.contains(req.verb() + " " + req.path())) auth = null; return auth; }
public static void saveTokenBeforeRenderingHeaders(Req req, Map<String, Serializable> tokenData) { String token = Tokens.serialize(tokenData); setResponseTokenCookie(req.response(), token); }
public static Map<String, Serializable> initAndDeserializeToken(Req req) { String token = req.cookie(TOKEN, null); if (U.isEmpty(token)) { token = req.data(TOKEN, null); } return Tokens.deserialize(token); }
@Override public AuthResponse execute(Req req, Resp resp) throws Exception { AuthResponse auth = new AuthResponse(); String username = req.data("username"); String password = req.data("password"); auth.success = resp.login(username, password); auth.token = auth.success ? Tokens.serialize(req.token()) : ""; return auth; }