Search in sources :

Example 71 with PrivilegedExceptionAction

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;
}
Also used : ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) MultiException(org.glassfish.hk2.api.MultiException) PrivilegedActionException(java.security.PrivilegedActionException) ExecutionException(java.util.concurrent.ExecutionException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

Example 72 with PrivilegedExceptionAction

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) EventListener(org.glassfish.api.event.EventListener) DelegatingClassLoader(org.glassfish.internal.api.DelegatingClassLoader) PrivilegedActionException(java.security.PrivilegedActionException) MalformedURLException(java.net.MalformedURLException)

Example 73 with PrivilegedExceptionAction

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;
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) WebServiceException(javax.xml.ws.WebServiceException) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Subject(javax.security.auth.Subject) PrivilegedActionException(java.security.PrivilegedActionException) AuthException(javax.security.auth.message.AuthException) WebServiceException(javax.xml.ws.WebServiceException) PacketMapMessageInfo(com.sun.enterprise.security.jmac.provider.PacketMapMessageInfo) AuthStatus(javax.security.auth.message.AuthStatus) PacketMessageInfo(com.sun.enterprise.security.jmac.provider.PacketMessageInfo)

Example 74 with PrivilegedExceptionAction

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);
    }
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) PacketMapMessageInfo(com.sun.enterprise.security.jmac.provider.PacketMapMessageInfo) Tube(com.sun.xml.ws.api.pipe.Tube) WebServiceException(javax.xml.ws.WebServiceException) AuthStatus(javax.security.auth.message.AuthStatus) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) NextAction(com.sun.xml.ws.api.pipe.NextAction) Subject(javax.security.auth.Subject) PrivilegedActionException(java.security.PrivilegedActionException) AuthException(javax.security.auth.message.AuthException) WebServiceException(javax.xml.ws.WebServiceException)

Example 75 with PrivilegedExceptionAction

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;
}
Also used : Implementor(com.sun.xml.rpc.spi.runtime.Implementor) PrivilegedActionException(java.security.PrivilegedActionException) StreamingHandler(com.sun.xml.rpc.spi.runtime.StreamingHandler) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) SOAPMessage(javax.xml.soap.SOAPMessage) PrivilegedActionException(java.security.PrivilegedActionException) Tie(com.sun.xml.rpc.spi.runtime.Tie) SOAPMessageContext(com.sun.xml.rpc.spi.runtime.SOAPMessageContext)

Aggregations

PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)387 IOException (java.io.IOException)199 PrivilegedActionException (java.security.PrivilegedActionException)135 Test (org.junit.Test)104 Connection (org.apache.hadoop.hbase.client.Connection)81 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)76 Table (org.apache.hadoop.hbase.client.Table)62 TableName (org.apache.hadoop.hbase.TableName)57 Result (org.apache.hadoop.hbase.client.Result)56 Scan (org.apache.hadoop.hbase.client.Scan)55 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)53 Delete (org.apache.hadoop.hbase.client.Delete)48 InterruptedIOException (java.io.InterruptedIOException)47 Cell (org.apache.hadoop.hbase.Cell)38 CellScanner (org.apache.hadoop.hbase.CellScanner)38 Configuration (org.apache.hadoop.conf.Configuration)36 File (java.io.File)33 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)33 Path (org.apache.hadoop.fs.Path)23 ArrayList (java.util.ArrayList)22