Re: [play-framework] Java Action Composition (for Auth): Return unauthorized

20 views
Skip to first unread message

Will Sargent

unread,
Jan 5, 2018, 9:47:08 PM1/5/18
to play-fr...@googlegroups.com
You need to return a CompletableFuture.completedFuture() with a play.mvc.Result in the bit that says "Not Logged in"


You can get unauthorized from play.mvc.Results:





On Fri, Dec 29, 2017 at 10:12 AM, Gunnar Beushausen <in...@innocommerce.de> wrote:
Hi,

i would like to use Action Composition to check every request, if a Bearer Token is present. If it's not present, the action should not be delegated to the target, but it should return a 401. Since the Apis changed so much in the last years, i'm not sure how to do it. My pseudo Code looks like this:


public class AuthAction extends play.mvc.Action.Simple {
   
@Override
   
public CompletionStage<Result> call(Http.Context ctx) {
       
if(ctx.request().getHeaders().get(SecurityController.AUTH_TOKEN_HEADER).isPresent()) {
           
String header = ctx.request().getHeaders().get(SecurityController.AUTH_TOKEN_HEADER).get();
           
System.out.println("Test: " + header);

       
} else {
           
//Not Logged in
       
}

       
return delegate.call(ctx);
   
}
}


What do i need to add to return a 401 Result?

Thanks.

Gunnar

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/a64b8f37-fe35-4fa6-b8e5-8d57767964d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages