%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.security.PortletPermission |
|
|
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>Portlet 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:dlestrat@apache.org">David Le Strat</a> |
|
30 | */ |
|
31 | public class PortletPermission extends PortalResourcePermission |
|
32 | { |
|
33 | ||
34 | /** |
|
35 | * <p>Constructor for PortletPermission.</p> |
|
36 | * |
|
37 | * @param name The portlet name. |
|
38 | * @param actions The actions on the portlet. |
|
39 | */ |
|
40 | public PortletPermission(String name, String actions) |
|
41 | { |
|
42 | 0 | super(name, actions); |
43 | 0 | } |
44 | ||
45 | /** |
|
46 | * <p>Constructor for PortletPermission.</p> |
|
47 | * |
|
48 | * @param name The portlet name. |
|
49 | * @param mask The mask of actions on the portlet. |
|
50 | */ |
|
51 | public PortletPermission(String name, int mask) |
|
52 | { |
|
53 | 0 | super(name, mask); |
54 | 0 | } |
55 | ||
56 | public boolean implies(Permission permission) |
|
57 | { |
|
58 | // The permission must be an instance |
|
59 | // of the PortletPermission. |
|
60 | 0 | if (!(permission instanceof PortletPermission)) |
61 | { |
|
62 | 0 | return false; |
63 | } |
|
64 | ||
65 | 0 | String name = getName(); |
66 | 0 | if (name != null) |
67 | { |
|
68 | 0 | int index = name.indexOf('*'); |
69 | 0 | if (index > -1) |
70 | { |
|
71 | 0 | if (!(permission.getName().startsWith(name.substring(0, index)))) |
72 | { |
|
73 | 0 | return false; |
74 | } |
|
75 | } |
|
76 | 0 | else if (!(permission.getName().equals(name))) |
77 | { |
|
78 | // The portlet name must be the same. |
|
79 | 0 | return false; |
80 | } |
|
81 | } |
|
82 | ||
83 | 0 | PortletPermission portletPerm = (PortletPermission) permission; |
84 | ||
85 | // The action bits in portletPerm (permission) |
|
86 | // must be set in the current mask permission. |
|
87 | 0 | return (mask & portletPerm.mask) == portletPerm.mask; |
88 | ||
89 | } |
|
90 | ||
91 | /** |
|
92 | * @see java.security.Permission#equals(Object) |
|
93 | */ |
|
94 | public boolean equals(Object object) |
|
95 | { |
|
96 | 0 | if (!(object instanceof PortletPermission)) |
97 | 0 | return false; |
98 | ||
99 | 0 | PortletPermission p = (PortletPermission) object; |
100 | 0 | return ((p.mask == mask) && (p.getName().equals(getName()))); |
101 | } |
|
102 | ||
103 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |