package info.bukova.isspst.security;

import info.bukova.isspst.Constants;
import info.bukova.isspst.data.User;

import org.springframework.security.core.Authentication;

/**
 * Vyhodnocuje právo k editaci vlastního záznamu uživatele
 * 
 * @author pepa
 *
 */
public class UserEvaluator implements Evaluator {

	@Override
	public boolean evaluate(Authentication authentication,
			Object targetDomainObject, String permission) {
		if (!(targetDomainObject instanceof User)) {
			return false;
		}
		
		User object = (User)targetDomainObject;
		
		return permission.equals(Constants.PERM_EDIT_OWN) && object.equals(authentication.getPrincipal());
	}

}
