use of java.security.PrivilegedExceptionAction in project Payara by payara.
the class ActiveJmsResourceAdapter method instantiateMCF.
@Override
protected ManagedConnectionFactory instantiateMCF(final String mcfClass, final ClassLoader loader) throws Exception {
ManagedConnectionFactory mcf = null;
if (moduleName_.equals(ConnectorRuntime.DEFAULT_JMS_ADAPTER)) {
Object tmp = AccessController.doPrivileged(new PrivilegedExceptionAction() {
@Override
public Object run() throws Exception {
return instantiateManagedConnectionFactory(mcfClass, loader);
}
});
mcf = (ManagedConnectionFactory) tmp;
}
return mcf;
}
use of java.security.PrivilegedExceptionAction in project Payara by payara.
the class ConnectorsClassLoaderUtil method createRARClassLoader.
private ConnectorClassFinder createRARClassLoader(final ClassLoader parent, String moduleDir, final String moduleName, List<URI> appLibs) throws ConnectorRuntimeException {
ConnectorClassFinder cl = null;
try {
final DelegatingClassLoader.ClassFinder librariesCL = getLibrariesClassLoader(appLibs);
cl = (ConnectorClassFinder) AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws Exception {
final ConnectorClassFinder ccf = new ConnectorClassFinder(parent, moduleName, librariesCL);
if (processEnv.getProcessType().isEmbedded()) {
events.register(new EventListener() {
public void event(Event event) {
if (event.is(EventTypes.PREPARE_SHUTDOWN)) {
ccf.done();
}
}
});
}
return ccf;
}
});
} catch (Exception ex) {
_logger.log(Level.SEVERE, "error.creating.connector.classloader", ex);
ConnectorRuntimeException cre = new ConnectorRuntimeException(ex.getMessage());
cre.initCause(ex);
throw cre;
}
File file = new File(moduleDir);
try {
cl.appendURL(file.toURI().toURL());
appendJars(file, cl);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
return cl;
}
use of java.security.PrivilegedExceptionAction in project Payara by payara.
the class CommonServerSecurityPipe method processRequest.
private Packet processRequest(Packet request) throws Exception {
AuthStatus status = AuthStatus.SUCCESS;
PacketMessageInfo info = new PacketMapMessageInfo(request, new Packet());
// XXX at this time, we expect the server subject to be null
Subject serverSubject = (Subject) request.invocationProperties.get(PipeConstants.SERVER_SUBJECT);
// could change the request packet
ServerAuthContext sAC = helper.getServerAuthContext(info, serverSubject);
Subject clientSubject = getClientSubject(request);
final Packet validatedRequest;
try {
if (sAC != null) {
// client subject must not be null
// and when return status is SUCCESS, module
// must have called handler.handle(CallerPrincipalCallback)
status = sAC.validateRequest(info, clientSubject, serverSubject);
}
} catch (Exception e) {
_logger.log(Level.SEVERE, LogUtils.ERROR_REQUEST_VALIDATION, e);
WebServiceException wse = new WebServiceException(localStrings.getLocalString("enterprise.webservice.cantValidateRequest", "Cannot validate request for {0}", new Object[] { helper.getModelName() }), e);
// set status for audit
status = AuthStatus.SEND_FAILURE;
// if unable to determine if two-way will return empty response
return helper.getFaultResponse(info.getRequestPacket(), info.getResponsePacket(), wse);
} finally {
validatedRequest = info.getRequestPacket();
helper.auditInvocation(validatedRequest, status);
}
Packet response = null;
if (status == AuthStatus.SUCCESS) {
boolean authorized = false;
try {
helper.authorize(validatedRequest);
authorized = true;
} catch (Exception e) {
// not authorized, construct fault and proceded
response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), e);
}
if (authorized) {
// only do doAdPriv if SecurityManager is in effect
if (System.getSecurityManager() == null) {
try {
// proceed to invoke the endpoint
response = next.process(validatedRequest);
} catch (Exception e) {
_logger.log(Level.SEVERE, LogUtils.NEXT_PIPE, e);
response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), e);
}
} else {
try {
response = (Packet) Subject.doAsPrivileged(clientSubject, new PrivilegedExceptionAction() {
@Override
public Object run() throws Exception {
// proceed to invoke the endpoint
return next.process(validatedRequest);
}
}, null);
} catch (PrivilegedActionException pae) {
Throwable cause = pae.getCause();
_logger.log(Level.SEVERE, LogUtils.NEXT_PIPE, cause);
response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), cause);
}
}
}
// pipes are not supposed to return a null response packet
if (response == null) {
WebServiceException wse = new WebServiceException(localStrings.getLocalString("enterprise.webservice.nullResponsePacket", "Invocation of Service {0} returned null response packet", new Object[] { helper.getModelName() }));
response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), wse);
_logger.log(Level.SEVERE, LogUtils.EXCEPTION_THROWN, wse);
}
// secure response, including if it is a fault
if (sAC != null && response.getMessage() != null) {
info.setResponsePacket(response);
response = processResponse(info, sAC, serverSubject);
}
} else {
// validateRequest did not return success
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "ws.status_validate_request", status);
}
// even for one-way mep, may return response with non-empty message
response = info.getResponsePacket();
}
return response;
}
use of java.security.PrivilegedExceptionAction in project Payara by payara.
the class CommonServerSecurityTube method processRequest.
@Override
public NextAction processRequest(Packet request) {
try {
if (isHttpBinding) {
return doInvoke(super.next, request);
}
AuthStatus status = AuthStatus.SUCCESS;
info = new PacketMapMessageInfo(request, new Packet());
// XXX at this time, we expect the server subject to be null
serverSubject = (Subject) request.invocationProperties.get(PipeConstants.SERVER_SUBJECT);
// could change the request packet
sAC = helper.getServerAuthContext(info, serverSubject);
Subject clientSubject = getClientSubject(request);
final Packet validatedRequest;
try {
if (sAC != null) {
// client subject must not be null
// and when return status is SUCCESS, module
// must have called handler.handle(CallerPrincipalCallback)
status = sAC.validateRequest(info, clientSubject, serverSubject);
}
} catch (Exception e) {
_logger.log(Level.SEVERE, LogUtils.ERROR_REQUEST_VALIDATION, e);
WebServiceException wse = new WebServiceException(localStrings.getLocalString("enterprise.webservice.cantValidateRequest", "Cannot validate request for {0}", new Object[] { helper.getModelName() }), e);
// set status for audit
status = AuthStatus.SEND_FAILURE;
// if unable to determine if two-way will return empty response
Packet ret = helper.getFaultResponse(info.getRequestPacket(), info.getResponsePacket(), wse);
return doReturnWith(ret);
} finally {
validatedRequest = info.getRequestPacket();
helper.auditInvocation(validatedRequest, status);
}
Packet response = null;
if (status == AuthStatus.SUCCESS) {
boolean authorized = false;
try {
helper.authorize(validatedRequest);
authorized = true;
} catch (Exception e) {
// not authorized, construct fault and proceded
response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), e);
return doReturnWith(response);
}
if (authorized) {
// only do doAdPriv if SecurityManager is in effect
if (System.getSecurityManager() == null) {
try {
// proceed to invoke the endpoint
return doInvoke(super.next, validatedRequest);
} catch (Exception e) {
_logger.log(Level.SEVERE, LogUtils.NEXT_PIPE, e);
response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), e);
return doReturnWith(response);
}
} else {
try {
final Tube next = super.next;
NextAction action = (NextAction) Subject.doAsPrivileged(clientSubject, new PrivilegedExceptionAction() {
public Object run() throws Exception {
// proceed to invoke the endpoint
return doInvoke(next, validatedRequest);
}
}, null);
return action;
} catch (PrivilegedActionException pae) {
Throwable cause = pae.getCause();
_logger.log(Level.SEVERE, LogUtils.NEXT_PIPE, cause);
response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), cause);
return doReturnWith(response);
}
}
} else {
// if not authorized
// not authorized, construct fault and proceded
response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), new Exception("Client Not Authorized"));
return doReturnWith(response);
}
} else {
// validateRequest did not return success
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "ws.status_validate_request", status);
}
// even for one-way mep, may return response with non-empty message
response = info.getResponsePacket();
return doReturnWith(response);
}
} catch (Throwable t) {
if (!(t instanceof WebServiceException)) {
t = new WebServiceException(t);
}
return doThrow(t);
}
}
use of java.security.PrivilegedExceptionAction in project Payara by payara.
the class ServletSystemHandlerDelegate method processRequest.
/**
* The processRequest method is invoked with an object that
* implements com.sun.xml.rpc.spi.runtime.SOAPMessageContext.
* <p>
* When this method is called by the JAXRPCServletDelegate
* (on the server side of jaxrpc servlet container invocation processing)
* it must be called just before the call to implementor.getTie().handle(),
* and at the time of the request message and the following properties
* must have been set on the SOAPMessageContext.
* <p>
* com.sun.xml.rpc.server.http.MessageContextProperties.IMPLEMENTOR
* <br>
* This property must be set to the com.sun.xml.rpc.spi.runtime.Implementor
* object corresponding to the target endpoint.
* <p>
* com.sun.xml.rpc.server.http.MessageContextProperties.HTTP_SERVLET_REQUEST
* <br>
* This property must be
* set to the javax.servlet.http.HttpServletRequest object containing the
* JAXRPC invocation.
* <p>
* com.sun.xml.rpc.server.http.MessageContextProperties.HTTP_SERVLET_RESPONSE
* <br>
* This property must be
* set to the javax.servlet.http.HttpServletResponse object corresponding to
* the JAXRPC invocation.
* <p>
* com.sun.xml.rpc.server.MessageContextProperties.HTTP_SERVLET_CONTEXT
* <br>
* This property must be
* set to the javax.servlet.ServletContext object corresponding to web application
* in which the JAXRPC servlet is running.
* @param messageContext the SOAPMessageContext object containing the request
* message and the properties described above.
* @return true if processing by the delegate was such that the caller
* should continue with its normal message processing. Returns false if the
* processing by the delegate resulted in the messageContext containing a response
* message that should be returned without the caller proceding to its normal
* message processing.
* @throws java.lang.RuntimeException when the processing by the delegate failed,
* without yielding a response message. In this case, the expectation is that
* the caller will return a HTTP layer response code reporting that an internal
* error occured.
*/
public boolean processRequest(SOAPMessageContext messageContext) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("ws.processRequest");
}
final SOAPMessageContext finalMC = messageContext;
Implementor implementor = (Implementor) messageContext.getProperty(IMPLEMENTOR);
final Tie tie = implementor.getTie();
StreamingHandler handler = (StreamingHandler) implementor.getTie();
SOAPMessage request = finalMC.getMessage();
final ServerAuthContext sAC = config_.getAuthContext(handler, request);
boolean status = true;
try {
if (sAC != null) {
status = false;
// proceed to process message security
status = WebServiceSecurity.validateRequest(finalMC, sAC);
if (status) {
messageContext.setProperty(SERVER_AUTH_CONTEXT, sAC);
}
}
} catch (AuthException ae) {
_logger.log(Level.SEVERE, LogUtils.ERROR_REQUEST_VALIDATION, ae);
throw new RuntimeException(ae);
} finally {
WebServiceSecurity.auditInvocation(messageContext, endpoint_, status);
}
if (status) {
if (System.getSecurityManager() != null) {
// on this branch, the endpoint invocation and the
// processing of the response will be initiated from
// within the system handler delegate. delegate returns
// false so that dispatcher will not invoke the endpoint.
status = false;
try {
Subject.doAsPrivileged(SecurityContext.getCurrent().getSubject(), new PrivilegedExceptionAction() {
public Object run() throws Exception {
tie.handle(finalMC);
processResponse(finalMC);
return null;
}
}, null);
} catch (PrivilegedActionException pae) {
Throwable cause = pae.getCause();
if (cause instanceof AuthException) {
_logger.log(Level.SEVERE, LogUtils.ERROR_RESPONSE_SECURING, cause);
}
RuntimeException re = null;
if (cause instanceof RuntimeException) {
re = (RuntimeException) cause;
} else {
re = new RuntimeException(cause);
}
throw re;
}
}
}
return status;
}
Aggregations