001: /*
002: * JBoss, Home of Professional Open Source
003: * Copyright 2005, JBoss Inc., and individual contributors as indicated
004: * by the @authors tag. See the copyright.txt in the distribution for a
005: * full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.portal.test.cms.security;
023:
024: import org.hibernate.Session;
025: import org.hibernate.SessionFactory;
026: import org.hibernate.Transaction;
027: import org.jboss.portal.cms.impl.interceptors.ACLInterceptor;
028: import org.jboss.portal.cms.impl.jcr.JCRCMS;
029: import org.jboss.portal.cms.security.AuthorizationProviderImpl;
030: import org.jboss.portal.common.invocation.Interceptor;
031: import org.jboss.portal.identity.IdentityContext;
032: import org.jboss.portal.identity.IdentityServiceController;
033: import org.jboss.portal.identity.UserModule;
034: import org.jboss.portal.server.impl.invocation.JBossInterceptorStack;
035: import org.jboss.portal.test.cms.commands.AbstractCommandTestCase;
036: import org.jboss.portal.test.cms.commands.CMSInterceptorStackFactory;
037:
038: import javax.naming.InitialContext;
039:
040: /** @author Sohil Shah - sohil.shah@jboss.com - Nov 30, 2006 */
041: public abstract class SecureCommandTestCase extends
042: AbstractCommandTestCase {
043: /**
044: *
045: */
046: protected UserModule userModule = null;
047:
048: /**
049: *
050: */
051: public SecureCommandTestCase() {
052: super ();
053: }
054:
055: /**
056: *
057: */
058: public void setUp() throws Exception {
059: //override the configration location to include workflow services
060: this .configuration = "org/jboss/portal/cms/jboss-beans-security.xml";
061: super .setUp();
062:
063: ACLInterceptor aclInterceptor = this .getACLInterceptor();
064:
065: //Setup the interceptor stack
066: CMSInterceptorStackFactory stackFactory = new CMSInterceptorStackFactory();
067: Interceptor[] interceptors = new Interceptor[1];
068: interceptors[0] = aclInterceptor;
069: JBossInterceptorStack stack = new JBossInterceptorStack(
070: interceptors);
071: stackFactory.setInterceptorStack(stack);
072:
073: this .service.setStackFactory(stackFactory);
074:
075: //Register the IdentityService with the JCR service
076: IdentityServiceController identityService = ((AuthorizationProviderImpl) aclInterceptor
077: .getAuthorizationManager().getProvider())
078: .getIdentityServiceController();
079: this .userModule = (UserModule) identityService
080: .getIdentityContext().getObject(
081: IdentityContext.TYPE_USER_MODULE);
082: }
083:
084: /**
085: *
086: */
087: public void tearDown() throws Exception {
088: super .tearDown();
089: this .userModule = null;
090: }
091:
092: /** @return */
093: protected ACLInterceptor getACLInterceptor() throws Exception {
094: ACLInterceptor aclInterceptor = (ACLInterceptor) new InitialContext()
095: .lookup("java:/portal/cms/ACLInterceptor");
096: return aclInterceptor;
097: }
098:
099: /** @param username */
100: protected void runAs(String username) throws Exception {
101: SessionFactory sessionFactory = (SessionFactory) new InitialContext()
102: .lookup("java:/SessionFactory");
103: Session session = sessionFactory.openSession();
104: Transaction tx = session.beginTransaction();
105: JCRCMS.getUserInfo().set(
106: this.userModule.findUserByUserName(username));
107: tx.commit();
108: session.close();
109: }
110: }
|