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

com.github.kaizen4j.shiro.csrf.DefaultCsrfToken Maven / Gradle / Ivy

package com.github.kaizen4j.shiro.csrf;

import org.apache.shiro.util.Assert;

/**
 * A CSRF token that is used to protect against CSRF attacks.
 *
 * @author liuguowen
 */
@SuppressWarnings("serial")
public class DefaultCsrfToken implements CsrfToken {

    private final String token;

    private final String parameterName;

    private final String headerName;

    /**
     * Creates a new instance
     *
     * @param headerName the HTTP header name to use
     * @param parameterName the HTTP parameter name to use
     * @param token the value of the token (i.e. expected value of the HTTP parameter of parameterName).
     */
    public DefaultCsrfToken(String headerName, String parameterName, String token) {
        Assert.hasLength(headerName, "headerName cannot be null or empty");
        Assert.hasLength(parameterName, "parameterName cannot be null or empty");
        Assert.hasLength(token, "token cannot be null or empty");
        this.headerName = headerName;
        this.parameterName = parameterName;
        this.token = token;
    }

    @Override
    public String getHeaderName() {
        return this.headerName;
    }

    @Override
    public String getParameterName() {
        return this.parameterName;
    }

    @Override
    public String getToken() {
        return this.token;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy