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 java.util.logging.Logger;
20 import org.wamblee.security.authentication.jpa.SecurityPersistenceUnit;
21 import org.wamblee.security.authorization.AuthorizationService;
22 import org.wamblee.security.authorization.AuthorizationServiceTest;
23 import org.wamblee.test.persistence.JpaTester;
24 import org.wamblee.test.transactions.TransactionProxyFactory;
27 * Unit test for the persistent authorization service.
29 * @author Erik Brakkee
31 public class JpaAuthorizationServiceTest extends AuthorizationServiceTest {
32 private static final Logger LOGGER = Logger
33 .getLogger(JpaAuthorizationServiceTest.class.getName());
35 private static final String SERVICE_TABLE = "SEC_AUTH_SVC";
37 private static final String RULES_TABLE = "SEC_AUTH_RULE";
39 private static final String SERVICE_RULES_TABLE = "SEC_AUTH_SVC_RULE";
41 private static final String OPERATIONCOND_TABLE = "SEC_OPERATION_CONDITION";
43 private static final String PATHCOND_TABLE = "SEC_PATH_CONDITION";
45 private static final String USERCOND_TABLE = "SEC_USER_CONDITION";
47 private JpaTester jpaTester;
50 protected void setUp() throws Exception {
51 jpaTester = new JpaTester(new SecurityPersistenceUnit());
58 protected void tearDown() throws Exception {
67 * org.wamblee.security.authorization.AuthorizationServiceTest#createService
71 protected AuthorizationService createService() {
72 TransactionProxyFactory<AuthorizationService> factory = new TransactionProxyFactory<AuthorizationService>(
73 jpaTester.getJpaBuilder(), AuthorizationService.class);
74 JpaAuthorizationService service = new JpaAuthorizationService(
75 "DEFAULT", factory.getTransactionScopedEntityManager(),
76 getUserAccessor(), getUserAdministration(), 10000);
78 return factory.getProxy(service);
85 * org.wamblee.security.authorization.AuthorizationServiceTest#checkRuleCount
89 protected void checkRuleCount(int aCount) {
91 assertEquals(1, jpaTester.getDbUtils().getTableSize(SERVICE_TABLE));
92 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
94 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
95 SERVICE_RULES_TABLE));
96 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
98 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
100 assertEquals(aCount, jpaTester.getDbUtils().getTableSize(
101 OPERATIONCOND_TABLE));
102 } catch (Exception e) {
103 throw new RuntimeException(e);
107 public void testPerformance() {
109 long time = System.currentTimeMillis();
111 for (int i = 0; i < n; i++) {
112 testFirstRuleGrants();
114 testSecondRuleDenies();
116 testThirdRuleGrants();
118 testNoRulesSupportResource();
121 LOGGER.info("Executed " + (4 * n) + " authorization checks in " +
122 ((float) (System.currentTimeMillis() - time) / (float) 1000) +