package org.gridlab.gridsphere.services.core.security.auth.modules.impl;

import org.gridlab.gridsphere.portlet.User;
import org.gridlab.gridsphere.services.core.security.auth.AuthorizationException;
import org.gridlab.gridsphere.services.core.security.auth.modules.LoginAuthModule;
import org.gridlab.gridsphere.services.core.security.auth.modules.impl.descriptor.AuthModuleDefinition;

import java.util.Map;

/**
 * @author <a href="mailto:novotny@aei.mpg.de">Jason Novotny</a>
 * @version $Id$
 */
public abstract class BaseAuthModule {

    protected Map attributes = null;
    protected AuthModuleDefinition moduleDef = null;

    public BaseAuthModule(AuthModuleDefinition moduleDef) {
        this.moduleDef = moduleDef;
    }

    public String getAttribute(String name) {
        return (String) attributes.get(name);
    }

    public Map getAttributes() {
        return attributes;
    }

    public void setAttributes(Map attributes) {
        this.attributes = attributes;
    }

    public String getModuleName() {
        return moduleDef.getModuleName();
    }

    public String getModuleDescription() {
        return moduleDef.getModuleDescription();
    }

    public int getModulePriority() {
        return moduleDef.getModulePriority();
    }

    public boolean isModuleActive() {
        return moduleDef.getModuleActive();
    }
    
    public int compareTo(Object obj) {
        if ((obj != null) && (obj instanceof LoginAuthModule)) {
            LoginAuthModule l = (LoginAuthModule) obj;
            if (this.moduleDef.getModulePriority() < l.getModulePriority()) {
                return -1;
            } else if (this.moduleDef.getModulePriority() > l.getModulePriority()) {
                return 1;
            } else {
                return 0;
            }
        }
        throw new ClassCastException("Unable to compare supplied object to this module");
    }


}

@@ -384,26 +384,180 @@
 on;%0A
-%0Aimport java.util.
+import org.gridlab.gridsphere.core.persistence.castor.descriptor.ConfigParam;%0A%0Aimport java.util.Map;%0Aimport java.util.List;%0Aimport java.util.Iterator;%0Aimport java.util.Hash
 Map;
@@ -720,19 +720,28 @@
 utes = n
-ull
+ew HashMap()
 ;%0A    pr
@@ -884,16 +884,297 @@
 uleDef;%0A
+        List configList = moduleDef.getConfigParamList();%0A        Iterator it = configList.iterator();%0A        while (it.hasNext()) %7B%0A            ConfigParam param = (ConfigParam)it.next();%0A            attributes.put(param.getParamName(), param.getParamValue());%0A        %7D        %0A
     %7D%0A%0A 

put config params in attributes