View Javadoc

1   /* 
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8   *
9   *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17  package org.apache.jetspeed.security;
18  
19  import java.security.Permission;
20  
21  /***
22   * <p>Folder permission.</p>
23   * <p>This code was partially inspired from articles from:</p>
24   * <ul>
25   * <li><a href="http://www-106.ibm.com/developerworks/library/j-jaas/">
26   * Extend JAAS for class instance-level authorization.</a></li>
27   * </ul>
28   *
29   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
30   */
31  public class PagePermission extends PortalResourcePermission
32  {
33      /***
34       * <p>Constructor for PagePermission.</p>
35       *
36       * @param name    The portlet name.
37       * @param actions The actions on the portlet.
38       */
39      public PagePermission(String name, String actions)
40      {
41          super(name, actions);
42      }
43  
44      /***
45       * <p>Constructor for PagePermission.</p>
46       *
47       * @param name The portlet name.
48       * @param mask The mask for actions on the portlet.
49       */
50      public PagePermission(String name, int mask)
51      {
52          super(name, mask);
53      }
54  
55      public boolean implies(Permission permission)
56      {
57          // The permission must be an instance 
58          // of the PortletPermission.
59          if (!(permission instanceof PagePermission))
60          {
61              return false;
62          }
63  
64          // The page name must be the same.
65          if (!(permission.getName().equals(getName())))
66          {
67              return false;
68          }
69  
70          PagePermission pagePerm = (PagePermission) permission;
71  
72          // The action bits in PagePerm (permission)
73          // must be set in the current mask permission.
74          return (mask & pagePerm.mask) == pagePerm.mask;
75  
76      }
77  
78      /***
79       * @see java.security.Permission#equals(Object)
80       */
81      public boolean equals(Object object)
82      {
83          if (!(object instanceof PagePermission))
84              return false;
85  
86          PagePermission p = (PagePermission) object;
87          return ((p.mask == mask) && (p.getName().equals(getName())));
88      }
89  
90  }