// Path: app/controllers/deadbolt/DeadboltHandler.java
// public interface DeadboltHandler
// {
//     /**
//      * Invoked immediately before controller or view restrictions are checked.  This forms the integration with any
//      * authentication actions that may need to occur.
//      */
//     void beforeRoleCheck();
// 
//     /**
//      * Gets the current {@link RoleHolder}, e.g. the current user.
//      *
//      * @return the current role holder
//      */
//     RoleHolder getRoleHolder();
// 
//     /**
//      * Invoked when an access failure is detected on <i>controllerClassName</i>.
//      *
//      * @param controllerClassName the name of the controller access was denied to
//      */
//     void onAccessFailure(String controllerClassName);
// 
//     /**
//      * Gets the accessor used to determine restrictions from an external source.
//      *
//      * @return the accessor for externalised restrictions.  May be null.
//      */
//     ExternalizedRestrictionsAccessor getExternalizedRestrictionsAccessor();
// 
//     /**
//      * Gets the handler used for dealing with resources restricted to specific users/groups.
//      *
//      * @return the handler for restricted resources.  May be null.
//      */
//     RestrictedResourcesHandler getRestrictedResourcesHandler();
// }
// 
// Path: app/controllers/deadbolt/ExternalizedRestrictionsAccessor.java
// public interface ExternalizedRestrictionsAccessor
// {
//     ExternalizedRestrictions getExternalizedRestrictions(String name);
// }
// 
// 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/AclUser.java
// @Entity
// public class AclUser extends Model implements RoleHolder
// {
//     @Required
//     public String userName;
// 
//     public String fullName;
// 
//     @Required
//     @ManyToOne
//     public AclApplicationRole role;
// 
//     @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE, CascadeType.DETACH})
//     public List<AclUser> friends;
// 
//     @ManyToMany(cascade = CascadeType.ALL)
//     public List<Photo> photos;
// 
//     @ManyToMany(cascade = CascadeType.ALL)
//     public List<StatusUpdate> statusUpdates;
// 
//     @OneToOne(cascade = CascadeType.ALL)
//     public AccessControlPreference accessControlPreference;
// 
//     public AclUser(String userName,
//                    String fullName,
//                    AclApplicationRole role)
//     {
//         this.userName = userName;
//         this.fullName = fullName;
//         this.role = role;
//         this.accessControlPreference = new AccessControlPreference();
//     }
// 
//     public static AclUser getByUserName(String userName)
//     {
//         return find("byUserName", userName).first();
//     }
// 
//     public List<? extends Role> getRoles()
//     {
//         return Arrays.asList(role);
//     }
// 
//     public void addPhoto(Photo photo)
//     {
//         if (photos == null)
//         {
//             photos = new ArrayList<Photo>();
//         }
//         photos.add(photo);
//     }
// 
//     public void addStatusUpdate(StatusUpdate statusUpdate)
//     {
//         if (statusUpdates == null)
//         {
//             statusUpdates = new ArrayList<StatusUpdate>();
//         }
//         statusUpdates.add(statusUpdate);
//     }
// 
//     public void addFriend(AclUser friend)
//     {
//         if (friends == null)
//         {
//             friends = new ArrayList<AclUser>();
//         }
//         friends.add(friend);
//     }
// 
//     public boolean isFriend(AclUser user)
//     {
//         return friends != null && friends.contains(user);
//     }
// 
//     @Override
//     public String toString()
//     {
//         return this.userName;
//     }
// }
// 
// Path: app/models/deadbolt/ExternalizedRestrictions.java
// public interface ExternalizedRestrictions
// {
//     /**
//      * Gets all the {@link ExternalizedRestriction}s associated with a target.
//      *
//      * @return
//      */
//     List<ExternalizedRestriction> getExternalisedRestrictions();
// }
// 
// Path: app/models/deadbolt/RoleHolder.java
// public interface RoleHolder
// {
//     /**
//      * A list of {@link Role}s held by the role holder.
//      *
//      * @return a list of roles
//      */
//     List<? extends Role> getRoles();
// }


import controllers.deadbolt.DeadboltHandler;
import controllers.deadbolt.ExternalizedRestrictionsAccessor;
import controllers.deadbolt.RestrictedResourcesHandler;
import model.AclUser;
import models.deadbolt.ExternalizedRestrictions;
import models.deadbolt.RoleHolder;
import play.mvc.Controller;
/*
 * Copyright 2010-2011 Steve Chaloner
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package controllers;


/**
 * @author Steve Chaloner (steve@objectify.be)
 */
public class AclDeadboltHandler extends Controller implements DeadboltHandler
{
// Path: app/controllers/deadbolt/DeadboltHandler.java
// public interface DeadboltHandler
// {
//     /**
//      * Invoked immediately before controller or view restrictions are checked.  This forms the integration with any
//      * authentication actions that may need to occur.
//      */
//     void beforeRoleCheck();
// 
//     /**
//      * Gets the current {@link RoleHolder}, e.g. the current user.
//      *
//      * @return the current role holder
//      */
//     RoleHolder getRoleHolder();
// 
//     /**
//      * Invoked when an access failure is detected on <i>controllerClassName</i>.
//      *
//      * @param controllerClassName the name of the controller access was denied to
//      */
//     void onAccessFailure(String controllerClassName);
// 
//     /**
//      * Gets the accessor used to determine restrictions from an external source.
//      *
//      * @return the accessor for externalised restrictions.  May be null.
//      */
//     ExternalizedRestrictionsAccessor getExternalizedRestrictionsAccessor();
// 
//     /**
//      * Gets the handler used for dealing with resources restricted to specific users/groups.
//      *
//      * @return the handler for restricted resources.  May be null.
//      */
//     RestrictedResourcesHandler getRestrictedResourcesHandler();
// }
// 
// Path: app/controllers/deadbolt/ExternalizedRestrictionsAccessor.java
// public interface ExternalizedRestrictionsAccessor
// {
//     ExternalizedRestrictions getExternalizedRestrictions(String name);
// }
// 
// 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/AclUser.java
// @Entity
// public class AclUser extends Model implements RoleHolder
// {
//     @Required
//     public String userName;
// 
//     public String fullName;
// 
//     @Required
//     @ManyToOne
//     public AclApplicationRole role;
// 
//     @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE, CascadeType.DETACH})
//     public List<AclUser> friends;
// 
//     @ManyToMany(cascade = CascadeType.ALL)
//     public List<Photo> photos;
// 
//     @ManyToMany(cascade = CascadeType.ALL)
//     public List<StatusUpdate> statusUpdates;
// 
//     @OneToOne(cascade = CascadeType.ALL)
//     public AccessControlPreference accessControlPreference;
// 
//     public AclUser(String userName,
//                    String fullName,
//                    AclApplicationRole role)
//     {
//         this.userName = userName;
//         this.fullName = fullName;
//         this.role = role;
//         this.accessControlPreference = new AccessControlPreference();
//     }
// 
//     public static AclUser getByUserName(String userName)
//     {
//         return find("byUserName", userName).first();
//     }
// 
//     public List<? extends Role> getRoles()
//     {
//         return Arrays.asList(role);
//     }
// 
//     public void addPhoto(Photo photo)
//     {
//         if (photos == null)
//         {
//             photos = new ArrayList<Photo>();
//         }
//         photos.add(photo);
//     }
// 
//     public void addStatusUpdate(StatusUpdate statusUpdate)
//     {
//         if (statusUpdates == null)
//         {
//             statusUpdates = new ArrayList<StatusUpdate>();
//         }
//         statusUpdates.add(statusUpdate);
//     }
// 
//     public void addFriend(AclUser friend)
//     {
//         if (friends == null)
//         {
//             friends = new ArrayList<AclUser>();
//         }
//         friends.add(friend);
//     }
// 
//     public boolean isFriend(AclUser user)
//     {
//         return friends != null && friends.contains(user);
//     }
// 
//     @Override
//     public String toString()
//     {
//         return this.userName;
//     }
// }
// 
// Path: app/models/deadbolt/ExternalizedRestrictions.java
// public interface ExternalizedRestrictions
// {
//     /**
//      * Gets all the {@link ExternalizedRestriction}s associated with a target.
//      *
//      * @return
//      */
//     List<ExternalizedRestriction> getExternalisedRestrictions();
// }
// 
// Path: app/models/deadbolt/RoleHolder.java
// public interface RoleHolder
// {
//     /**
//      * A list of {@link Role}s held by the role holder.
//      *
//      * @return a list of roles
//      */
//     List<? extends Role> getRoles();
// }


// Path: samples-and-tests/acl/app/controllers/AclDeadboltHandler.java
import controllers.deadbolt.DeadboltHandler;
import controllers.deadbolt.ExternalizedRestrictionsAccessor;
import controllers.deadbolt.RestrictedResourcesHandler;
import model.AclUser;
import models.deadbolt.ExternalizedRestrictions;
import models.deadbolt.RoleHolder;
import play.mvc.Controller;

/*
 * Copyright 2010-2011 Steve Chaloner
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package controllers;


/**
 * @author Steve Chaloner (steve@objectify.be)
 */
public class AclDeadboltHandler extends Controller implements DeadboltHandler
{
    private static final RestrictedResourcesHandler RESTRICTED_RESOURCES_HANDLER = new AclRestrictedResourcesHandler();