use of java.security.PrivilegedExceptionAction in project jersey by jersey.
the class EjbComponentProvider method registerEjbInterceptor.
private void registerEjbInterceptor() {
try {
final Object interceptor = new EjbComponentInterceptor(injectionManager);
initialContext = getInitialContext();
final EjbContainerUtil ejbUtil = EjbContainerUtilImpl.getInstance();
final ApplicationInfo appInfo = getApplicationInfo(ejbUtil);
final List<String> tempLibNames = new LinkedList<>();
for (ModuleInfo moduleInfo : appInfo.getModuleInfos()) {
final String jarName = moduleInfo.getName();
if (jarName.endsWith(".jar") || jarName.endsWith(".war")) {
final String moduleName = jarName.substring(0, jarName.length() - 4);
tempLibNames.add(moduleName);
final Object bundleDescriptor = moduleInfo.getMetaData(EjbBundleDescriptorImpl.class.getName());
if (bundleDescriptor instanceof EjbBundleDescriptorImpl) {
final Collection<EjbDescriptor> ejbs = ((EjbBundleDescriptorImpl) bundleDescriptor).getEjbs();
for (final EjbDescriptor ejb : ejbs) {
final BaseContainer ejbContainer = EjbContainerUtilImpl.getInstance().getContainer(ejb.getUniqueId());
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
@Override
public Object run() throws Exception {
final Method registerInterceptorMethod = BaseContainer.class.getDeclaredMethod("registerSystemInterceptor", java.lang.Object.class);
registerInterceptorMethod.setAccessible(true);
registerInterceptorMethod.invoke(ejbContainer, interceptor);
return null;
}
});
} catch (PrivilegedActionException pae) {
final Throwable cause = pae.getCause();
LOGGER.log(Level.WARNING, LocalizationMessages.EJB_INTERCEPTOR_BINDING_WARNING(ejb.getEjbClassName()), cause);
}
}
}
}
}
libNames.addAll(tempLibNames);
final Object interceptorBinder = initialContext.lookup("java:org.glassfish.ejb.container.interceptor_binding_spi");
// the name
if (interceptorBinder == null) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_BIND_API_NOT_AVAILABLE());
}
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
@Override
public Object run() throws Exception {
Method interceptorBinderMethod = interceptorBinder.getClass().getMethod("registerInterceptor", java.lang.Object.class);
interceptorBinderMethod.invoke(interceptorBinder, interceptor);
EjbComponentProvider.this.ejbInterceptorRegistered = true;
LOGGER.log(Level.CONFIG, LocalizationMessages.EJB_INTERCEPTOR_BOUND());
return null;
}
});
} catch (PrivilegedActionException pae) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_CONFIG_ERROR(), pae.getCause());
}
} catch (NamingException ex) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_BIND_API_NOT_AVAILABLE(), ex);
} catch (LinkageError ex) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_CONFIG_LINKAGE_ERROR(), ex);
}
}
use of java.security.PrivilegedExceptionAction in project intellij-community by JetBrains.
the class SystemClassLoaderAction method initSystemClassLoader.
private static synchronized void initSystemClassLoader() {
if (!sclSet) {
if (scl != null)
throw new IllegalStateException("recursive call");
sun.misc.Launcher l = sun.misc.Launcher.getLauncher();
if (l != null) {
Throwable oops = null;
scl = l.getClassLoader();
try {
PrivilegedExceptionAction a;
a = new SystemClassLoaderAction(scl);
scl = (ClassLoader) AccessController.doPrivileged(a);
} catch (PrivilegedActionException pae) {
oops = pae.getCause();
if (oops instanceof InvocationTargetException) {
oops = oops.getCause();
}
}
if (oops != null) {
if (oops instanceof Error) {
throw (Error) oops;
} else {
// wrap the exception
throw new Error(oops);
}
}
}
sclSet = true;
}
}
use of java.security.PrivilegedExceptionAction in project phoenix by apache.
the class SecureUserConnectionsTest method testMultipleInvocationsBySameUserAreEquivalent.
@Test
public void testMultipleInvocationsBySameUserAreEquivalent() throws Exception {
final HashSet<ConnectionInfo> connections = new HashSet<>();
final String princ1 = getUserPrincipal(1);
final File keytab1 = getUserKeytabFile(1);
UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(princ1, keytab1.getPath());
PrivilegedExceptionAction<Void> callable = new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
String url = joinUserAuthentication(BASE_URL, princ1, keytab1);
connections.add(ConnectionInfo.create(url).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
return null;
}
};
// Using the same UGI should result in two equivalent ConnectionInfo objects
ugi.doAs(callable);
assertEquals(1, connections.size());
verifyAllConnectionsAreKerberosBased(connections);
ugi.doAs(callable);
assertEquals(1, connections.size());
verifyAllConnectionsAreKerberosBased(connections);
}
use of java.security.PrivilegedExceptionAction in project sling by apache.
the class ProtectedFunctionMapper method getMapForFunction.
/**
* Creates an instance for this class, and stores the Method for the given
* EL function prefix and name. This method is used for the case when there
* is only one function in the EL expression.
*
* @param fnQName
* The EL function qualified name (including prefix)
* @param c
* The class containing the Java method
* @param methodName
* The name of the Java method
* @param args
* The arguments of the Java method
* @throws RuntimeException
* if no method with the given signature could be found.
*/
public static ProtectedFunctionMapper getMapForFunction(String fnQName, final Class c, final String methodName, final Class[] args) {
java.lang.reflect.Method method;
ProtectedFunctionMapper funcMapper;
if (SecurityUtil.isPackageProtectionEnabled()) {
funcMapper = (ProtectedFunctionMapper) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new ProtectedFunctionMapper();
}
});
try {
method = (java.lang.reflect.Method) AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws Exception {
return c.getDeclaredMethod(methodName, args);
}
});
} catch (PrivilegedActionException ex) {
throw new RuntimeException("Invalid function mapping - no such method: " + ex.getException().getMessage());
}
} else {
funcMapper = new ProtectedFunctionMapper();
try {
method = c.getDeclaredMethod(methodName, args);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Invalid function mapping - no such method: " + e.getMessage());
}
}
funcMapper.theMethod = method;
return funcMapper;
}
use of java.security.PrivilegedExceptionAction in project sling by apache.
the class PageContextImpl method proprietaryEvaluate.
/**
* Proprietary method to evaluate EL expressions. XXX - This method should
* go away once the EL interpreter moves out of JSTL and into its own
* project. For now, this is necessary because the standard machinery is too
* slow.
*
* @param expression
* The expression to be evaluated
* @param expectedType
* The expected resulting type
* @param pageContext
* The page context
* @param functionMap
* Maps prefix and name to Method
* @return The result of the evaluation
*/
public static Object proprietaryEvaluate(final String expression, final Class expectedType, final PageContext pageContext, final ProtectedFunctionMapper functionMap, final boolean escape) throws ELException {
Object retValue;
final ExpressionFactory exprFactory = JspFactory.getDefaultFactory().getJspApplicationContext(pageContext.getServletContext()).getExpressionFactory();
if (SecurityUtil.isPackageProtectionEnabled()) {
try {
retValue = AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws Exception {
ELContextImpl ctx = (ELContextImpl) pageContext.getELContext();
ctx.setFunctionMapper(new FunctionMapperImpl(functionMap));
ValueExpression ve = exprFactory.createValueExpression(ctx, expression, expectedType);
return ve.getValue(ctx);
}
});
} catch (PrivilegedActionException ex) {
Exception realEx = ex.getException();
if (realEx instanceof ELException) {
throw (ELException) realEx;
} else {
throw new ELException(realEx);
}
}
} else {
ELContextImpl ctx = (ELContextImpl) pageContext.getELContext();
ctx.setFunctionMapper(new FunctionMapperImpl(functionMap));
ValueExpression ve = exprFactory.createValueExpression(ctx, expression, expectedType);
retValue = ve.getValue(ctx);
}
if (escape && retValue != null) {
retValue = XmlEscape(retValue.toString());
}
return retValue;
}
Aggregations