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 * @author Erik Brakkee
32 public class PersistentAuthorizationServiceTest extends AuthorizationServiceTest {
34 private static final Logger LOGGER = Logger.getLogger(PersistentAuthorizationServiceTest.class);
36 private static final String SERVICE_TABLE = "AUTHORIZATION_SERVICE";
37 private static final String RULES_TABLE = "AUTHORIZATION_RULES";
38 private static final String SERVICE_RULES_TABLE = "AUTHORIZATION_SERVICE_RULES";
39 private static final String OPERATIONCOND_TABLE = "OPERATION_CONDITIONS";
40 private static final String PATHCOND_TABLE = "PATH_CONDITIONS";
41 private static final String USERCOND_TABLE = "USER_CONDITIONS";
44 public PersistentAuthorizationServiceTest() {
45 super(AuthorizationSpringConfigFiles.class, AuthorizationMappingFiles.class);
49 * @see org.wamblee.security.authorization.AuthorizationServiceTest#createService()
52 protected AuthorizationService createService() {
53 PersistentAuthorizationService service = new PersistentAuthorizationService("DEFAULT",
54 BeanKernel.getBeanFactory().find(HibernateTemplate.class), createUserAccessor(), 10000);
59 * @see org.wamblee.security.authorization.AuthorizationServiceTest#checkRuleCount(int)
62 protected void checkRuleCount(int aCount) {
64 assertEquals(1, getTableSize(SERVICE_TABLE));
65 assertEquals(aCount, getTableSize(RULES_TABLE));
66 assertEquals(aCount, getTableSize(SERVICE_RULES_TABLE));
67 assertEquals(aCount, getTableSize(USERCOND_TABLE));
68 assertEquals(aCount, getTableSize(PATHCOND_TABLE));
69 assertEquals(aCount, getTableSize(OPERATIONCOND_TABLE));
70 } catch (SQLException e) {
71 throw new RuntimeException(e);
76 public void testPerformance() {
78 PersistentAuthorizationService service = (PersistentAuthorizationService)getService();
81 long time = System.currentTimeMillis();
82 for (int i = 0; i < n; i++) {
83 testFirstRuleGrants();
85 testSecondRuleDenies();
87 testThirdRuleGrants();
89 testNoRulesSupportResource();
91 LOGGER.info("Executed " + 4*n + " authorization checks in " + (float)(System.currentTimeMillis()-time)/(float)1000 + " seconds.");