package helpers;

import play.Play;
import play.libs.Codec;
import play.mvc.Http;

/**
 * @author jtremeaux
 */
public class BasicAuthHelper {
    public static void unauthorized(Http.Response response) {
        String realm = Play.configuration.getProperty("basicAuth.realm", "Secure Realm");
        response.status = Http.StatusCode.UNAUTHORIZED;
        response.setHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\"");
    }

    public static boolean checkAuthenticationHeaders(Http.Request request) {
        Http.Header authHeader = request.headers.get("authorization");
        if (authHeader != null) {
            String username = Play.configuration.getProperty("basicAuth.username");
            String password = Play.configuration.getProperty("basicAuth.password");
            if (username == null || password == null) {
                return true;
            }
            String expected = "Basic " + Codec.encodeBASE64(username + ":" + password);
            if (expected.equals(authHeader.value())) {
                return true;
            }
        }
        return false;
    }
}

@@ -513,117 +513,8 @@
 ) %7B%0A
-        Http.Header authHeader = request.headers.get(%22authorization%22);%0A        if (authHeader != null) %7B%0A    
     
@@ -593,28 +593,24 @@
 %22);%0A        
-   
- 
 String passw
@@ -673,28 +673,24 @@
 %22);%0A        
-    
 if (username
@@ -725,36 +725,32 @@
 ) %7B%0A            
-  
-  
 return true;%0A   
@@ -746,37 +746,138 @@
 n true;%0A        
-    %7D
+%7D%0A        Http.Header authHeader = request.headers.get(%22authorization%22);%0A        if (authHeader != null) %7B
 %0A            Str

Allow plugin to be disabled