001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.cms.security;
023:
024: import org.jboss.portal.cms.impl.jcr.command.ACLEnforcer;
025: import org.jboss.portal.jems.as.JNDI;
026: import org.jboss.portal.jems.as.system.AbstractJBossService;
027: import org.jboss.portal.security.PortalPermission;
028: import org.jboss.portal.security.PortalSecurityException;
029: import org.jboss.portal.security.spi.auth.PortalAuthorizationManager;
030:
031: import javax.security.auth.Subject;
032:
033: /**
034: * Created on : Jan 23, 2007
035: *
036: * @author Sohil Shah - sohil.shah@jboss.com
037: */
038: public class AuthorizationManagerImpl extends AbstractJBossService
039: implements AuthorizationManager {
040: /**
041: *
042: */
043: private ACLEnforcer enforcer = null;
044:
045: /**
046: *
047: */
048: private AuthorizationProvider provider = null;
049:
050: /**
051: *
052: */
053: private String jndiName = null;
054: private JNDI.Binding jndiBinding = null;
055:
056: /** @return */
057: public AuthorizationProvider getProvider() {
058: return provider;
059: }
060:
061: /** @param provider */
062: public void setProvider(AuthorizationProvider provider) {
063: this .provider = provider;
064: }
065:
066: /** @return */
067: public String getJNDIName() {
068: return this .jndiName;
069: }
070:
071: /** @param jndiName */
072: public void setJNDIName(String jndiName) {
073: this .jndiName = jndiName;
074: }
075:
076: /**
077: *
078: */
079: public void startService() throws Exception {
080: super .startService();
081:
082: //perform jndi registration for this service
083: if (this .jndiName != null) {
084: jndiBinding = new JNDI.Binding(jndiName, this );
085: jndiBinding.bind();
086: }
087:
088: //initialize the authorization/policy enforcer
089: enforcer = new ACLEnforcer(this );
090: }
091:
092: //---PortalAuthorizationManagerFactory implementation-----------------------------------------------
093: /**
094: *
095: */
096: public PortalAuthorizationManager getManager()
097: throws PortalSecurityException {
098: return this ;
099: }
100:
101: //---PortalAuthorizationManager implementation-------------------------------------------------------
102: /**
103: *
104: */
105: public boolean checkPermission(PortalPermission permission)
106: throws PortalSecurityException {
107: return this .enforcer.hasAccess(((CMSPermission) permission)
108: .getSecurityContext());
109: }
110:
111: /**
112: *
113: */
114: public boolean checkPermission(Subject checkedSubject,
115: PortalPermission permission) throws PortalSecurityException {
116: return this.checkPermission(permission);
117: }
118: }
|