    1   package org.apache.turbine.services.security;
    2
    3
    4   /*
    5    * Licensed to the Apache Software Foundation (ASF) under one
    6    * or more contributor license agreements.  See the NOTICE file
    7    * distributed with this work for additional information
    8    * regarding copyright ownership.  The ASF licenses this file
    9    * to you under the Apache License, Version 2.0 (the
    10   * "License"); you may not use this file except in compliance
    11   * with the License.  You may obtain a copy of the License at
    12   *
    13   *   http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing,
    16   * software distributed under the License is distributed on an
    17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    18   * KIND, either express or implied.  See the License for the
    19   * specific language governing permissions and limitations
    20   * under the License.
    21   */
    22
    23
    24  import java.util.HashMap;
    25  import java.util.Map;
    26
    27  import org.apache.commons.configuration.BaseConfiguration;
    28  import org.apache.commons.configuration.Configuration;
    29
    30  import org.apache.turbine.services.ServiceManager;
    31  import org.apache.turbine.services.TurbineServices;
    32  import org.apache.turbine.services.security.SecurityService;
    33  import org.apache.turbine.test.BaseTestCase;
    34  import org.apache.turbine.test.MockSecurityService;
    35  import org.apache.turbine.util.TurbineConfig;
    36  import org.apache.turbine.util.security.AccessControlList;
    37  import org.apache.turbine.util.security.TurbineAccessControlList;
    38
    39  public class AccessControlListTest
    40      extends BaseTestCase
    41  {
    42
    43  	private static TurbineConfig tc = null;
    44      private static final String PREFIX = "services." +
    45          SecurityService.SERVICE_NAME + '.';
    46
    47      public AccessControlListTest( String name )
    48              throws Exception
    49      {
    50          super(name);
    51      }
    52
    53      public void setUp() throws Exception
    54      {
    55          tc = new TurbineConfig(".", "/conf/test/TestFulcrumComponents.properties");
    56          tc.initialize();
    57      }
    58      public void tearDown() throws Exception
    59      {
    60          if (tc != null)
    61          {
    62              tc.dispose();
    63          }
    64      }
    65
    66      public void testSelection() throws Exception
    67      {
    68      	  ServiceManager serviceManager = TurbineServices.getInstance();
    69            serviceManager.setApplicationRoot(".");
    70
    71            Configuration cfg = new BaseConfiguration();
    72
    73            cfg.setProperty(PREFIX + "classname",
    74                            MockSecurityService.class.getName());
    75
    76            cfg.setProperty(PREFIX + "acl.class",
    77                            TurbineAccessControlList.class.getName());
    78
    79            // We must run init!
    80            cfg.setProperty(PREFIX+"earlyInit", "true");
    81
    82            /* Ugh */
    83
    84   //         cfg.setProperty("services." + FactoryService.SERVICE_NAME + ".classname",
    85     //                       TurbineFactoryService.class.getName());
    86
    87            serviceManager.setConfiguration(cfg);
    88
    89            serviceManager.init();
    90
    91            Class aclClass = TurbineSecurity.getService().getAclClass();
    92
    93            if(!aclClass.getName().equals(TurbineAccessControlList.class.getName()))
    94            {
    95                fail("ACL Class is " + aclClass.getName()
    96                     + ", expected was " + TurbineAccessControlList.class.getName());
    97            }
    98
    99            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 }