/**
 * $Revision$
 * $Date$
 *
 * Copyright (C) 2006 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution.
 */
package org.jivesoftware.openfire.clearspace;

import org.jivesoftware.openfire.auth.AuthProvider;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.user.UserNotFoundException;

/**
 * @author Daniel Henninger
 */
public class ClearspaceAuthProvider implements AuthProvider {
    public boolean isPlainSupported() {
        return true;
    }

    public boolean isDigestSupported() {
        return true;
    }

    public void authenticate(String username, String password) throws UnauthorizedException {
        // Nothing
    }

    public void authenticate(String username, String token, String digest) throws UnauthorizedException {
        // Nothing
    }

    public String getPassword(String username) throws UserNotFoundException, UnsupportedOperationException {
        return (username.equals("admin") ? "test" : "asdasdasdasd");
    }

    public void setPassword(String username, String password) throws UserNotFoundException, UnsupportedOperationException {
        // Nothing
    }

    public boolean supportsPasswordRetrieval() {
        return false;
    }
}

@@ -381,16 +381,99 @@
 eption;%0A
+import static org.jivesoftware.openfire.clearspace.ClearspaceManager.HttpType.GET;%0A
 import o
@@ -624,16 +624,250 @@
 vider %7B%0A
+    protected static final String URL_PREFIX = %22permissionService/%22;%0A%0A    private ClearspaceManager manager;%0A%0A    public ClearspaceAuthProvider() %7B%0A        // gets the manager%0A        manager = ClearspaceManager.getInstance();%0A    %7D%0A%0A
     publ
@@ -974,35 +974,36 @@
 %0A        return 
-tru
+fals
 e;%0A    %7D%0A%0A    pu
@@ -1094,34 +1094,437 @@
 n %7B%0A        
-// Nothing
+try %7B%0A            String path = URL_PREFIX + %22authenticate/%22 + username + %22/%22 + password;%0A            manager.executeRequest(GET, path);%0A        %7D catch (UnauthorizedException ue) %7B%0A            throw ue;%0A        %7D catch (Exception e) %7B%0A            // It is not supported exception, wrap it into an UnsupportedOperationException%0A            throw new UnsupportedOperationException(%22Unexpected error%22, e);%0A        %7D
 %0A    %7D%0A%0A    
@@ -1629,34 +1629,88 @@
 n %7B%0A        
-// Nothing
+throw new UnsupportedOperationException(%22Digest not supported%22);
 %0A    %7D%0A%0A    
@@ -1826,64 +1826,80 @@
     
-return (username.equals(%22admin%22) ? %22test%22 : %22asdasdasdas
+throw new UnsupportedOperationException(%22Password retrieval not supporte
 d%22);
@@ -2042,18 +2042,81 @@
     
-// Nothing
+throw new UnsupportedOperationException(%22Change Password not supported%22);
 %0A   

Create CSAuthProvider to integrate with Clearspace. JM-1224