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;
19 import java.util.logging.Logger;
21 import org.wamblee.security.authentication.jpa.SecurityPersistenceUnit;
22 import org.wamblee.security.authorization.AuthorizationService;
23 import org.wamblee.security.authorization.AuthorizationServiceTest;
24 import org.wamblee.test.persistence.JpaTester;
25 import org.wamblee.test.transactions.TransactionProxyFactory;
28 * Unit test for the persistent authorization service.
30 * @author Erik Brakkee
32 public class JpaAuthorizationServiceTest extends AuthorizationServiceTest {
33 private static final Logger LOGGER = Logger
34 .getLogger(JpaAuthorizationServiceTest.class.getName());
36 private static final String SERVICE_TABLE = "SEC_AUTH_SVC";
38 private static final String RULES_TABLE = "SEC_AUTH_RULE";
40 private static final String SERVICE_RULES_TABLE = "SEC_AUTH_SVC_RULE";
42 private static final String OPERATIONCOND_TABLE = "SEC_OPERATION_CONDITION";
44 private static final String PATHCOND_TABLE = "SEC_PATH_CONDITION";
46 private static final String USERCOND_TABLE = "SEC_USER_CONDITION";
48 private JpaTester jpaTester;
51 protected void setUp() throws Exception {
52 jpaTester = new JpaTester(new SecurityPersistenceUnit());
59 protected void tearDown() throws Exception {
68 * org.wamblee.security.authorization.AuthorizationServiceTest#createService
72 protected AuthorizationService createService() {
73 TransactionProxyFactory<AuthorizationService> factory = new TransactionProxyFactory<AuthorizationService>(
74 jpaTester.getJpaBuilder(), AuthorizationService.class);
75 JpaAuthorizationService service = new JpaAuthorizationService(
76 "DEFAULT", factory.getTransactionScopedEntityManager(),
77 getUserAccessor(), getUserAdministration(), 10000);
79 return factory.getProxy(service);
86 * org.wamblee.security.authorization.AuthorizationServiceTest#checkRuleCount
90 protected void checkRuleCount(int aCount) {
92 assertEquals(1, jpaTester.getDbUtils().getTableSize(SERVICE_TABLE));
93 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
95 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
96 SERVICE_RULES_TABLE));
97 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
99 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
101 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
102 OPERATIONCOND_TABLE));
103 } catch (Exception e) {
104 throw new RuntimeException(e);
108 public void testPerformance() {
110 long time = System.currentTimeMillis();
112 for (int i = 0; i < n; i++) {
113 testFirstRuleGrants();
115 testSecondRuleDenies();
117 testThirdRuleGrants();
119 testNoRulesSupportResource();
122 LOGGER.info("Executed " + (4 * n) + " authorization checks in " +
123 ((float) (System.currentTimeMillis() - time) / (float) 1000) +