All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.yadaframework.security.YadaWrappedSavedRequest Maven / Gradle / Ivy

There is a newer version: 0.7.7.R4
Show newest version
package net.yadaframework.security;

import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.springframework.security.web.savedrequest.SavedRequest;

import jakarta.servlet.http.Cookie;
import net.yadaframework.components.YadaWebUtil;

/**
 * A wrapper for the saved request that allows to add url parameters.
 * Used to detect logins triggered by ajax calls.
 */
public class YadaWrappedSavedRequest implements SavedRequest {
	private static final long serialVersionUID = 1L;

	private SavedRequest savedRequest;
	private YadaWebUtil yadaWebUtil;
	private String overriddenRedirectUrl;

	public YadaWrappedSavedRequest(SavedRequest savedRequest, YadaWebUtil yadaWebUtil) {
		this.savedRequest = savedRequest;
		this.yadaWebUtil = yadaWebUtil;
		this.overriddenRedirectUrl = savedRequest.getRedirectUrl();
	}

	/**
	 * Add a url parameter or change its value if present
	 * @param name the name of the parameter, not urlencoded
	 * @param value the value of the parameter, not urlencoded. Can be null to only have the name with no value in the url
	 */
	public void addOrUpdateUrlParameter(String name, String value) {
		this.overriddenRedirectUrl = yadaWebUtil.addOrUpdateUrlParameter(overriddenRedirectUrl, name, value);
	}

	@Override
	public String getRedirectUrl() {
		return overriddenRedirectUrl;
	}

	@Override
	public List getCookies() {
		return savedRequest.getCookies();
	}

	@Override
	public String getMethod() {
		return savedRequest.getMethod();
	}

	@Override
	public List getHeaderValues(String name) {
		return savedRequest.getHeaderValues(name);
	}

	@Override
	public Collection getHeaderNames() {
		return savedRequest.getHeaderNames();
	}

	@Override
	public List getLocales() {
		return savedRequest.getLocales();
	}

	@Override
	public String[] getParameterValues(String name) {
		return savedRequest.getParameterValues(name);
	}

	@Override
	public Map getParameterMap() {
		return savedRequest.getParameterMap();
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy