<commit_before>/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.nanos.http;

import foam.core.*;
import foam.nanos.http.ProxyWebAgent;
import foam.nanos.http.WebAgent;
import java.io.PrintWriter;
import foam.nanos.auth.AuthService;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import foam.nanos.session.Session;
import foam.dao.DAO;
import foam.nanos.auth.User;

public class AuthWebAgent
  extends ProxyWebAgent
{
  public AuthWebAgent(WebAgent delegate) {
    setDelegate(delegate);
  }

  public void execute(X x) {
    HttpServletRequest  req  = (HttpServletRequest) x.get(HttpServletRequest.class);
    HttpServletResponse resp = (HttpServletResponse) x.get(HttpServletResponse.class);
    PrintWriter         out  = (PrintWriter) x.get(PrintWriter.class);

    DAO                 sessionDAO = (DAO) x.get("sessionDAO");

    Cookie[] cookies = req.getCookies();
    String sessionId = null;
    if(cookies != null){
      for ( Cookie cookie : cookies ) {
        if (cookie.getName().toString().equals("sessionId")){
          sessionId = cookie.getValue().toString();
          Session session = (Session) sessionDAO.find(sessionId);
          if ( session != null ) {
            getDelegate().execute(x);
          }
        } else {
          templateLogin(x);
        }
      }
    } else {
      templateLogin(x);<commit_msg>session expiry check<commit_after>/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.nanos.http;

import foam.core.*;
import foam.nanos.http.ProxyWebAgent;
import foam.nanos.http.WebAgent;
import java.io.PrintWriter;
import foam.nanos.auth.AuthService;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import foam.nanos.session.Session;
import foam.dao.DAO;
import foam.nanos.auth.User;

public class AuthWebAgent
  extends ProxyWebAgent
{
  public AuthWebAgent(WebAgent delegate) {
    setDelegate(delegate);
  }

  public void execute(X x) {
    HttpServletRequest  req  = (HttpServletRequest) x.get(HttpServletRequest.class);
    HttpServletResponse resp = (HttpServletResponse) x.get(HttpServletResponse.class);
    PrintWriter         out  = (PrintWriter) x.get(PrintWriter.class);

    DAO                 sessionDAO = (DAO) x.get("sessionDAO");

    Cookie[] cookies = req.getCookies();
    String sessionId = null;
    if( cookies != null ){
      for ( Cookie cookie : cookies ) {
        if ( cookie.getName().toString().equals("sessionId" )){
          sessionId = cookie.getValue().toString();
          Session session = (Session) sessionDAO.find(sessionId);
          Date expiry = session.getExpiry();
          Date dateNow = new Date();
          if ( session != null && expiry.before(dateNow) ) {
            getDelegate().execute(x);
          } else {
            templateLogin(x);
          }
        } else {
          templateLogin(x);
        }
      }
    } else {
      templateLogin(x);
{'fraction_non_alphanumeric': 0.12090994079152384, 'fraction_numerical': 0.00373948270489249, 'mean_word_length': 2.9925373134328357, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5309254', 'n_tokens_mistral': 950, 'n_tokens_neox': 944, 'n_words': 198}