Create a gist now

Instantly share code, notes, and snippets.

WebSphere Application Server run as server
/**
* Run code with the server subject
* (having the authorization to do any administration operation)
*/
PrivilegedExceptionAction<Void> action = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() {
// YOUR CODE HERE
return null;
}
};
try {
// run the priviledged action as the system
ContextManagerFactory.getInstance().runAsSystem(action);
/*
Also possible:
Subject serverSubject = ContextManagerFactory.getInstance().getServerSubject();
WSSubject.doAs(serverSubject, action);
*/
} catch (PrivilegedActionException e) {
Throable thrownException = e.getCause();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment