/*
* JBoss, Home of Professional Open Source
* Copyright 2005, 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.jms.server.container;
import java.security.AccessController;
import java.security.Principal;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import javax.security.auth.Subject;
import java.util.Set;
import org.jboss.security.SecurityAssociation;
import org.jboss.security.SecurityContext;
import org.jboss.security.SecurityContextAssociation;
import org.jboss.jms.server.SecurityStore;
import org.jboss.jms.server.security.SecurityMetadata;
import org.jboss.jms.server.security.CheckType;
import java.security.Principal;
import javax.jms.JMSSecurityException;
/** A collection of privileged actions for this package
* @author Scott.Stark@jboss.org
* @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
* @author <a href="mailto:anil.saldhana@jboss.com">anil saldhana</a>
* @author <a href="mailto:hgao@redhat.com">Howard Gao</a>
* @version $Revison: 1.0$
*/
class SecurityActions
{
static SecurityContext getSecurityContext()
{
return AccessController.doPrivileged(new PrivilegedAction<SecurityContext>(){
public SecurityContext run()
{
return SecurityContextAssociation.getSecurityContext();
}});
}
static void setSecurityContext(final SecurityContext sc)
{
AccessController.doPrivileged(new PrivilegedAction<Object>(){
public Object run()
{
SecurityContextAssociation.setSecurityContext(sc);
return null;
}});
}
static SecurityMetadata getSecurityMetadata( final SecurityStore sm,
final boolean isQueue,
final String name )
{
return AccessController.doPrivileged(new PrivilegedAction<SecurityMetadata>() {
public SecurityMetadata run() {
return sm.getSecurityMetadata(isQueue, name);
}
});
}
static void authenticate( final SecurityStore sm,
final String username,
final String password ) throws JMSSecurityException
{
try
{
AccessController.doPrivileged(new PrivilegedExceptionAction()
{
public Object run() throws Exception {
sm.authenticate(username, password);
return null;
}
});
}
catch( PrivilegedActionException pae )
{
throw new JMSSecurityException(pae.toString());
}
}
static public boolean authorize( final SecurityStore sm,
final String username,
final Set principals,
final CheckType checkType ) throws JMSSecurityException
{
try
{
return AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>() {
public Boolean run() throws Exception {
return sm.authorize(username, principals, checkType);
}
});
}
catch( PrivilegedActionException pae )
{
throw new JMSSecurityException(pae.toString());
}
}
}