package com.st.openfire.auth;

import org.jivesoftware.openfire.auth.AuthProvider;
import org.jivesoftware.openfire.auth.ConnectionException;
import org.jivesoftware.openfire.auth.InternalUnauthenticatedException;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CustomAuthProvider implements AuthProvider {

final static Logger logger = LoggerFactory.getLogger(CustomAuthProvider.class);

public void authenticate(String userName, String passWord) throws UnauthorizedException, ConnectionException, InternalUnauthenticatedException {
    
		boolean isUserAuthorized;
        logger.info("authenticate() - starts");

         if (userName == null || passWord == null) {
                throw new UnauthorizedException();
        }

		/*
		* Write custom authentication code here. Based on it, user is authenticated.
		*/
       
        logger.info("authenticate() - ends");

    if( isUserAuthorized == false){
         throw new UnauthorizedException();
}
 }
    
public void authenticate(String arg0, String arg1, String arg2) throws UnauthorizedException, ConnectionException,InternalUnauthenticatedException {
        throw new UnauthorizedException();
    }

    public String getPassword(String arg0) throws UserNotFoundException,UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    public boolean isDigestSupported() {
        return false;
    }

    public boolean isPlainSupported() {
        return true;
    }

    public void setPassword(String arg0, String arg1) throws UserNotFoundException, UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    public boolean supportsPasswordRetrieval() {
        return false;
    }
}
