/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.felix.karaf.webconsole;

import java.io.IOException;
import java.security.GeneralSecurityException;
import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.LoginContext;

import org.apache.felix.webconsole.WebConsoleSecurityProvider;

public class JaasSecurityProvider implements WebConsoleSecurityProvider {

    private String realm;

    public String getRealm() {
        return realm;
    }

    public void setRealm(String realm) {
        this.realm = realm;
    }

    public Object authenticate(final String username, final String password) throws GeneralSecurityException {
        Subject subject = new Subject();
        LoginContext loginContext = new LoginContext(realm, subject, new CallbackHandler() {
            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                for (int i = 0; i < callbacks.length; i++) {
                    if (callbacks[i] instanceof NameCallback) {
                        ((NameCallback) callbacks[i]).setName(username);
                    } else if (callbacks[i] instanceof PasswordCallback) {
                        ((PasswordCallback) callbacks[i]).setPassword(password.toCharArray());
                    } else {
                        throw new UnsupportedCallbackException(callbacks[i]);
                    }
                }
            }
        });
        loginContext.login();
        return subject;
    }

    public void authorize(Object o, String s) throws GeneralSecurityException {
        throw new UnsupportedOperationException();
    }
}

@@ -872,55 +872,8 @@
 on;%0A
-import java.security.GeneralSecurityException;%0A
 impo
@@ -1604,42 +1604,28 @@
 rd) 
-throws GeneralSecurityException %7B%0A
+%7B%0A        try %7B%0A    
     
@@ -1657,24 +1657,28 @@
  Subject();%0A
+    
         Logi
@@ -1766,24 +1766,28 @@
             
+ 
+   
 public void 
@@ -1882,16 +1882,20 @@
         
+    
 for (int
@@ -1951,16 +1951,20 @@
         
+ 
+   
 if (call
@@ -1991,32 +1991,36 @@
 NameCallback) %7B%0A
+    
                 
@@ -2092,24 +2092,28 @@
             
+    
 %7D else if (c
@@ -2147,32 +2147,36 @@
 wordCallback) %7B%0A
+    
                 
@@ -2270,24 +2270,28 @@
             
+    
 %7D else %7B%0A   
@@ -2287,16 +2287,20 @@
  else %7B%0A
+    
         
@@ -2381,34 +2381,42 @@
                 
-%7D%0A
+    %7D%0A    
                 
@@ -2429,26 +2429,33 @@
         
-%7D%0A
+    %7D%0A   
         
 %7D);%0A    
@@ -2450,12 +2450,17 @@
     
+ 
 %7D);%0A
+    
     
@@ -2489,24 +2489,28 @@
 ();%0A        
+   
+ 
 return subje
@@ -2513,16 +2513,83 @@
 ubject;%0A
+        %7D catch (Exception e) %7B%0A            return null;%0A        %7D%0A
     %7D%0A%0A 
@@ -2598,20 +2598,23 @@
  public 
-void
+boolean
  authori
@@ -2640,91 +2640,29 @@
  s) 
-throws GeneralSecurityException %7B%0A        throw new UnsupportedOperationException()
+%7B%0A        return true
 ;%0A  

Update with latest change to the security interface for the webconsole