001 package org.apache.turbine.services.security; 002 003 004 /* 005 * Licensed to the Apache Software Foundation (ASF) under one 006 * or more contributor license agreements. See the NOTICE file 007 * distributed with this work for additional information 008 * regarding copyright ownership. The ASF licenses this file 009 * to you under the Apache License, Version 2.0 (the 010 * "License"); you may not use this file except in compliance 011 * with the License. You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, 016 * software distributed under the License is distributed on an 017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 018 * KIND, either express or implied. See the License for the 019 * specific language governing permissions and limitations 020 * under the License. 021 */ 022 023 024 import java.util.HashMap; 025 import java.util.Map; 026 027 import org.apache.commons.configuration.BaseConfiguration; 028 import org.apache.commons.configuration.Configuration; 029 030 import org.apache.turbine.services.ServiceManager; 031 import org.apache.turbine.services.TurbineServices; 032 import org.apache.turbine.services.security.SecurityService; 033 import org.apache.turbine.test.BaseTestCase; 034 import org.apache.turbine.test.MockSecurityService; 035 import org.apache.turbine.util.TurbineConfig; 036 import org.apache.turbine.util.security.AccessControlList; 037 import org.apache.turbine.util.security.TurbineAccessControlList; 038 039 public class AccessControlListTest 040 extends BaseTestCase 041 { 042 043 private static TurbineConfig tc = null; 044 private static final String PREFIX = "services." + 045 SecurityService.SERVICE_NAME + '.'; 046 047 public AccessControlListTest( String name ) 048 throws Exception 049 { 050 super(name); 051 } 052 053 public void setUp() throws Exception 054 { 055 tc = new TurbineConfig(".", "/conf/test/TestFulcrumComponents.properties"); 056 tc.initialize(); 057 } 058 public void tearDown() throws Exception 059 { 060 if (tc != null) 061 { 062 tc.dispose(); 063 } 064 } 065 066 public void testSelection() throws Exception 067 { 068 ServiceManager serviceManager = TurbineServices.getInstance(); 069 serviceManager.setApplicationRoot("."); 070 071 Configuration cfg = new BaseConfiguration(); 072 073 cfg.setProperty(PREFIX + "classname", 074 MockSecurityService.class.getName()); 075 076 cfg.setProperty(PREFIX + "acl.class", 077 TurbineAccessControlList.class.getName()); 078 079 // We must run init! 080 cfg.setProperty(PREFIX+"earlyInit", "true"); 081 082 /* Ugh */ 083 084 // cfg.setProperty("services." + FactoryService.SERVICE_NAME + ".classname", 085 // TurbineFactoryService.class.getName()); 086 087 serviceManager.setConfiguration(cfg); 088 089 serviceManager.init(); 090 091 Class aclClass = TurbineSecurity.getService().getAclClass(); 092 093 if(!aclClass.getName().equals(TurbineAccessControlList.class.getName())) 094 { 095 fail("ACL Class is " + aclClass.getName() 096 + ", expected was " + TurbineAccessControlList.class.getName()); 097 } 098 099 Map roles = new HashMap(); 100 Map permissions = new HashMap(); 101 102 AccessControlList aclTest = 103 TurbineSecurity.getService().getAclInstance(roles, permissions); 104 105 if(aclTest == null) 106 { 107 fail("Security Service failed to deliver a " + aclClass.getName() 108 + " Object"); 109 } 110 } 111 112 113 }