<commit_before>package org.cirmmp.spring.security;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/* redirects to url set in url_prior_login attribute */
public class RedirectHandler extends SavedRequestAwareAuthenticationSuccessHandler {
    public RedirectHandler(String defaultTargetUrl) {
        setDefaultTargetUrl(defaultTargetUrl);
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
        HttpSession session = request.getSession();
        if (session != null) {
            String redirectUrl = (String) session.getAttribute("url_prior_login");
            //fix ../staff/index.html is redirected to /admin../staff/index.html
            if (redirectUrl.startsWith("..")) redirectUrl="/"+redirectUrl;
            if (redirectUrl != null) {
                // clean this attribute from session
                session.removeAttribute("url_prior_login");

                getRedirectStrategy().sendRedirect(request, response, redirectUrl);
            } else {
                super.onAuthenticationSuccess(request, response, authentication);
            }
        } else {
            super.onAuthenticationSuccess(request, response, authentication);
        }
    }
}<commit_msg>FIX: NPE when accessing admin page directly - no redirecturl<commit_after>package org.cirmmp.spring.security;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/* redirects to url set in url_prior_login attribute */
public class RedirectHandler extends SavedRequestAwareAuthenticationSuccessHandler {
    public RedirectHandler(String defaultTargetUrl) {
        setDefaultTargetUrl(defaultTargetUrl);
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
        HttpSession session = request.getSession();
        if (session != null) {
            String redirectUrl = (String) session.getAttribute("url_prior_login");
            //fix ../staff/index.html is redirected to /admin../staff/index.html
            if (redirectUrl != null) {
                // clean this attribute from session
                session.removeAttribute("url_prior_login");
                if (redirectUrl.startsWith("..")) redirectUrl="/"+redirectUrl;
                getRedirectStrategy().sendRedirect(request, response, redirectUrl);
            } else {
                super.onAuthenticationSuccess(request, response, authentication);
            }
        } else {
            super.onAuthenticationSuccess(request, response, authentication);
        }
    }
}
{'fraction_non_alphanumeric': 0.08633093525179857, 'fraction_numerical': 0.0, 'mean_word_length': 3.449333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4670911', 'n_tokens_mistral': 778, 'n_tokens_neox': 765, 'n_words': 174}