package eu.freme.broker.security.voter;

import java.util.Collection;

import org.springframework.security.access.AccessDecisionVoter;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.core.Authentication;

import eu.freme.broker.security.database.User;

public class UserAccessDecisionVoter implements AccessDecisionVoter<User> {

	@Override
	public boolean supports(ConfigAttribute attribute) {
		return true;
	}

	@Override
	public boolean supports(Class<?> clazz) {
		return clazz == User.class;
	}

	@Override
	public int vote(Authentication authentication, User object,
			Collection<ConfigAttribute> attributes) {
		
		System.err.println();
		if( authentication.getPrincipal().equals( "anonymousUser" )){
			return ACCESS_DENIED;
		}

		User authenticatedUser = (User) authentication.getDetails();
		if (authenticatedUser.getName() == object.getName()) {
			return ACCESS_GRANTED;
		} else {
			return ACCESS_DENIED;
		}
	}
}

@@ -667,32 +667,8 @@
 %0A%09%09%0A
-%09%09System.err.println();%0A
 %09%09if
@@ -813,15 +813,17 @@
 .get
-Details
+Principal
 ();%0A
@@ -855,20 +855,24 @@
 etName()
- == 
+.equals(
 object.g
@@ -880,16 +880,17 @@
 tName())
+)
  %7B%0A%09%09%09re

fix user decision voter