use of com.sun.xml.ws.api.pipe.NextAction 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);
}
}
Aggregations