FileDocCategorySizeDatePackage
CommonServerSecurityPipe.javaAPI DocGlassfish v2 API9965Tue Jun 05 04:58:38 BST 2007com.sun.enterprise.webservice

CommonServerSecurityPipe

public class CommonServerSecurityPipe extends com.sun.xml.ws.api.pipe.helper.AbstractFilterPipeImpl
This pipe is used to do 196 security

Fields Summary
protected static final Logger
_logger
protected static final com.sun.enterprise.util.LocalStringManagerImpl
localStrings
private final boolean
isHttpBinding
private com.sun.enterprise.security.jmac.config.PipeHelper
helper
Constructors Summary
CommonServerSecurityPipe(Map props, com.sun.xml.ws.api.pipe.Pipe next, boolean isHttpBinding)


         
			       

        super(next);

	props.put(PipeConstants.SECURITY_PIPE,this);

	this.helper = new PipeHelper(PipeConstants.SOAP_LAYER,props,null);

        this.isHttpBinding = isHttpBinding;
       
    
protected CommonServerSecurityPipe(CommonServerSecurityPipe that, com.sun.xml.ws.api.pipe.PipeCloner cloner)


        super(that, cloner);
        // we can share the helper for all pipes so that the remove 
        // registration (in server side) can be done properly
        this.helper = that.helper;

        this.isHttpBinding = that.isHttpBinding;

    
Methods Summary
public com.sun.xml.ws.api.pipe.Pipecopy(com.sun.xml.ws.api.pipe.PipeCloner cloner)
This is used in creating subsequent pipes.

        return new CommonServerSecurityPipe(this, cloner);
    
private static javax.security.auth.SubjectgetClientSubject(com.sun.xml.ws.api.message.Packet p)

	
	Subject s = null;
	
	if (p != null) {

	    s =(Subject) 
		p.invocationProperties.get(PipeConstants.CLIENT_SUBJECT);

	}
	if (s == null) {
	    
	    s = PipeHelper.getClientSubject();
	    
	    if (p != null) {
		p.invocationProperties.put(PipeConstants.CLIENT_SUBJECT,s);
	    }
	}

	return s;
    
public voidpreDestroy()
This method is called once in server side and at most one in client side.

	helper.disable();
    
public com.sun.xml.ws.api.message.Packetprocess(com.sun.xml.ws.api.message.Packet request)


        if (isHttpBinding) {
            return next.process(request);
        }
        
        Packet response = null;

        try {

            response = processRequest(request);

        } catch(Exception e) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Failure in security pipe process", e);
            }
            response = helper.makeFaultResponse(response,e);
        }

        return response;
    
private com.sun.xml.ws.api.message.PacketprocessRequest(com.sun.xml.ws.api.message.Packet request)


        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,"ws.error_validate_request", 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) {
			if (e instanceof AuthException){
			    _logger.log(Level.SEVERE,"ws.error_next_pipe", e);
			}
			response = helper.getFaultResponse
			    (validatedRequest,info.getResponsePacket(),e);
		    }
		} else {
		    try {
			response = (Packet)Subject.doAsPrivileged
			    (clientSubject,new PrivilegedExceptionAction() {
				public Object run() throws Exception {
				    // proceed to invoke the endpoint
				    return next.process(validatedRequest);
				}
			    }, null);
		    } catch (PrivilegedActionException pae) {
		        Throwable cause = pae.getCause();
			if (cause instanceof AuthException){
			    _logger.log(Level.SEVERE,"ws.error_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,"",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;
    
private com.sun.xml.ws.api.message.PacketprocessResponse(com.sun.enterprise.security.jmac.PacketMessageInfo info, ServerAuthContext sAC, javax.security.auth.Subject serverSubject)

        
        AuthStatus status;

	try {

	    status = sAC.secureResponse(info, serverSubject);

	} catch (Exception e) {
	    if (e instanceof AuthException) {
		if (_logger.isLoggable(Level.INFO)) {
		    _logger.log(Level.INFO, "ws.error_secure_response", e);
		}
	    } else {
		_logger.log(Level.SEVERE, "ws.error_secure_response", e);
	    }
    
	    return helper.makeFaultResponse(info.getResponsePacket(),e);
	}

	if (_logger.isLoggable(Level.FINE)) {
	    _logger.log(Level.FINE,"ws.status_secure_response", status);
	}

	return info.getResponsePacket();