
java.org.jboss.security.plugins.acl.JBossACLContext Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source
* Copyright 2007, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.security.plugins.acl;
import static org.jboss.security.authorization.AuthorizationContext.DENY;
import static org.jboss.security.authorization.AuthorizationContext.PERMIT;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.jboss.logging.Logger;
import org.jboss.security.acl.ACLContext;
import org.jboss.security.acl.ACLPermission;
import org.jboss.security.acl.ACLProvider;
import org.jboss.security.acl.config.ACLProviderEntry;
import org.jboss.security.authorization.AuthorizationException;
import org.jboss.security.authorization.EntitlementHolder;
import org.jboss.security.authorization.Permission;
import org.jboss.security.authorization.Resource;
import org.jboss.security.config.ACLInfo;
import org.jboss.security.config.ApplicationPolicy;
import org.jboss.security.config.ControlFlag;
import org.jboss.security.config.SecurityConfiguration;
import org.jboss.security.identity.Identity;
// $Id$
/**
* Default Implementation of ACLContext
*
* @author [email protected]
* @since Jan 30, 2008
* @version $Revision$
*/
public class JBossACLContext extends ACLContext
{
private static Logger log = Logger.getLogger(JBossACLContext.class);
private final boolean trace = log.isTraceEnabled();
public JBossACLContext(String name)
{
this.securityDomainName = name;
}
@Override
public EntitlementHolder getEntitlements(final Class clazz, final Resource resource,
final Identity identity) throws AuthorizationException
{
Set aggregateEntitlements = null;
try
{
initializeModules(resource, identity);
}
catch (PrivilegedActionException e1)
{
throw new RuntimeException(e1);
}
// Do a PrivilegedAction
try
{
aggregateEntitlements = AccessController.doPrivileged(new PrivilegedExceptionAction>()
{
public Set run() throws AuthorizationException
{
Set entitlements = invokeACL(clazz, resource, identity);
invokeTeardown();
return entitlements;
}
});
}
catch (PrivilegedActionException e)
{
Exception exc = e.getException();
if (trace)
log.trace("Error in authorize:", exc);
invokeTeardown();
throw ((AuthorizationException) exc);
}
final Set result = aggregateEntitlements;
return new EntitlementHolder()
{
public Set getEntitled()
{
return result;
}
};
}
/*
* (non-Javadoc)
*
* @see org.jboss.security.acl.ACLContext#authorize(org.jboss.security.authorization.Resource,
* org.jboss.security.identity.Identity, org.jboss.security.authorization.Permission)
*/
@Override
public int authorize(final Resource resource, final Identity identity, final Permission permission)
throws AuthorizationException
{
if (permission instanceof ACLPermission == false)
throw new AuthorizationException("Unable to process permission of type " + permission.getClass());
// instantiate and initialize the ACL modules.
try
{
initializeModules(resource, identity);
}
catch (PrivilegedActionException pae)
{
throw new RuntimeException(pae);
}
// invoke the module's isAccessGranted method to figure out whether identity has or not access to the resource.
Integer result;
try
{
result = (Integer) AccessController.doPrivileged(new PrivilegedExceptionAction
© 2015 - 2025 Weber Informatics LLC | Privacy Policy