1 22 package org.jboss.ejb.plugins; 23 24 import org.jboss.ejb.Container; 25 import org.jboss.invocation.Invocation; 26 import org.jboss.metadata.ApplicationMetaData; 27 import org.jboss.metadata.AssemblyDescriptorMetaData; 28 import org.jboss.metadata.BeanMetaData; 29 import org.jboss.metadata.SecurityIdentityMetaData; 30 import org.jboss.security.RunAsIdentity; 31 32 import java.util.Set ; 33 34 41 public class RunAsSecurityInterceptor extends AbstractInterceptor 42 { 43 protected RunAsIdentity runAsIdentity; 44 45 public RunAsSecurityInterceptor() 46 { 47 } 48 49 53 public void setContainer(Container container) 54 { 55 super.setContainer(container); 56 if (container != null) 57 { 58 BeanMetaData beanMetaData = container.getBeanMetaData(); 59 ApplicationMetaData application = beanMetaData.getApplicationMetaData(); 60 AssemblyDescriptorMetaData assemblyDescriptor = application.getAssemblyDescriptor(); 61 62 SecurityIdentityMetaData secMetaData = beanMetaData.getSecurityIdentityMetaData(); 63 if (secMetaData != null && secMetaData.getUseCallerIdentity() == false) 64 { 65 String roleName = secMetaData.getRunAsRoleName(); 66 String principalName = secMetaData.getRunAsPrincipalName(); 67 if( principalName == null ) 68 principalName = application.getUnauthenticatedPrincipal(); 69 Set extraRoleNames = assemblyDescriptor.getSecurityRoleNamesByPrincipal(principalName); 71 runAsIdentity = new RunAsIdentity(roleName, principalName, extraRoleNames); 72 } 73 } 74 } 75 76 public void start() throws Exception 78 { 79 super.start(); 80 } 81 82 public Object invokeHome(Invocation mi) throws Exception 83 { 84 88 SecurityActions.pushRunAsIdentity(runAsIdentity); 89 try 90 { 91 Object returnValue = getNext().invokeHome(mi); 92 return returnValue; 93 } 94 finally 95 { 96 SecurityActions.popRunAsIdentity(); 97 } 98 } 99 100 public Object invoke(Invocation mi) throws Exception 101 { 102 106 SecurityActions.pushRunAsIdentity(runAsIdentity); 107 try 108 { 109 Object returnValue = getNext().invoke(mi); 110 return returnValue; 111 } 112 finally 113 { 114 SecurityActions.popRunAsIdentity(); 115 } 116 } 117 118 } 119 | Popular Tags |