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

restx.security.DefaultCookieSigner Maven / Gradle / Ivy

There is a newer version: 1.2.0-rc2
Show newest version
package restx.security;

import javax.inject.Named;

import com.google.common.base.Optional;

import restx.common.Crypto;
import restx.factory.Component;

/**
 * Default cookie signer, using HMAC-SHA1 algorithm to sign the cookie.
 *
 * @author apeyrard
 */
@Component
@Named(RestxSessionCookieFilter.COOKIE_SIGNER_NAME)
public class DefaultCookieSigner implements Signer {
	private final SignatureKey signatureKey;

	public DefaultCookieSigner(Optional signatureKey) {
		this.signatureKey = signatureKey.or(SignatureKey.DEFAULT);
	}

	@Override
	public String sign(String cookie) {
		return Crypto.sign(cookie, signatureKey.getKey());
	}

	@Override
	public boolean verify(String cookie, String signedCookie) {
		return sign(cookie).equals(signedCookie);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy