001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.jacc.test.external;
023:
024: import java.security.CodeSource;
025: import java.security.Permission;
026: import java.security.PermissionCollection;
027: import java.security.Policy;
028: import java.security.ProtectionDomain;
029: import java.util.Enumeration;
030: import java.util.Iterator;
031: import java.util.Vector;
032:
033: //$Id: TestExternalPolicyProvider.java 57211 2006-09-26 12:39:46Z dimitris@jboss.org $
034:
035: /**
036: * Test Policy Provider for JACC Authorization checks
037: * @author <a href="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
038: * @since Apr 27, 2006
039: * @version $Revision: 57211 $
040: */
041: public class TestExternalPolicyProvider extends Policy {
042: private TestPermissionCollection tpc;
043:
044: public TestExternalPolicyProvider() {
045: tpc = new TestPermissionCollection();
046: }
047:
048: public PermissionCollection getPermissions(CodeSource codeSource) {
049: return tpc;
050: }
051:
052: public void refresh() {
053: }
054:
055: public boolean implies(ProtectionDomain domain, Permission perm) {
056: return super .implies(domain, perm);
057: }
058:
059: //Custom methods used for xmbean injection
060: public String listContextPolicies() {
061: return "Dummy Context Policy";
062: }
063:
064: public Policy getPolicyProxy() {
065: return this ;
066: }
067:
068: public Class[] getExternalPermissionTypes() {
069: return new Class[] {};
070: }
071:
072: public void setExternalPermissionTypes(
073: Class[] externalPermissionTypes) {
074: }
075:
076: //Test Permission Collection
077: public class TestPermissionCollection extends PermissionCollection {
078: /** The serialVersionUID */
079: private static final long serialVersionUID = -8586347666117056129L;
080: private Vector perms = new Vector();
081:
082: public void add(Permission perm) {
083: perms.add(perm);
084: }
085:
086: public boolean implies(Permission perm) {
087: boolean result = false;
088: //Uncomment when there are advanced jacc external provider testcases
089: /*Iterator iter = perms.iterator();
090: while(iter.hasNext())
091: {
092: Permission p = (Permission)iter.next();
093: result = p.implies(perm);
094: if(result)
095: break;
096: }*/
097: return !result;
098: }
099:
100: public Enumeration elements() {
101: return perms.elements();
102: }
103: }
104: }
|