All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.jts.enmasse.SecurityOutFaultInterceptor Maven / Gradle / Ivy

Go to download

EnMasse is a Web application that provides a RESTful implementation of Fortress' ANSI RBAC INCITS 359 engine.

There is a newer version: 1.0-RC35
Show newest version
/*
 * Copyright (c) 2009-2013, JoshuaTree. All Rights Reserved.
 */
package us.jts.enmasse;

import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.interceptor.security.AccessDeniedException;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.transport.http.AbstractHTTPDestination;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Utility for EnMasse Server.  This class is thread safe.
 *
 * @author Shawn McKinney
 */

public class SecurityOutFaultInterceptor extends AbstractPhaseInterceptor
{
    public SecurityOutFaultInterceptor()
    {
        super(Phase.PRE_STREAM);

    }

    public void handleMessage(Message message) throws Fault
    {
        Fault fault = (Fault) message.getContent(Exception.class);
        Throwable ex = fault.getCause();
        if (!(ex instanceof SecurityException))
        {
            throw new RuntimeException("Security Exception is expected:" + ex);
        }

        HttpServletResponse response = (HttpServletResponse) message.getExchange().getInMessage()
            .get(AbstractHTTPDestination.HTTP_RESPONSE);
        int status = ex instanceof AccessDeniedException ? 403 : 401;
        response.setStatus(status);
        try
        {
            response.getOutputStream().write(ex.getMessage().getBytes());
            response.getOutputStream().flush();
        }
        catch (IOException iex)
        {
            // ignore
        }

        message.getInterceptorChain().abort();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy