Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain HttpServletRequest @Context in DropWizard Auth

Tags:

dropwizard

I am using Basic Auth in Dropwizard 0.8 and I need to get access to the request context in my SimpleAuthenticator class, beyond the basic credentials.

Perhaps I need my own AuthFactory implementation to do this?

I want to implement basic access control for Basic Auth based on the resource path requested.

Thanks

Jon

like image 460
jdh961502 Avatar asked Nov 09 '22 14:11

jdh961502


1 Answers

    @PermitAll
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response getResponse(**@Context** SecurityContext context) {
        SimplePrincipal principal = (SimplePrincipal)context.getUserPrincipal();

        return Response.ok("{\"Hello\": \"" + principal.getUsername() + "\"}").build();
    }

Using @Context suffice for the basic Authorization atleast for Dropwizard version 0.9.2

like image 130
user6679850 Avatar answered Jan 04 '23 01:01

user6679850