<commit_before>/*******************************************************************************
 * Copyright (c) 2015 IBH SYSTEMS GmbH.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBH SYSTEMS GmbH - initial API and implementation
 *******************************************************************************/
package org.eclipse.packagedrone.sec.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.eclipse.packagedrone.sec.UserInformation;
import org.eclipse.packagedrone.sec.service.SecurityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SecurityFilter implements Filter
{
    private final static Logger logger = LoggerFactory.getLogger ( SecurityFilter.class );

    protected static final String ATTR_USER_INFORMATION = SecurityFilter.class.getName () + ".userInformation";

    protected static final String ATTR_USER_RELOAD = SecurityFilter.class.getName () + ".reload";

    public static final String ATTR_REMEMBER_ME = SecurityFilter.class.getName () + ".rememberMe";

    public static final String COOKIE_REMEMBER_ME = "rememberMe";

    public static final String COOKIE_EMAIL = "email";

    private SecurityService service;

    public void setService ( final SecurityService service )
    {
        this.service = service;
    }

    public void unsetService ( final SecurityService service )
    {
        this.service = null;
    }

    @Override
    public void init ( final FilterConfig filterConfig ) throws ServletException
    {
    }

    @Override
    public void destroy ()
    {
    }

    @Override
    public void doFilter ( final ServletRequest request, final ServletResponse response, final FilterChain filterChain ) throws IOException, ServletException
    {
        logger.trace ( "doFilter[{}] - {}", this.service != null, request );

        if ( this.service != null && request instanceof HttpServletRequest && response instanceof HttpServletResponse )
        {
            logger.trace ( "Injecting request wrapper" );
            processFilter ( (HttpServletRequest)request, (HttpServletResponse)response, filterChain );
        }
        else
        {
            // just pretend we are not here, so we also won't inject any user principals
            filterChain.doFilter ( request, response );
        }
    }

    protected void processFilter ( final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain ) throws IOException, ServletException
    {
        logger.trace ( "Processing request: {}", request );

        final HttpSession session = request.getSession ( false );

        if ( session != null )
        {
            // always reload details

            markReloadDetails ( session );

            // try to log on

            tryRememberMe ( request, response, session );

        }
<commit_msg>we need to force a session<commit_after>/*******************************************************************************
 * Copyright (c) 2015 IBH SYSTEMS GmbH.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBH SYSTEMS GmbH - initial API and implementation
 *******************************************************************************/
package org.eclipse.packagedrone.sec.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.eclipse.packagedrone.sec.UserInformation;
import org.eclipse.packagedrone.sec.service.SecurityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SecurityFilter implements Filter
{
    private final static Logger logger = LoggerFactory.getLogger ( SecurityFilter.class );

    protected static final String ATTR_USER_INFORMATION = SecurityFilter.class.getName () + ".userInformation";

    protected static final String ATTR_USER_RELOAD = SecurityFilter.class.getName () + ".reload";

    public static final String ATTR_REMEMBER_ME = SecurityFilter.class.getName () + ".rememberMe";

    public static final String COOKIE_REMEMBER_ME = "rememberMe";

    public static final String COOKIE_EMAIL = "email";

    private SecurityService service;

    public void setService ( final SecurityService service )
    {
        this.service = service;
    }

    public void unsetService ( final SecurityService service )
    {
        this.service = null;
    }

    @Override
    public void init ( final FilterConfig filterConfig ) throws ServletException
    {
    }

    @Override
    public void destroy ()
    {
    }

    @Override
    public void doFilter ( final ServletRequest request, final ServletResponse response, final FilterChain filterChain ) throws IOException, ServletException
    {
        logger.trace ( "doFilter[{}] - {}", this.service != null, request );

        if ( this.service != null && request instanceof HttpServletRequest && response instanceof HttpServletResponse )
        {
            logger.trace ( "Injecting request wrapper" );
            processFilter ( (HttpServletRequest)request, (HttpServletResponse)response, filterChain );
        }
        else
        {
            // just pretend we are not here, so we also won't inject any user principals
            filterChain.doFilter ( request, response );
        }
    }

    protected void processFilter ( final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain ) throws IOException, ServletException
    {
        logger.trace ( "Processing request: {}", request );

        final HttpSession session = request.getSession ();

        if ( session != null )
        {
            // always reload details

            markReloadDetails ( session );

            // try to log on

            tryRememberMe ( request, response, session );

        }

{'fraction_non_alphanumeric': 0.12195121951219512, 'fraction_numerical': 0.0029036004645760743, 'mean_word_length': 3.4387886597938144, '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': '5401609', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1625, 'n_words': 504}