/**
 * 
 */
package de.bstly.board.security;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices;
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;


/**
 * The Class LocalRememberMeServices.
 */
public class LocalRememberMeServices extends PersistentTokenBasedRememberMeServices {

	/**
	 * Instantiates a new local remember me services.
	 *
	 * @param key the key
	 * @param userDetailsService the user details service
	 * @param tokenRepository the token repository
	 */
	public LocalRememberMeServices(String key, UserDetailsService userDetailsService,
			PersistentTokenRepository tokenRepository) {
		super(key, userDetailsService, tokenRepository);
	}


	/*
	 * @see org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices#rememberMeRequested(javax.servlet.http.HttpServletRequest, java.lang.String)
	 */
	@Override
	protected boolean rememberMeRequested(HttpServletRequest request, String parameter) {
		Object value = request.getAttribute(parameter);
		if (value != null) {
			String paramValue = value.toString();
			if (paramValue.equalsIgnoreCase("true") || paramValue.equalsIgnoreCase("on")
					|| paramValue.equalsIgnoreCase("yes") || paramValue.equals("1")) {
				return true;
			}
		}

		return super.rememberMeRequested(request, parameter);
	}

}
