use of java.security.PrivilegedAction in project jdk8u_jdk by JetBrains.
the class MetaData method getPrivateFieldValue.
static Object getPrivateFieldValue(Object instance, String name) {
Field field = fields.get(name);
if (field == null) {
int index = name.lastIndexOf('.');
final String className = name.substring(0, index);
final String fieldName = name.substring(1 + index);
field = AccessController.doPrivileged(new PrivilegedAction<Field>() {
public Field run() {
try {
Field field = Class.forName(className).getDeclaredField(fieldName);
field.setAccessible(true);
return field;
} catch (ClassNotFoundException exception) {
throw new IllegalStateException("Could not find class", exception);
} catch (NoSuchFieldException exception) {
throw new IllegalStateException("Could not find field", exception);
}
}
});
fields.put(name, field);
}
try {
return field.get(instance);
} catch (IllegalAccessException exception) {
throw new IllegalStateException("Could not get value of the field", exception);
}
}
use of java.security.PrivilegedAction in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method checkMBeanTrustPermission.
private static void checkMBeanTrustPermission(final Class<?> theClass) throws SecurityException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
Permission perm = new MBeanTrustPermission("register");
PrivilegedAction<ProtectionDomain> act = new PrivilegedAction<ProtectionDomain>() {
public ProtectionDomain run() {
return theClass.getProtectionDomain();
}
};
ProtectionDomain pd = AccessController.doPrivileged(act);
AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] { pd });
sm.checkPermission(perm, acc);
}
}
use of java.security.PrivilegedAction in project jdk8u_jdk by JetBrains.
the class Queue method dispatchEvent.
/**
* Dispatches an event. The manner in which the event is
* dispatched depends upon the type of the event and the
* type of the event's source object:
*
* <table border=1 summary="Event types, source types, and dispatch methods">
* <tr>
* <th>Event Type</th>
* <th>Source Type</th>
* <th>Dispatched To</th>
* </tr>
* <tr>
* <td>ActiveEvent</td>
* <td>Any</td>
* <td>event.dispatch()</td>
* </tr>
* <tr>
* <td>Other</td>
* <td>Component</td>
* <td>source.dispatchEvent(AWTEvent)</td>
* </tr>
* <tr>
* <td>Other</td>
* <td>MenuComponent</td>
* <td>source.dispatchEvent(AWTEvent)</td>
* </tr>
* <tr>
* <td>Other</td>
* <td>Other</td>
* <td>No action (ignored)</td>
* </tr>
* </table>
* <p>
* @param event an instance of <code>java.awt.AWTEvent</code>,
* or a subclass of it
* @throws NullPointerException if <code>event</code> is <code>null</code>
* @since 1.2
*/
protected void dispatchEvent(final AWTEvent event) {
final Object src = event.getSource();
final PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
public Void run() {
// dispatch the event straight away.
if (fwDispatcher == null || isDispatchThreadImpl()) {
dispatchEventImpl(event, src);
} else {
fwDispatcher.scheduleDispatch(new Runnable() {
@Override
public void run() {
dispatchEventImpl(event, src);
}
});
}
return null;
}
};
final AccessControlContext stack = AccessController.getContext();
final AccessControlContext srcAcc = getAccessControlContextFrom(src);
final AccessControlContext eventAcc = event.getAccessControlContext();
if (srcAcc == null) {
javaSecurityAccess.doIntersectionPrivilege(action, stack, eventAcc);
} else {
javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Void>() {
public Void run() {
javaSecurityAccess.doIntersectionPrivilege(action, eventAcc);
return null;
}
}, stack, srcAcc);
}
}
use of java.security.PrivilegedAction in project jdk8u_jdk by JetBrains.
the class IIORegistry method registerInstalledProviders.
private void registerInstalledProviders() {
/*
We need to load installed providers from the
system classpath (typically the <code>lib/ext</code>
directory in in the Java installation directory)
in the privileged mode in order to
be able read corresponding jar files even if
file read capability is restricted (like the
applet context case).
*/
PrivilegedAction doRegistration = new PrivilegedAction() {
public Object run() {
Iterator categories = getCategories();
while (categories.hasNext()) {
Class<IIOServiceProvider> c = (Class) categories.next();
for (IIOServiceProvider p : ServiceLoader.loadInstalled(c)) {
registerServiceProvider(p);
}
}
return this;
}
};
AccessController.doPrivileged(doRegistration);
}
use of java.security.PrivilegedAction in project admin-console-beta by connexta.
the class GraphQLServlet method query.
private void query(String query, String operationName, Map<String, Object> variables, GraphQLSchema schema, HttpServletRequest req, HttpServletResponse resp, GraphQLContext context) throws IOException {
if (Subject.getSubject(AccessController.getContext()) == null && context.getSubject().isPresent()) {
Subject.doAs(context.getSubject().get(), new PrivilegedAction<Void>() {
@Override
@SneakyThrows
public Void run() {
query(query, operationName, variables, schema, req, resp, context);
return null;
}
});
} else {
runListeners(operationListeners, l -> runListener(l, it -> it.beforeGraphQLOperation(context, operationName, query, variables)));
ExecutionResult executionResult = new GraphQL(schema, getQueryExecutionStrategy(), getMutationExecutionStrategy()).execute(query, operationName, context, transformVariables(schema, query, variables));
List<GraphQLError> errors = executionResult.getErrors();
Object data = executionResult.getData();
String response = mapper.writeValueAsString(createResultFromDataAndErrors(data, errors));
resp.setContentType(APPLICATION_JSON_UTF8);
resp.setStatus(STATUS_OK);
resp.getWriter().write(response);
if (errorsPresent(errors)) {
runListeners(operationListeners, l -> l.onFailedGraphQLOperation(context, operationName, query, variables, data, errors));
} else {
runListeners(operationListeners, l -> l.onSuccessfulGraphQLOperation(context, operationName, query, variables, data));
}
}
}
Aggregations