001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.security;
018:
019: import org.apache.jetspeed.JetspeedActions;
020:
021: import java.security.Permission;
022: import java.security.PermissionCollection;
023:
024: /**
025: * <p>Generalized Portlet Resoure permission.</p>
026: * <p>This code was partially inspired from articles from:</p>
027: * <ul>
028: * <li><a href="http://www-106.ibm.com/developerworks/library/j-jaas/">
029: * Extend JAAS for class instance-level authorization.</a></li>
030: * </ul>
031: *
032: * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
033: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
034: */
035: public abstract class PortalResourcePermission extends Permission {
036: /**
037: * <p>Mask used for determining what actions are allowed or requested.</p>
038: */
039: protected final int mask;
040:
041: /**
042: * <p>Constructor for PortletPermission.</p>
043: *
044: * @param name The portlet name.
045: * @param actions The actions on the portlet.
046: */
047: public PortalResourcePermission(String name, String actions) {
048: super (name);
049: mask = parseActions(actions);
050: }
051:
052: /**
053: * <p>Constructor for PortletPermission.</p>
054: *
055: * @param name The portlet name.
056: * @param mask The mask representing actions on the portlet.
057: */
058: public PortalResourcePermission(String name, int mask) {
059: super (name);
060: this .mask = mask;
061: }
062:
063: /**
064: * @see java.security.Permission#hashCode()
065: */
066: public int hashCode() {
067: StringBuffer value = new StringBuffer(getName());
068: return value.toString().hashCode() ^ mask;
069: }
070:
071: /**
072: * @see java.security.Permission#getActions()
073: */
074: public String getActions() {
075: return JetspeedActions.getContainerActions(mask);
076: }
077:
078: /* (non-Javadoc)
079: * @see java.security.Permission#implies(java.security.Permission)
080: */
081: public boolean implies(Permission permission) {
082: throw new IllegalStateException(
083: "Permission class did not implement implies");
084: }
085:
086: /**
087: * <p>Parses the actions string.</p>
088: * <p>Actions are separated by commas or white space.</p>
089: *
090: * @param actions The actions
091: */
092: public static int parseActions(String actions) {
093: return JetspeedActions.getContainerActionsMask(actions);
094: }
095:
096: /**
097: * <p>Overrides <code>Permission.newPermissionCollection()</code>.</p>
098: *
099: * @see java.security.Permission#newPermissionCollection()
100: */
101: public PermissionCollection newPermissionCollection() {
102: return new PortalResourcePermissionCollection();
103: }
104: }
|