001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.test.security;
023:
024: import org.jboss.portal.security.PortalPermission;
025: import org.jboss.portal.security.PortalPermissionCollection;
026: import org.jboss.portal.security.PortalSecurityException;
027: import org.jboss.portal.security.spi.provider.PermissionRepository;
028:
029: import javax.security.auth.Subject;
030: import java.security.Permission;
031:
032: /**
033: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
034: * @version $Revision: 8784 $
035: */
036: public class FlatPermission extends PortalPermission {
037:
038: /** The serialVersionUID */
039: private static final long serialVersionUID = 1908049509264888772L;
040:
041: /** . */
042: public static final String PERMISSION_TYPE = "flat";
043:
044: public FlatPermission(PortalPermissionCollection collection) {
045: super (PERMISSION_TYPE, collection);
046: }
047:
048: public FlatPermission(String uri) {
049: super (PERMISSION_TYPE, uri);
050: }
051:
052: public boolean implies(PermissionRepository repository,
053: Subject caller, String roleName, PortalPermission permission)
054: throws PortalSecurityException {
055: if (permission instanceof FlatPermission
056: && permission.getURI() != null) {
057: PortalPermission a = repository.getPermission(roleName,
058: permission.getURI());
059: if (a != null) {
060: return a.implies(permission);
061: }
062: }
063: return false;
064: }
065:
066: public boolean implies(Permission permission) {
067: if (permission instanceof FlatPermission && uri != null) {
068: FlatPermission that = (FlatPermission) permission;
069: return uri.equals(that.uri);
070: }
071: return false;
072: }
073:
074: public boolean equals(Object obj) {
075: if (obj == this ) {
076: return true;
077: }
078: if (obj instanceof FlatPermission) {
079: FlatPermission that = (FlatPermission) obj;
080: if (uri == null) {
081: return that.uri == null;
082: } else {
083: return uri.equals(that.uri);
084: }
085: }
086: return false;
087: }
088:
089: public int hashCode() {
090: return uri == null ? 0 : uri.hashCode();
091: }
092:
093: public String getActions() {
094: return null;
095: }
096:
097: public String getType() {
098: return PERMISSION_TYPE;
099: }
100: }
|