package io.paradoxical.cassieq.discoverable.auth;

import io.dropwizard.auth.Authorizer;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.core.SecurityContext;
import java.security.Principal;

public class AccountSecurityContext<P extends Principal>  implements SecurityContext {
    private final P principal;
    private final Authorizer<P> authorizer;
    private final ContainerRequestContext requestContext;

    public AccountSecurityContext(
            final P principal,
            Authorizer<P> authorizer,
            ContainerRequestContext requestContext) {

        this.principal = principal;
        this.authorizer = authorizer;
        this.requestContext = requestContext;
    }

    @Override
    public Principal getUserPrincipal() {
        return principal;
    }

    @Override
    public boolean isUserInRole(String role) {
        return authorizer.authorize(principal, role);
    }

    @Override
    public boolean isSecure() {
        return true;
    }

    @Override
    public String getAuthenticationScheme() {
        return "Signed";
    }
}

@@ -395,32 +395,24 @@
 nal 
-ContainerRequest
+Security
 Context 
 requ
@@ -403,31 +403,32 @@
 rityContext 
+p
 re
-quest
+vious
 Context;%0A%0A  
@@ -503,16 +503,22 @@
         
+final 
 Authoriz
@@ -551,32 +551,30 @@
     
-ContainerRequest
+final Security
 Context 
 requ
@@ -569,23 +569,24 @@
 Context 
+p
 re
-quest
+vious
 Context)
@@ -676,23 +676,24 @@
    this.
+p
 re
-quest
+vious
 Context 
@@ -698,15 +698,16 @@
 t = 
+p
 re
-quest
+vious
 Cont
@@ -994,12 +994,34 @@
 urn 
-true
+previousContext.isSecure()
 ;%0A  

Clean up the account security context