01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.test.security;
23:
24: import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
25: import org.jboss.portal.security.PortalPermission;
26: import org.jboss.portal.security.PortalSecurityException;
27: import org.jboss.portal.security.RoleSecurityBinding;
28: import org.jboss.portal.security.spi.provider.AuthorizationDomain;
29: import org.jboss.portal.security.spi.provider.DomainConfigurator;
30: import org.jboss.portal.security.spi.provider.PermissionRepository;
31: import org.jboss.portal.security.spi.provider.SecurityConfigurationException;
32:
33: import java.util.Iterator;
34: import java.util.Map;
35: import java.util.Set;
36:
37: /**
38: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
39: * @version $Revision: 8784 $
40: */
41: public abstract class BaseAuthorizationDomain implements
42: AuthorizationDomain, DomainConfigurator, PermissionRepository {
43:
44: /** . */
45: private Map repository = new ConcurrentHashMap();
46:
47: public DomainConfigurator getConfigurator() {
48: return this ;
49: }
50:
51: public PermissionRepository getPermissionRepository() {
52: return this ;
53: }
54:
55: // ************
56:
57: public PortalPermission getPermission(String roleName, String uri)
58: throws PortalSecurityException {
59: Set set = (Set) repository.get(uri);
60: if (set != null) {
61: for (Iterator i = set.iterator(); i.hasNext();) {
62: RoleSecurityBinding sc = (RoleSecurityBinding) i.next();
63: if (sc.getRoleName().equals(roleName)) {
64: return getPermissionFactory().createPermission(uri,
65: sc.getActions());
66: }
67: }
68: }
69: return null;
70: }
71:
72: // ************
73:
74: public Set getSecurityBindings(String uri) {
75: Set set = (Set) repository.get(uri);
76: return set;
77: }
78:
79: public void setSecurityBindings(String uri, Set securityBindings)
80: throws SecurityConfigurationException {
81: repository.put(uri, securityBindings);
82: }
83:
84: public void removeSecurityBindings(String uri)
85: throws SecurityConfigurationException {
86: repository.remove(uri);
87: }
88: }
|