Search in sources :

Example 1 with TestHttpServletResponseWrapper

use of org.javaee7.jaspic.wrapping.servlet.TestHttpServletResponseWrapper in project javaee7-samples by javaee-samples.

the class TestWrappingServerAuthModule method secureResponse.

@Override
public AuthStatus secureResponse(MessageInfo messageInfo, Subject serviceSubject) throws AuthException {
    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    // Unwrap the request
    if (request instanceof TestHttpServletRequestWrapper) {
        messageInfo.setRequestMessage(((TestHttpServletRequestWrapper) request).getRequest());
    }
    HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage();
    if (response instanceof TestHttpServletResponseWrapper) {
        messageInfo.setResponseMessage(((TestHttpServletResponseWrapper) response).getResponse());
    }
    return SEND_SUCCESS;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TestHttpServletRequestWrapper(org.javaee7.jaspic.wrapping.servlet.TestHttpServletRequestWrapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) TestHttpServletResponseWrapper(org.javaee7.jaspic.wrapping.servlet.TestHttpServletResponseWrapper)

Example 2 with TestHttpServletResponseWrapper

use of org.javaee7.jaspic.wrapping.servlet.TestHttpServletResponseWrapper in project javaee7-samples by javaee-samples.

the class TestWrappingServerAuthModule method validateRequest.

@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {
    try {
        handler.handle(new Callback[] { new CallerPrincipalCallback(clientSubject, "test"), new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) });
    } catch (IOException | UnsupportedCallbackException e) {
        throw (AuthException) new AuthException().initCause(e);
    }
    // Wrap the request - the resource to be invoked should get to see this
    messageInfo.setRequestMessage(new TestHttpServletRequestWrapper((HttpServletRequest) messageInfo.getRequestMessage()));
    // Wrap the response - the resource to be invoked should get to see this
    messageInfo.setResponseMessage(new TestHttpServletResponseWrapper((HttpServletResponse) messageInfo.getResponseMessage()));
    return SUCCESS;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CallerPrincipalCallback(javax.security.auth.message.callback.CallerPrincipalCallback) GroupPrincipalCallback(javax.security.auth.message.callback.GroupPrincipalCallback) TestHttpServletRequestWrapper(org.javaee7.jaspic.wrapping.servlet.TestHttpServletRequestWrapper) AuthException(javax.security.auth.message.AuthException) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) TestHttpServletResponseWrapper(org.javaee7.jaspic.wrapping.servlet.TestHttpServletResponseWrapper)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 TestHttpServletRequestWrapper (org.javaee7.jaspic.wrapping.servlet.TestHttpServletRequestWrapper)2 TestHttpServletResponseWrapper (org.javaee7.jaspic.wrapping.servlet.TestHttpServletResponseWrapper)2 IOException (java.io.IOException)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 AuthException (javax.security.auth.message.AuthException)1 CallerPrincipalCallback (javax.security.auth.message.callback.CallerPrincipalCallback)1 GroupPrincipalCallback (javax.security.auth.message.callback.GroupPrincipalCallback)1