use of java.security.PrivilegedActionException in project wildfly by wildfly.
the class RoleAddingInterceptor method processInvocation.
public Object processInvocation(final InterceptorContext context) throws Exception {
final SecurityDomain securityDomain = context.getPrivateData(SecurityDomain.class);
Assert.checkNotNullParam("securityDomain", securityDomain);
final SecurityIdentity currentIdentity = securityDomain.getCurrentSecurityIdentity();
final RoleMapper mergeMapper = roleMapper.or((roles) -> currentIdentity.getRoles(category));
final SecurityIdentity newIdentity = currentIdentity.withRoleMapper(category, mergeMapper);
try {
return newIdentity.runAs(context);
} catch (PrivilegedActionException e) {
Throwable cause = e.getCause();
if (cause != null) {
if (cause instanceof Exception) {
throw (Exception) cause;
} else {
throw new RuntimeException(e);
}
} else {
throw e;
}
}
}
use of java.security.PrivilegedActionException in project wildfly by wildfly.
the class ExternalizableExternalizer method readObject.
@Override
public T readObject(ObjectInput input) throws IOException, ClassNotFoundException {
PrivilegedExceptionAction<T> action = new PrivilegedExceptionAction<T>() {
@Override
public T run() throws InstantiationException, IllegalAccessException {
return ExternalizableExternalizer.this.getTargetClass().newInstance();
}
};
try {
T object = WildFlySecurityManager.doChecked(action);
object.readExternal(input);
return object;
} catch (PrivilegedActionException e) {
throw new IOException(e.getCause());
}
}
use of java.security.PrivilegedActionException in project gerrit by GerritCodeReview.
the class Helper method kerberosOpen.
private DirContext kerberosOpen(final Properties env) throws LoginException, NamingException {
LoginContext ctx = new LoginContext("KerberosLogin");
ctx.login();
Subject subject = ctx.getSubject();
try {
return Subject.doAs(subject, new PrivilegedExceptionAction<DirContext>() {
@Override
public DirContext run() throws NamingException {
return new InitialDirContext(env);
}
});
} catch (PrivilegedActionException e) {
Throwables.throwIfInstanceOf(e.getException(), NamingException.class);
Throwables.throwIfInstanceOf(e.getException(), RuntimeException.class);
LdapRealm.log.warn("Internal error", e.getException());
return null;
} finally {
ctx.logout();
}
}
use of java.security.PrivilegedActionException in project jdk8u_jdk by JetBrains.
the class RMIConnectionImpl method addNotificationListener.
// MarshalledObject
@SuppressWarnings("rawtypes")
public void addNotificationListener(ObjectName name, ObjectName listener, MarshalledObject filter, MarshalledObject handback, Subject delegationSubject) throws InstanceNotFoundException, IOException {
checkNonNull("Target MBean name", name);
checkNonNull("Listener MBean name", listener);
final NotificationFilter filterValue;
final Object handbackValue;
final boolean debug = logger.debugOn();
final ClassLoader targetCl = getClassLoaderFor(name);
if (debug)
logger.debug("addNotificationListener" + "(ObjectName,ObjectName,NotificationFilter,Object)", "connectionId=" + connectionId + " unwrapping filter with target extended ClassLoader.");
filterValue = unwrap(filter, targetCl, defaultClassLoader, NotificationFilter.class, delegationSubject);
if (debug)
logger.debug("addNotificationListener" + "(ObjectName,ObjectName,NotificationFilter,Object)", "connectionId=" + connectionId + " unwrapping handback with target extended ClassLoader.");
handbackValue = unwrap(handback, targetCl, defaultClassLoader, Object.class, delegationSubject);
try {
final Object[] params = new Object[] { name, listener, filterValue, handbackValue };
if (debug)
logger.debug("addNotificationListener" + "(ObjectName,ObjectName,NotificationFilter,Object)", "connectionId=" + connectionId + ", name=" + name + ", listenerName=" + listener + ", filter=" + filterValue + ", handback=" + handbackValue);
doPrivilegedOperation(ADD_NOTIFICATION_LISTENER_OBJECTNAME, params, delegationSubject);
} catch (PrivilegedActionException pe) {
Exception e = extractException(pe);
if (e instanceof InstanceNotFoundException)
throw (InstanceNotFoundException) e;
if (e instanceof IOException)
throw (IOException) e;
throw newIOException("Got unexpected server exception: " + e, e);
}
}
use of java.security.PrivilegedActionException in project jdk8u_jdk by JetBrains.
the class RMIConnectionImpl method doPrivilegedOperation.
private Object doPrivilegedOperation(final int operation, final Object[] params, final Subject delegationSubject) throws PrivilegedActionException, IOException {
serverCommunicatorAdmin.reqIncoming();
try {
final AccessControlContext reqACC;
if (delegationSubject == null)
reqACC = acc;
else {
if (subject == null) {
final String msg = "Subject delegation cannot be enabled unless " + "an authenticated subject is put in place";
throw new SecurityException(msg);
}
reqACC = subjectDelegator.delegatedContext(acc, delegationSubject, removeCallerContext);
}
PrivilegedOperation op = new PrivilegedOperation(operation, params);
if (reqACC == null) {
try {
return op.run();
} catch (Exception e) {
if (e instanceof RuntimeException)
throw (RuntimeException) e;
throw new PrivilegedActionException(e);
}
} else {
return AccessController.doPrivileged(op, reqACC);
}
} catch (Error e) {
throw new JMXServerErrorException(e.toString(), e);
} finally {
serverCommunicatorAdmin.rspOutgoing();
}
}
Aggregations