2 * Copyright 2005-2010 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.
16 package org.wamblee.security.authorization.jpa;
18 import org.apache.log4j.Logger;
19 import org.wamblee.security.authentication.jpa.SecurityPersistenceUnit;
20 import org.wamblee.security.authorization.AuthorizationService;
21 import org.wamblee.security.authorization.AuthorizationServiceTest;
22 import org.wamblee.support.persistence.JpaTester;
23 import org.wamblee.support.persistence.TransactionProxyFactory;
26 * Unit test for the persistent authorization service.
28 * @author Erik Brakkee
30 public class JpaAuthorizationServiceTest extends AuthorizationServiceTest {
31 private static final Logger LOGGER = Logger
32 .getLogger(JpaAuthorizationServiceTest.class);
34 private static final String SERVICE_TABLE = "SEC_AUTH_SVC";
36 private static final String RULES_TABLE = "SEC_AUTH_RULE";
38 private static final String SERVICE_RULES_TABLE = "SEC_AUTH_SVC_RULE";
40 private static final String OPERATIONCOND_TABLE = "SEC_OPERATION_CONDITION";
42 private static final String PATHCOND_TABLE = "SEC_PATH_CONDITION";
44 private static final String USERCOND_TABLE = "SEC_USER_CONDITION";
46 private JpaTester jpaTester;
49 protected void setUp() throws Exception {
50 jpaTester = new JpaTester(new SecurityPersistenceUnit());
57 protected void tearDown() throws Exception {
66 * org.wamblee.security.authorization.AuthorizationServiceTest#createService
70 protected AuthorizationService createService() {
71 TransactionProxyFactory<AuthorizationService> factory = new TransactionProxyFactory<AuthorizationService>(
72 jpaTester.getJpaBuilder(), AuthorizationService.class);
73 JpaAuthorizationService service = new JpaAuthorizationService(
74 "DEFAULT", factory.getTransactionScopedEntityManager(),
75 getUserAccessor(), getUserAdministration(), 10000);
77 return factory.getProxy(service);
84 * org.wamblee.security.authorization.AuthorizationServiceTest#checkRuleCount
88 protected void checkRuleCount(int aCount) {
90 assertEquals(1, jpaTester.getDbUtils().getTableSize(SERVICE_TABLE));
91 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
93 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
94 SERVICE_RULES_TABLE));
95 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
97 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
99 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
100 OPERATIONCOND_TABLE));
101 } catch (Exception e) {
102 throw new RuntimeException(e);
106 public void testPerformance() {
108 long time = System.currentTimeMillis();
110 for (int i = 0; i < n; i++) {
111 testFirstRuleGrants();
113 testSecondRuleDenies();
115 testThirdRuleGrants();
117 testNoRulesSupportResource();
120 LOGGER.info("Executed " + (4 * n) + " authorization checks in " +
121 ((float) (System.currentTimeMillis() - time) / (float) 1000) +