// Path: app/controllers/deadbolt/RestrictedResourcesHandler.java
// public interface RestrictedResourcesHandler
// {
//     /**
//      * Check the access of someone, typically the current user, for the named resource.
//      *
//      * <ul>
//      * <li>If {@link AccessResult#NOT_SPECIFIED} is returned and
//      * {@link controllers.deadbolt.RestrictedResource#staticFallback()} is false, access is denied.</li>
//      * <li>If {@link AccessResult#NOT_SPECIFIED} is returned and
//      * {@link controllers.deadbolt.RestrictedResource#staticFallback()} is true, any further Restrict or
//      * Restrictions annotations are processed.  Note that if no Restrict or Restrictions annotations are present,
//      * access will be allowed.</li>
//      * </ul>
//      *
//      * @param resourceNames the names of the resource
//      * @param resourceParameters additional information on the resource
//      * @return {@link AccessResult#ALLOWED} if access is permitted.  {@link AccessResult#DENIED} if access is denied.
//      * {@link AccessResult#NOT_SPECIFIED} if access is not specified.
//      */
//     AccessResult checkAccess(List<String> resourceNames,
//                              Map<String, String> resourceParameters);
// }
// 
// Path: samples-and-tests/acl/app/model/AccessControlPreference.java
// @Entity
// public class AccessControlPreference extends Model
// {
//     public enum AccessChain { FRIENDS, ANYONE };
// 
//     @Enumerated(EnumType.STRING)
//     public AccessChain friendVisibility = AccessChain.ANYONE;
// 
//     @Enumerated(EnumType.STRING)
//     public AccessChain statusVisibility = AccessChain.ANYONE;
// 
//     @Enumerated(EnumType.STRING)
//     public AccessChain photoVisibility = AccessChain.ANYONE;
// }
// 
// Path: app/models/deadbolt/AccessResult.java
// public enum AccessResult
// {
//     ALLOWED,
//     DENIED,
//     NOT_SPECIFIED
// }
// 
// Path: samples-and-tests/acl/app/security/AccessChainHandler.java
// public abstract class AccessChainHandler implements RestrictedResourcesHandler
// {
//     public AccessResult checkAccess(List<String> resourceNames,
//                                     Map<String, String> resourceParameters)
//     {
//         String currentUserName = AclController.getCurrentUserName();
//         Http.Request request = Http.Request.current();
//         String targetUserName = request.params.get("targetUserName");
// 
//         AccessResult accessResult = AccessResult.DENIED;
//         if (targetUserName == null || currentUserName.equals(targetUserName))
//         {
//             // current user is viewing own information
//             accessResult = AccessResult.ALLOWED;
//         }
//         else
//         {
//             AclUser targetUser = AclUser.getByUserName(targetUserName);
// 
//             switch (getAccessChain(targetUser.accessControlPreference))
//             {
//                 case FRIENDS:
//                     AclUser currentUser = AclUser.getByUserName(currentUserName);
//                     accessResult = targetUser.isFriend(currentUser) ? AccessResult.ALLOWED : AccessResult.DENIED;
//                     break;
//                 case ANYONE:
//                     accessResult = AccessResult.ALLOWED;
//                     break;
//             }
//         }
// 
//         return accessResult;
//     }
// 
//     public abstract AccessControlPreference.AccessChain getAccessChain(AccessControlPreference preference);
// }


import controllers.deadbolt.RestrictedResourcesHandler;
import model.AccessControlPreference;
import models.deadbolt.AccessResult;
import security.AccessChainHandler;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
package controllers;



/**
 * @author Steve Chaloner (steve@objectify.be)
 */
public class AclRestrictedResourcesHandler implements RestrictedResourcesHandler
{
    private static Map<String, RestrictedResourcesHandler> HANDLERS = new HashMap<String, RestrictedResourcesHandler>();

    static
    {
        HANDLERS.put("friends",
// Path: app/controllers/deadbolt/RestrictedResourcesHandler.java
// public interface RestrictedResourcesHandler
// {
//     /**
//      * Check the access of someone, typically the current user, for the named resource.
//      *
//      * <ul>
//      * <li>If {@link AccessResult#NOT_SPECIFIED} is returned and
//      * {@link controllers.deadbolt.RestrictedResource#staticFallback()} is false, access is denied.</li>
//      * <li>If {@link AccessResult#NOT_SPECIFIED} is returned and
//      * {@link controllers.deadbolt.RestrictedResource#staticFallback()} is true, any further Restrict or
//      * Restrictions annotations are processed.  Note that if no Restrict or Restrictions annotations are present,
//      * access will be allowed.</li>
//      * </ul>
//      *
//      * @param resourceNames the names of the resource
//      * @param resourceParameters additional information on the resource
//      * @return {@link AccessResult#ALLOWED} if access is permitted.  {@link AccessResult#DENIED} if access is denied.
//      * {@link AccessResult#NOT_SPECIFIED} if access is not specified.
//      */
//     AccessResult checkAccess(List<String> resourceNames,
//                              Map<String, String> resourceParameters);
// }
// 
// Path: samples-and-tests/acl/app/model/AccessControlPreference.java
// @Entity
// public class AccessControlPreference extends Model
// {
//     public enum AccessChain { FRIENDS, ANYONE };
// 
//     @Enumerated(EnumType.STRING)
//     public AccessChain friendVisibility = AccessChain.ANYONE;
// 
//     @Enumerated(EnumType.STRING)
//     public AccessChain statusVisibility = AccessChain.ANYONE;
// 
//     @Enumerated(EnumType.STRING)
//     public AccessChain photoVisibility = AccessChain.ANYONE;
// }
// 
// Path: app/models/deadbolt/AccessResult.java
// public enum AccessResult
// {
//     ALLOWED,
//     DENIED,
//     NOT_SPECIFIED
// }
// 
// Path: samples-and-tests/acl/app/security/AccessChainHandler.java
// public abstract class AccessChainHandler implements RestrictedResourcesHandler
// {
//     public AccessResult checkAccess(List<String> resourceNames,
//                                     Map<String, String> resourceParameters)
//     {
//         String currentUserName = AclController.getCurrentUserName();
//         Http.Request request = Http.Request.current();
//         String targetUserName = request.params.get("targetUserName");
// 
//         AccessResult accessResult = AccessResult.DENIED;
//         if (targetUserName == null || currentUserName.equals(targetUserName))
//         {
//             // current user is viewing own information
//             accessResult = AccessResult.ALLOWED;
//         }
//         else
//         {
//             AclUser targetUser = AclUser.getByUserName(targetUserName);
// 
//             switch (getAccessChain(targetUser.accessControlPreference))
//             {
//                 case FRIENDS:
//                     AclUser currentUser = AclUser.getByUserName(currentUserName);
//                     accessResult = targetUser.isFriend(currentUser) ? AccessResult.ALLOWED : AccessResult.DENIED;
//                     break;
//                 case ANYONE:
//                     accessResult = AccessResult.ALLOWED;
//                     break;
//             }
//         }
// 
//         return accessResult;
//     }
// 
//     public abstract AccessControlPreference.AccessChain getAccessChain(AccessControlPreference preference);
// }


// Path: samples-and-tests/acl/app/controllers/AclRestrictedResourcesHandler.java
import controllers.deadbolt.RestrictedResourcesHandler;
import model.AccessControlPreference;
import models.deadbolt.AccessResult;
import security.AccessChainHandler;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

package controllers;



/**
 * @author Steve Chaloner (steve@objectify.be)
 */
public class AclRestrictedResourcesHandler implements RestrictedResourcesHandler
{
    private static Map<String, RestrictedResourcesHandler> HANDLERS = new HashMap<String, RestrictedResourcesHandler>();

    static
    {
        HANDLERS.put("friends",
                     new AccessChainHandler()