Search in sources :

Example 21 with RequestData

use of org.simbasecurity.api.service.thrift.RequestData in project simba-os by cegeka.

the class JerseyBasicAuthenticationFilter method filter.

@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
    ContainerRequest containerRequest = (ContainerRequest) containerRequestContext.getRequest();
    Map<String, String> requestParameters = toMap(containerRequestContext.getUriInfo().getQueryParameters());
    List<String> auth = containerRequest.getRequestHeader("authorization");
    if (auth == null || auth.isEmpty()) {
        throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    }
    String[] credentials = decode(auth.get(0));
    requestParameters.put(AuthenticationConstants.USERNAME, credentials[0]);
    requestParameters.put(AuthenticationConstants.PASSWORD, credentials[1]);
    RequestData requestData = new RequestData(requestParameters, toMap(containerRequest.getRequestHeaders()), containerRequest.getAbsolutePath().toString(), simbaWebURL, null, /* SSO Token */
    null, /* Client IP */
    false, false, false, false, false, containerRequest.getMethod(), RequestUtil.HOST_SERVER_NAME, null, null);
    THttpClient tHttpClient = null;
    try {
        tHttpClient = new THttpClient(simbaWebURL + "/authenticationService");
        TProtocol tProtocol = new TJSONProtocol(tHttpClient);
        AuthenticationFilterService.Client authenticationClient = new AuthenticationFilterService.Client(tProtocol);
        ActionDescriptor actionDescriptor = authenticationClient.processRequest(requestData, "wsLoginChain");
        if (!actionDescriptor.getActionTypes().contains(ActionType.DO_FILTER_AND_SET_PRINCIPAL)) {
            throw new WebApplicationException(Response.Status.UNAUTHORIZED);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new WebApplicationException(e, Response.Status.UNAUTHORIZED);
    } finally {
        if (tHttpClient != null) {
            tHttpClient.close();
        }
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) AuthenticationFilterService(org.simbasecurity.api.service.thrift.AuthenticationFilterService) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) THttpClient(org.apache.thrift.transport.THttpClient) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) RequestData(org.simbasecurity.api.service.thrift.RequestData) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) THttpClient(org.apache.thrift.transport.THttpClient)

Example 22 with RequestData

use of org.simbasecurity.api.service.thrift.RequestData in project simba-os by cegeka.

the class ManagerSecurityInterceptor method preHandle.

public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    RequestData requestData = RequestUtil.createRequestData(request, SystemConfiguration.getSimbaWebURL());
    try {
        ActionDescriptor actionDescriptor = authenticationService().processRequest(requestData, SystemConfiguration.getManagerAuthorizationChainName());
        if (actionDescriptor.getActionTypes().contains(ActionType.DO_FILTER_AND_SET_PRINCIPAL)) {
            return true;
        }
    } catch (Exception ignored) {
        ignored.printStackTrace();
    }
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    return false;
}
Also used : RequestData(org.simbasecurity.api.service.thrift.RequestData) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) TTransportException(org.apache.thrift.transport.TTransportException)

Aggregations

RequestData (org.simbasecurity.api.service.thrift.RequestData)22 Test (org.junit.Test)15 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)14 THttpClient (org.apache.thrift.transport.THttpClient)12 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)9 SimbaCredentials (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials)9 SSOToken (org.simbasecurity.api.service.thrift.SSOToken)8 ActionDescriptorBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests)7 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)5 AuthenticationFilterService (org.simbasecurity.api.service.thrift.AuthenticationFilterService)4 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)3 TProtocol (org.apache.thrift.protocol.TProtocol)3 SimbaCredentialsBuilderForTests (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests)3 RequestDataBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.RequestDataBuilderForTests)3 IOException (java.io.IOException)2 RequestActionFactory (org.simbasecurity.common.filter.action.RequestActionFactory)2 SimbaPrincipal (org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal)2 UserPrincipal (com.sun.security.auth.UserPrincipal)1 Principal (java.security.Principal)1 ServletContext (javax.servlet.ServletContext)1