2 * Copyright 2005 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.wamblee.security.authorization.hibernate;
19 import java.sql.SQLException;
21 import org.apache.log4j.Logger;
22 import org.springframework.orm.hibernate3.HibernateTemplate;
23 import org.wamblee.general.BeanKernel;
24 import org.wamblee.security.authorization.AuthorizationService;
25 import org.wamblee.security.authorization.AuthorizationServiceTest;
28 * Unit test for the persistent authorization service.
30 public class PersistentAuthorizationServiceTest extends AuthorizationServiceTest {
32 private static final Logger LOGGER = Logger.getLogger(PersistentAuthorizationServiceTest.class);
34 private static final String SERVICE_TABLE = "AUTHORIZATION_SERVICE";
35 private static final String RULES_TABLE = "AUTHORIZATION_RULES";
36 private static final String SERVICE_RULES_TABLE = "AUTHORIZATION_SERVICE_RULES";
37 private static final String OPERATIONCOND_TABLE = "OPERATION_CONDITIONS";
38 private static final String PATHCOND_TABLE = "PATH_CONDITIONS";
39 private static final String USERCOND_TABLE = "USER_CONDITIONS";
42 public PersistentAuthorizationServiceTest() {
43 super(AuthorizationSpringConfigFiles.class, AuthorizationMappingFiles.class);
47 * @see org.wamblee.security.authorization.AuthorizationServiceTest#createService()
50 protected AuthorizationService createService() {
51 PersistentAuthorizationService service = new PersistentAuthorizationService("DEFAULT",
52 BeanKernel.getBeanFactory().find(HibernateTemplate.class), createUserAccessor(), 10000);
57 * @see org.wamblee.security.authorization.AuthorizationServiceTest#checkRuleCount(int)
60 protected void checkRuleCount(int aCount) {
62 assertEquals(1, getTableSize(SERVICE_TABLE));
63 assertEquals(aCount, getTableSize(RULES_TABLE));
64 assertEquals(aCount, getTableSize(SERVICE_RULES_TABLE));
65 assertEquals(aCount, getTableSize(USERCOND_TABLE));
66 assertEquals(aCount, getTableSize(PATHCOND_TABLE));
67 assertEquals(aCount, getTableSize(OPERATIONCOND_TABLE));
68 } catch (SQLException e) {
69 throw new RuntimeException(e);
74 public void testPerformance() {
76 PersistentAuthorizationService service = (PersistentAuthorizationService)getService();
79 long time = System.currentTimeMillis();
80 for (int i = 0; i < n; i++) {
81 testFirstRuleGrants();
83 testSecondRuleDenies();
85 testThirdRuleGrants();
87 testNoRulesSupportResource();
89 LOGGER.info("Executed " + 4*n + " authorization checks in " + (float)(System.currentTimeMillis()-time)/(float)1000 + " seconds.");