/* * Copyright 2005 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.wamblee.security.authorization.hibernate; import java.sql.SQLException; import org.apache.log4j.Logger; import org.springframework.orm.hibernate3.HibernateTemplate; import org.wamblee.general.BeanKernel; import org.wamblee.security.authorization.AuthorizationService; import org.wamblee.security.authorization.AuthorizationServiceTest; /** * Unit test for the persistent authorization service. * * @author Erik Brakkee */ public class PersistentAuthorizationServiceTest extends AuthorizationServiceTest { private static final Logger LOGGER = Logger.getLogger(PersistentAuthorizationServiceTest.class); private static final String SERVICE_TABLE = "AUTHORIZATION_SERVICE"; private static final String RULES_TABLE = "AUTHORIZATION_RULES"; private static final String SERVICE_RULES_TABLE = "AUTHORIZATION_SERVICE_RULES"; private static final String OPERATIONCOND_TABLE = "OPERATION_CONDITIONS"; private static final String PATHCOND_TABLE = "PATH_CONDITIONS"; private static final String USERCOND_TABLE = "USER_CONDITIONS"; public PersistentAuthorizationServiceTest() { super(AuthorizationSpringConfigFiles.class, AuthorizationMappingFiles.class); } /* (non-Javadoc) * @see org.wamblee.security.authorization.AuthorizationServiceTest#createService() */ @Override protected AuthorizationService createService() { PersistentAuthorizationService service = new PersistentAuthorizationService("DEFAULT", BeanKernel.getBeanFactory().find(HibernateTemplate.class), createUserAccessor(), 10000); return service; } /* (non-Javadoc) * @see org.wamblee.security.authorization.AuthorizationServiceTest#checkRuleCount(int) */ @Override protected void checkRuleCount(int aCount) { try { assertEquals(1, getTableSize(SERVICE_TABLE)); assertEquals(aCount, getTableSize(RULES_TABLE)); assertEquals(aCount, getTableSize(SERVICE_RULES_TABLE)); assertEquals(aCount, getTableSize(USERCOND_TABLE)); assertEquals(aCount, getTableSize(PATHCOND_TABLE)); assertEquals(aCount, getTableSize(OPERATIONCOND_TABLE)); } catch (SQLException e) { throw new RuntimeException(e); } } public void testPerformance() { PersistentAuthorizationService service = (PersistentAuthorizationService)getService(); int n = 1000; long time = System.currentTimeMillis(); for (int i = 0; i < n; i++) { testFirstRuleGrants(); resetTestRules(); testSecondRuleDenies(); resetTestRules(); testThirdRuleGrants(); resetTestRules(); testNoRulesSupportResource(); } LOGGER.info("Executed " + 4*n + " authorization checks in " + (float)(System.currentTimeMillis()-time)/(float)1000 + " seconds."); } }