1 25 26 package org.objectweb.easybeans.security.propagation.jonas; 27 28 import java.lang.reflect.InvocationTargetException ; 29 import java.lang.reflect.Method ; 30 31 import org.objectweb.easybeans.security.api.EZBSecurityContext; 32 import org.objectweb.easybeans.security.api.EZBSecurityCurrent; 33 34 38 public class JOnASSecurityCurrent implements EZBSecurityCurrent { 39 40 43 private static final String JONAS_SECURITY_CURRENT = "org.objectweb.security.context.SecurityCurrent"; 44 45 48 private static final String JONAS_SECURITY_CONTEXT = "org.objectweb.security.context.SecurityContext"; 49 50 51 54 private static Object jonasSecurityCurrent = initCurrent(); 55 56 57 61 private static Object initCurrent() { 62 63 Class jonasSecurityCurrentClass = null; 64 try { 65 jonasSecurityCurrentClass = Thread.currentThread().getContextClassLoader().loadClass(JONAS_SECURITY_CURRENT); 66 } catch (ClassNotFoundException e) { 67 throw new IllegalStateException ("Cannot load the '" + JONAS_SECURITY_CURRENT + "' class.", e); 68 } 69 70 Method m = null; 71 try { 72 m = jonasSecurityCurrentClass.getMethod("getCurrent"); 73 } catch (SecurityException e) { 74 throw new IllegalStateException ("Cannot get the method getCurrent on the JOnAS security context", e); 75 } catch (NoSuchMethodException e) { 76 throw new IllegalStateException ("Cannot get the method getCurrent on the JOnAS security context", e); 77 } 78 79 try { 80 return m.invoke(null); 81 } catch (IllegalArgumentException e) { 82 throw new IllegalStateException ("Cannot call getCallerPrincipal method on the JOnAS security context", e); 83 } catch (IllegalAccessException e) { 84 throw new IllegalStateException ("Cannot call getCallerPrincipal method on the JOnAS security context", e); 85 } catch (InvocationTargetException e) { 86 throw new IllegalStateException ("Cannot call getCallerPrincipal method on the JOnAS security context", e); 87 } 88 } 89 90 91 92 97 public EZBSecurityContext getSecurityContext() { 98 Method m = null; 99 try { 100 m = jonasSecurityCurrent.getClass().getMethod("getSecurityContext"); 101 } catch (SecurityException e) { 102 throw new IllegalStateException ("Cannot get the method getSecurityContext on the JOnAS security context", e); 103 } catch (NoSuchMethodException e) { 104 throw new IllegalStateException ("Cannot get the method getSecurityContext on the JOnAS security context", e); 105 } 106 107 Object jonasSecurityContext = null; 109 try { 110 jonasSecurityContext = m.invoke(jonasSecurityCurrent); 111 } catch (IllegalArgumentException e) { 112 throw new IllegalStateException ("Cannot call getSecurityContext method on the JOnAS security context", e); 113 } catch (IllegalAccessException e) { 114 throw new IllegalStateException ("Cannot call getSecurityContext method on the JOnAS security context", e); 115 } catch (InvocationTargetException e) { 116 throw new IllegalStateException ("Cannot call getSecurityContext method on the JOnAS security context", e); 117 } 118 119 if (jonasSecurityContext == null) { 121 Class securityContextClass = null; 123 try { 124 securityContextClass = Thread.currentThread().getContextClassLoader().loadClass(JONAS_SECURITY_CONTEXT); 125 } catch (ClassNotFoundException e) { 126 throw new IllegalStateException ("Cannot load the class '" + JONAS_SECURITY_CONTEXT + "'.", e); 127 } 128 try { 130 jonasSecurityContext = securityContextClass.newInstance(); 131 } catch (InstantiationException e) { 132 throw new IllegalStateException ("Cannot build an instance of the class '" + JONAS_SECURITY_CONTEXT + "'.", e); 133 } catch (IllegalAccessException e) { 134 throw new IllegalStateException ("Cannot build an instance of the class '" + JONAS_SECURITY_CONTEXT + "'.", e); 135 } 136 } 137 138 139 return new JOnASSecurityContext(jonasSecurityContext); 141 142 } 143 144 148 public void setSecurityContext(final EZBSecurityContext securityContext) { 149 } 151 152 156 public void setGlobalSecurityContext(final EZBSecurityContext securityContext) { 157 } 159 160 } 161 | Popular Tags |