DomainAttrs.java :  » Portal » Open-Portal » migration » modules » ldap » Java Open Source

Java Open Source » Portal » Open Portal 
Open Portal » migration » modules » ldap » DomainAttrs.java
package migration.modules.ldap;

import netscape.ldap.util.*;

import netscape.ldap.LDAPAttribute;
import netscape.ldap.LDAPAttributeSet;

import java.util.*;
import java.io.*;

public class DomainAttrs extends CommonXml {

  static OutputStreamWriter outFile;
  static String roleMigrationType;
  static String ldapUserPasswd;


  /* Netmail pertaining constants: */
  static final int NETMAIL_USER_SMTP_SERVER=90;
  static final int NETMAIL_USER_IMAP_SERVER=91;
  static final int NETMAIL_USER_DEFAULTMAILDOMAIN=92;
  static final int NETMAIL_ROOT_FOLDER=93;
  static final int NETMAIL_SENT_FOLDER=94;
  static final int NETMAIL_REPLY_WITHAUTHOR=95;
  static final int NETMAIL_REPLY_WITHBODY=96;
  static final int NETMAIL_REPLY_WITHDATE=97;
  static final int NETMAIL_INDENT_PREFIX=98;
  static final int NETMAIL_ADD_SIGNATURE=99;
  static final int NETMAIL_INITIAL_HDRS=100;
  static final int NETMAIL_INACTIVITY_INTERVAL=101;
  static final int NETMAIL_MAX_ATTACH_LEN=102;
  static final int NETMAIL_AUTOLOAD=103;
  static final int NETMAIL_AUTOSAVE=104;
  static final int NETMAIL_AUTOPURGE=105;
  static final int NETMAIL_AUTOFOLDERLOAD=106;
  static final int NETMAIL_MULTIPLE_RDW=107;//Multiple Read Windows
  static final int NETMAIL_HEADERS_PAGE=108;
  static final int NETMAIL_NEWEST_FIRST=109;
  static final int NETMAIL_LOGMSSGS=110;
  static final int NETMAIL_NOPREFSLIST=111;
  static final int NETMAIL_LDAPSERVERS=112;


  static HashMap ATTRIBUTES = new HashMap();
  public static void main(String args[]){

     String outputDir,ldifDir;


     ldifDir=new String();// Input file, the LDIF file to be converted....
     outputDir=new String();

  getNamingAttributes(System.getProperty("IMPORT_DIR"));
  getAMConfigProperties();

     InitHashMap();
     if(args.length==2){
      outputDir=args[1];
      ldifDir=args[0];
     }
     else if(args.length==1){
      outputDir=new String("/tmp/xml");
      ldifDir=args[0];
     }
     else if(args.length==0){
      System.out.println("Input file to be converted not specified!");
      System.out.println("Invokation Format is:java DomainAttrs ldif_directory output_dir");
      System.exit(1);
     }

     roleMigrationType=new String("org");

     if(System.getProperty("ROLE_TYPE")!=null){
      roleMigrationType=System.getProperty("ROLE_TYPE");
     }
     if(System.getProperty("LDAPUSER_PASSWD")!=null){
      ldapUserPasswd=System.getProperty("LDAPUSER_PASSWD");
     }

     try{
      outOrgsList_LDAP=new OutputStreamWriter(new FileOutputStream(outputDir+"/.orgslist"), "UTF-8");
      doConvert(ldifDir+"/application.ldif",outputDir+"/desktopDefaultType.xml");
      doConvert(ldifDir+"/domain.ldif",outputDir+"/desktopOrgAttrs.xml");
      doConvert(ldifDir+"/role.ldif",outputDir+"/desktopRoleAttrs.xml");
      setGlobalServiceAttr(outputDir+"/desktopGlobalServiceAttrs.xml");
      outOrgsList_LDAP.close();
     }catch(Exception e){
      System.out.println("Error:"+e.toString());
      e.printStackTrace();
     }
  }

  public static void doConvert(String ldiffile,String outputfile){
     LDIFRecord out;
     int count=0;
     LDIF l1;


     try{
      l1=new LDIF(ldiffile);
      outFile=new OutputStreamWriter(new FileOutputStream (outputfile), "UTF-8");

      //System.out.println("Converting LDIF entries corr. to users from file:"+ldiffile+".....\n");

      LDIFRecord tmp=l1.nextRecord();

      printHeader();
      while(tmp !=null){
        ProcessRecord(tmp);
        tmp=l1.nextRecord();
      }
      outFile.write("\n</Requests>");
      outFile.close();
      //System.out.println("Processed "+count+" entries");
      //System.out.println("Output available in file "+outputfile);
     }catch(Exception e){
      System.out.println("Error:"+e.toString());
      e.printStackTrace();
     }
  }
  static void printHeader() throws Exception {

    outFile.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
    outFile.write("\n<!--  PROPRIETARY/CONFIDENTIAL/ Use of this product is subject");
    outFile.write("\n to license terms. Copyright 2001 Sun Microsystems Inc.");
    outFile.write("Some preexisting portions Copyright 2001 Netscape");
    outFile.write("Communications Corp. All rights reserved. -->");
    outFile.write("\n<!DOCTYPE Requests PUBLIC \"-//Sun ONE//iDSAME 5.0 Admin CLI DTD//EN \" ");
    outFile.write("\"file:"+IDSAMEBaseDir+"/dtd/amAdmin.dtd\">");

    outFile.write("\n<Requests>");
    return;
  }

  static void ProcessRecord(LDIFRecord toConvert ) throws Exception{
    LDIFAttributeContent con;
    LDAPAttributeSet theAttrSet;
    String[] allAttrs;
    String attrName;
    String profileid,org,profiletype,rolename,parent;
    boolean tabContainerFound=false;
    boolean authModulesToAdd=false;
    boolean deriveAuthFromApp=true;
    String dn=new String();
    profileid=new String();

    LDAPAttribute[] attrList;

    profiletype=parent=rolename=null;
    org=getOrgName(toConvert.getDN());

    con=(LDIFAttributeContent)toConvert.getContent();
    attrList=con.getAttributes();
    theAttrSet = new LDAPAttributeSet(attrList);
    for(int i=0;i<attrList.length;++i){
      if ((attrList[i].getName()).equalsIgnoreCase("profiletype")){
        allAttrs=(((LDAPAttribute)(theAttrSet.getAttribute(attrList[i].getName()))).getStringValueArray());
        profiletype=allAttrs[0];
      }
      if ((attrList[i].getName()).equalsIgnoreCase("profileid")){
        allAttrs=(((LDAPAttribute)(theAttrSet.getAttribute(attrList[i].getName()))).getStringValueArray());
        profileid=allAttrs[0];
      }
      if ((attrList[i].getName()).equalsIgnoreCase("cn")){
        allAttrs=(((LDAPAttribute)(theAttrSet.getAttribute(attrList[i].getName()))).getStringValueArray());
        rolename=allAttrs[0];
      }
      if ((attrList[i].getName()).equalsIgnoreCase("parent")){
        allAttrs=(((LDAPAttribute)(theAttrSet.getAttribute(attrList[i].getName()))).getStringValueArray());
        parent=allAttrs[0];
      }
    }

    if(profiletype.equalsIgnoreCase("role"))
        dn=ConstructDN(profileid);

    if(!profiletype.equalsIgnoreCase("application")){

       for(int i=0;i<attrList.length;++i){
      attrName=attrList[i].getName();
      allAttrs=(((LDAPAttribute)(theAttrSet.getAttribute(attrList[i].getName()))).getStringValueArray()
);
      if(allAttrs == null || allAttrs.length <= 1) break;

      if(attrType(attrName) >= NETMAIL_USER_SMTP_SERVER && attrType(attrName) <= NETMAIL_LDAPSERVERS ) {
        if(profiletype.equalsIgnoreCase("domain"))
           outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
        if(profiletype.equalsIgnoreCase("role")){
          if(!roleMigrationType.equalsIgnoreCase("flat"))
               outFile.write("\n <OrganizationRequests DN=\""+dn.substring(1)+","+rootsuffix+"\">");
          else
            outFile.write("\n <RoleRequests DN=\"" + getMangledRoleWithOrgFromProfileId(profileid) + "," + rootsuffix + "\">");
        }
        outFile.write("\n   <ModifyServiceTemplate serviceName=\"SunPortalNetMailService\" schemaType=\"Dynamic\">");
        outFile.write("\n     <AttributeValuePair>");
        outFile.write(setNetMailServiceAttributes(attrName,allAttrs));
        outFile.write("\n     </AttributeValuePair>");
        outFile.write("\n   </ModifyServiceTemplate>");
        if((profiletype.equalsIgnoreCase("domain"))||((profiletype.equalsIgnoreCase("role"))&&(!roleMigrationType.equalsIgnoreCase("flat"))))
                outFile.write("\n </OrganizationRequests>");
                                else
                outFile.write("\n </RoleRequests>");
      }
      if(attrName.equalsIgnoreCase("iwtAuthLdap-server-at")){
        if(allAttrs[1].indexOf(":") != -1)  allAttrs[1]=allAttrs[1].substring(0,allAttrs[1].indexOf(":"));
        if(allAttrs[1].equalsIgnoreCase(hostname)){
            outOrgsList_LDAP.write("\n"+org);
        }
      }

      if(attrName.equalsIgnoreCase("iwtPlatform-locale-at") && profiletype.equalsIgnoreCase("domain")){
        outFile.write("\n<OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
        outFile.write("\n    <ModifyServiceTemplate serviceName=\"iPlanetAMAuthService\" schemaType=\"Organization\">");
        outFile.write("\n     <AttributeValuePair>");
        outFile.write("\n        <Attribute name=\"iplanet-am-auth-locale\"/>");
        outFile.write("\n        <Value>"+allAttrs[1]);
        outFile.write("</Value>");
        outFile.write("\n     </AttributeValuePair>");
        outFile.write("\n    </ModifyServiceTemplate>");
        outFile.write("\n</OrganizationRequests>");
      }

      if(attrName.equalsIgnoreCase("iwtDesktop-userSelectedProviders-at")){
        if(profiletype.equalsIgnoreCase("domain"))
           outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
        if(profiletype.equalsIgnoreCase("role")){
          if(!roleMigrationType.equalsIgnoreCase("flat"))
               outFile.write("\n <OrganizationRequests DN=\""+dn.substring(1)+","+rootsuffix+"\">");
          else
            outFile.write("\n <RoleRequests DN=\"" + getMangledRoleWithOrgFromProfileId(profileid) +
"," + rootsuffix + "\">");
        }
        outFile.write("\n   <ModifyServiceTemplate serviceName=\"SunPortalDesktopService\" schemaType=\"Dynamic\">");
        if(allAttrs.length > 1){
           for(int jk=1;jk<allAttrs.length;++jk){
            if(allAttrs[jk].equalsIgnoreCase("iwtTabProvider")){
              tabContainerFound=true;
              //System.out.println("Found...");
            }
           }
         }

        outFile.write("\n     <AttributeValuePair>");
        outFile.write("\n        <Attribute name=\"sunPortalDesktopDefaultChannelName\"/>");
        outFile.write("\n        <Value>");
        if(tabContainerFound==true)
          outFile.write("TemplateTabContainer");
        else
          outFile.write("TemplateTableContainer");
        outFile.write("</Value>");
        outFile.write("\n    </AttributeValuePair>");
        outFile.write("\n   </ModifyServiceTemplate>");
        if((profiletype.equalsIgnoreCase("domain"))||((profiletype.equalsIgnoreCase("role"))&&(!roleMigrationType.equalsIgnoreCase("flat"))))
                outFile.write("\n </OrganizationRequests>");
                                else
                outFile.write("\n </RoleRequests>");
      }
      if(attrName.equalsIgnoreCase("iwtUser-timezone-at")){
        if(profiletype.equalsIgnoreCase("domain"))
           outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
        if(profiletype.equalsIgnoreCase("role")){
          if(!roleMigrationType.equalsIgnoreCase("flat"))
               outFile.write("\n <OrganizationRequests DN=\""+dn.substring(1)+","+rootsuffix+"\">");
          else
            outFile.write("\n <RoleRequests DN=\"" + getMangledRoleWithOrgFromProfileId(profileid) +
"," + rootsuffix + "\">");

        }
        outFile.write("\n   <ModifyServiceTemplate serviceName=\"iPlanetAMUserService\" schemaType=\"Dynamic\">");
        outFile.write("\n     <AttributeValuePair>");
        outFile.write("\n        <Attribute name=\"preferredtimezone\"/>");
        outFile.write("\n        <Value>"+allAttrs[1]);
        outFile.write("</Value>");
        outFile.write("\n    </AttributeValuePair>");
        outFile.write("\n   </ModifyServiceTemplate>");
        if((profiletype.equalsIgnoreCase("domain"))||((profiletype.equalsIgnoreCase("role"))&&(!roleMigrationType.equalsIgnoreCase("flat"))))
                outFile.write("\n </OrganizationRequests>");
                                else
                outFile.write("\n </RoleRequests>");
      }
      if(attrName.equalsIgnoreCase("iwtUser-authModules-at")){
        if(profiletype.equalsIgnoreCase("domain"))
           outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
        if(profiletype.equalsIgnoreCase("role")){
          if(!roleMigrationType.equalsIgnoreCase("flat"))
               outFile.write("\n <OrganizationRequests DN=\""+dn.substring(1)+","+rootsuffix+"\">");
          else
            outFile.write("\n <RoleRequests DN=\"" + getMangledRoleWithOrgFromProfileId(profileid) +
"," + rootsuffix + "\">");

        }
        outFile.write("\n   <ModifyServiceTemplate serviceName=\"iPlanetAMUserService\" schemaType=\"Dynamic\">");
        outFile.write("\n     <AttributeValuePair>");
        outFile.write("\n        <Attribute name=\"iplanet-am-user-auth-modules\"/>");
        for(int jk=1;jk<allAttrs.length;++jk){
          outFile.write("\n        <Value>"+allAttrs[jk]);
          outFile.write("</Value>");
        }
        outFile.write("\n    </AttributeValuePair>");
        outFile.write("\n   </ModifyServiceTemplate>");
        if((profiletype.equalsIgnoreCase("domain"))||((profiletype.equalsIgnoreCase("role"))&&(!roleMigrationType.equalsIgnoreCase("flat"))))
                outFile.write("\n </OrganizationRequests>");
                                else
                outFile.write("\n </RoleRequests>");
      }
      if(attrName.equalsIgnoreCase("iwtDesktop-type-at")){
        if(profiletype.equalsIgnoreCase("domain"))
           outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
        if(profiletype.equalsIgnoreCase("role")) {
          if(!roleMigrationType.equalsIgnoreCase("flat"))
               outFile.write("\n <OrganizationRequests DN=\""+dn.substring(1)+","+rootsuffix+"\">");
          else
            outFile.write("\n <RoleRequests DN=\"" + getMangledRoleWithOrgFromProfileId(profileid) +
"," + rootsuffix + "\">");

        }
        outFile.write("\n   <ModifyServiceTemplate serviceName=\"SunPortalDesktopService\" schemaType=\"Dynamic\">");
        outFile.write("\n     <AttributeValuePair>");
        outFile.write("\n        <Attribute name=\"sunPortalDesktopType\"/>");
        outFile.write("\n        <Value>"+allAttrs[1]);
        outFile.write("</Value>");
        outFile.write("\n    </AttributeValuePair>");
        outFile.write("\n   </ModifyServiceTemplate>");
        if((profiletype.equalsIgnoreCase("domain"))||((profiletype.equalsIgnoreCase("role"))&&(!roleMigrationType.equalsIgnoreCase("flat"))))
                outFile.write("\n </OrganizationRequests>");
                                else
                outFile.write("\n </RoleRequests>");
      }

          int authModulesReg;
          if(attrName.equalsIgnoreCase("iwtAuth-authMenu-at")){
        deriveAuthFromApp=false;
        authModulesReg=allAttrs.length-1;
        for(int ik=1;ik<allAttrs.length;++ik){
          //if(allAttrs[ik].equalsIgnoreCase("LDAP") || allAttrs[ik].equalsIgnoreCase("Membership") || allAttrs[ik].equalsIgnoreCase("Anonymous")) authModulesReg--;
          if(allAttrs[ik].equalsIgnoreCase("LDAP") ||allAttrs[ik].equalsIgnoreCase("SKey")|| allAttrs[ik].equalsIgnoreCase("SecurID")|| allAttrs[ik].equalsIgnoreCase("Radius")) authModulesReg--;

        }
        if(profiletype.equalsIgnoreCase("role")) org=dn.substring(3);//Ignoring the initial o=,
        if((profiletype.equalsIgnoreCase("role") || profiletype.equalsIgnoreCase("domain"))&& authModulesReg > 0){

          for(int ik=1;ik<allAttrs.length;++ik){
            if(allAttrs[ik].equalsIgnoreCase("Anonymous")){
              outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
              outFile.write("\n    <RegisterServices>");
              outFile.write("\n     <Service_Name>iPlanetAMAuthAnonymousService</Service_Name>");
              outFile.write("\n    </RegisterServices>");
              outFile.write("\n </OrganizationRequests>");
            }
            if(allAttrs[ik].equalsIgnoreCase("Membership")){
              outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
              outFile.write("\n    <RegisterServices>");
              outFile.write("\n     <Service_Name>iPlanetAMAuthMembershipService</Service_Name>");
              outFile.write("\n    </RegisterServices>");
              outFile.write("\n </OrganizationRequests>");
            }
            if(allAttrs[ik].equalsIgnoreCase("Safeword")){
              outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
              outFile.write("\n    <RegisterServices>");
              outFile.write("\n     <Service_Name>iPlanetAMAuthSafeWordService</Service_Name>");
              outFile.write("\n    </RegisterServices>");
              outFile.write("\n </OrganizationRequests>");
            }
            if(allAttrs[ik].equalsIgnoreCase("Unix")){
              outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
              outFile.write("\n    <RegisterServices>");
              outFile.write("\n     <Service_Name>iPlanetAMAuthUnixService</Service_Name>");
              outFile.write("\n    </RegisterServices>");
              outFile.write("\n </OrganizationRequests>");
            }
            if(allAttrs[ik].equalsIgnoreCase("Cert")){
              outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
              outFile.write("\n    <RegisterServices>");
              outFile.write("\n     <Service_Name>iPlanetAMAuthCertService</Service_Name>");
              outFile.write("\n    </RegisterServices>");
              outFile.write("\n </OrganizationRequests>");
            }
          }
    
          Vector valuesAuth=new Vector();
          for(int ik=1;ik<allAttrs.length;++ik){
            if(allAttrs[ik].equalsIgnoreCase("LDAP")){
              valuesAuth.add(new String("LDAP"));
            }
            if(allAttrs[ik].equalsIgnoreCase("Radius")){
              valuesAuth.add(new String("Radius"));
            }
            if(allAttrs[ik].equalsIgnoreCase("Anonymous")){
              outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
              outFile.write("\n     <CreateServiceTemplate>");
              outFile.write("\n        <Service_Name>iPlanetAMAuthAnonymousService</Service_Name>");
              outFile.write("\n     </CreateServiceTemplate>");
              outFile.write("\n </OrganizationRequests>");
              valuesAuth.add(new String("Anonymous"));
            }
            if(allAttrs[ik].equalsIgnoreCase("Membership")){
              outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
              outFile.write("\n     <CreateServiceTemplate>");
              outFile.write("\n        <Service_Name>iPlanetAMAuthMembershipService</Service_Name>");
              outFile.write("\n     </CreateServiceTemplate>");
              outFile.write("\n </OrganizationRequests>");

              outFile.write("\n<OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
              outFile.write("\n    <ModifyServiceTemplate serviceName=\"iPlanetAMAuthMembershipService\" schemaType=\"Organization\">");
              outFile.write("\n        <AttributeValuePair>");
              outFile.write("\n               <Attribute name=\"iplanet-am-auth-membership-base-dn\"/>");
              outFile.write("\n               <Value>" +
              constructOrgDN(org, rootsuffix) + "</Value>");
              outFile.write("\n        </AttributeValuePair>");

              outFile.write("\n        <AttributeValuePair>");
                          outFile.write("\n            <Attribute name=\"iplanet-am-auth-membership-bind-passwd\"/>");
                          outFile.write("\n            <Value>"+ldapUserPasswd+"</Value>");
                           outFile.write("\n        </AttributeValuePair>");
                                 outFile.write("\n     </ModifyServiceTemplate>");
              outFile.write("\n </OrganizationRequests>");
              valuesAuth.add(new String("Membership"));
            }
            if(allAttrs[ik].equalsIgnoreCase("Safeword")){
              outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
              outFile.write("\n     <CreateServiceTemplate>");
              outFile.write("\n       <Service_Name>iPlanetAMAuthSafeWordService</Service_Name>");
              outFile.write("\n     </CreateServiceTemplate>");
              //outFile.write(getCreateServiceTemplate("iPlanetAMAuthRadiusService"));
              outFile.write("\n </OrganizationRequests>");
              valuesAuth.add(new String("SafeWord"));
            }
            if(allAttrs[ik].equalsIgnoreCase("Unix")){
              outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
              outFile.write("\n     <CreateServiceTemplate>");
              outFile.write("\n        <Service_Name>iPlanetAMAuthUnixService</Service_Name>");
              outFile.write("\n     </CreateServiceTemplate>");
              //outFile.write(getCreateServiceTemplate("iPlanetAMAuthUnixService"));
              outFile.write("\n </OrganizationRequests>");
              valuesAuth.add(new String("Unix"));
            }
            if(allAttrs[ik].equalsIgnoreCase("Cert")){
              outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
              outFile.write("\n     <CreateServiceTemplate>");
              outFile.write("\n       <Service_Name>iPlanetAMAuthCertService</Service_Name>");
              outFile.write("\n     </CreateServiceTemplate>");
              //outFile.write(getCreateServiceTemplate("iPlanetAMAuthCertService"));
              outFile.write("\n </OrganizationRequests>");
              valuesAuth.add(new String("Cert"));
            }
          }
          outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
          outFile.write("\n     <ModifyServiceTemplate serviceName=\"iPlanetAMAuthService\" schemaType=\"Organization\">");
          outFile.write("\n         <AttributeValuePair>");
          outFile.write("\n            <Attribute name=\"iplanet-am-auth-allowed-modules\"/>");
          for(int jk=0;jk<valuesAuth.size();++jk)
            outFile.write("\n            <Value>"+(String)(valuesAuth.elementAt(jk))+"</Value>");
          outFile.write("\n         </AttributeValuePair>");
          outFile.write("\n     </ModifyServiceTemplate>");
          outFile.write("\n </OrganizationRequests>");
        }
      }
      }
    }
    else{
       for(int i=0;i<attrList.length;++i){
      attrName=attrList[i].getName();
      allAttrs=(((LDAPAttribute)(theAttrSet.getAttribute(attrList[i].getName()))).getStringValueArray()
);
      if(attrName.equalsIgnoreCase("iwtUser-timezone-at")){
        outFile.write("\n   <SchemaRequests serviceName=\"iPlanetAMUserService\" SchemaType=\"Dynamic\">");
        outFile.write("\n  <ModifyDefaultValues>");
        outFile.write("\n     <AttributeValuePair>");
        outFile.write("\n        <Attribute name=\"preferredtimezone\"/>");
        outFile.write("\n        <Value>"+allAttrs[1]);
        outFile.write("</Value>");
        outFile.write("\n    </AttributeValuePair>");
        outFile.write("\n  </ModifyDefaultValues>");
        outFile.write("\n </SchemaRequests>");
      }
      if(attrName.equalsIgnoreCase("iwtDesktop-type-at")){
        outFile.write("\n <SchemaRequests serviceName=\"SunPortalDesktopService\" SchemaType=\"Dynamic\">");
        outFile.write("\n  <ModifyDefaultValues>");
        outFile.write("\n     <AttributeValuePair>");
        outFile.write("\n        <Attribute name=\"sunPortalDesktopType\"/>");
        outFile.write("\n        <Value>"+allAttrs[1]);
        outFile.write("</Value>");
        outFile.write("\n     </AttributeValuePair>");
        outFile.write("\n  </ModifyDefaultValues>");
        outFile.write("\n </SchemaRequests>");
      }
      if(attrName.equalsIgnoreCase("iwtPlatform-availableLocales-at")){
        outFile.write("\n <SchemaRequests serviceName=\"iPlanetAMPlatformService\" SchemaType=\"Global\">");
        outFile.write("\n  <ModifyDefaultValues>");
        outFile.write("\n     <AttributeValuePair>");
        outFile.write("\n        <Attribute name=\"iplanet-am-platform-available-locales\"/>");
        for(int j=1;j<allAttrs.length;++j){
          outFile.write("\n        <Value>"+allAttrs[j]);
          outFile.write("</Value>");
        }
        outFile.write("\n     </AttributeValuePair>");
        outFile.write("\n  </ModifyDefaultValues>");
        outFile.write("\n </SchemaRequests>");
      }
      if(attrName.equalsIgnoreCase("iwtPlatform-locale-at")){
        outFile.write("\n <SchemaRequests serviceName=\"iPlanetAMPlatformService\" SchemaType=\"Global\">");
        outFile.write("\n  <ModifyDefaultValues>");
        outFile.write("\n     <AttributeValuePair>");
        outFile.write("\n        <Attribute name=\"iplanet-am-platform-locale\"/>");
        outFile.write("\n        <Value>"+allAttrs[1]);
        outFile.write("</Value>");
        outFile.write("\n     </AttributeValuePair>");
        outFile.write("\n  </ModifyDefaultValues>");
        outFile.write("\n </SchemaRequests>");
      }
      if(attrName.equalsIgnoreCase("iwtDesktop-userSelectedProviders-at")){
        outFile.write("\n <SchemaRequests serviceName=\"SunPortalDesktopService\" SchemaType=\"Dynamic\">");
        tabContainerFound=false;
        if(allAttrs.length > 1){
           for(int jk=1;jk<allAttrs.length;++jk){
            //System.out.println("Value of :"+allAttrs[jk]);
            if(allAttrs[jk].equalsIgnoreCase("iwtTabProvider")){
              tabContainerFound=true;
              //System.out.println("Found...");
            }
           }
         }

        outFile.write("\n  <ModifyDefaultValues>");
        outFile.write("\n     <AttributeValuePair>");
        outFile.write("\n        <Attribute name=\"sunPortalDesktopDefaultChannelName\"/>");
        outFile.write("\n        <Value>");
        if(tabContainerFound==true)
          outFile.write("TemplateTabContainer");
        else
          outFile.write("TemplateTableContainer");
        outFile.write("</Value>");
        outFile.write("\n      </AttributeValuePair>");
        outFile.write("\n  </ModifyDefaultValues>");
        outFile.write("\n </SchemaRequests>");
      }
       }

    }

    if(profiletype.equalsIgnoreCase("role"))
          org=dn.substring(3);
    //System.out.println("Value of org..."+org);
    if((deriveAuthFromApp) && ((profiletype.equalsIgnoreCase("domain")))){
      //If no customization in 3.0 w.r.t authentication modules, it just shows all.
      //Hence register and create service templates for all the modules provided.

      outFile.write("\n <OrganizationRequests DN=\"o="+org+","+rootsuffix+"\">");
      outFile.write("\n    <RegisterServices>");
      outFile.write("\n     <Service_Name>iPlanetAMAuthLDAPService</Service_Name>");
      outFile.write("\n    </RegisterServices>");
      outFile.write("\n </OrganizationRequests>");
      outFile.write("\n <OrganizationRequests DN=\"o="+org+","+rootsuffix+"\">");
      outFile.write("\n    <RegisterServices>");
      outFile.write("\n     <Service_Name>iPlanetAMAuthAnonymousService</Service_Name>");
      outFile.write("\n    </RegisterServices>");
      outFile.write("\n </OrganizationRequests>");
      outFile.write("\n <OrganizationRequests DN=\"o="+org+","+rootsuffix+"\">");
      outFile.write("\n    <RegisterServices>");
      outFile.write("\n     <Service_Name>iPlanetAMAuthMembershipService</Service_Name>");
      outFile.write("\n    </RegisterServices>");
      outFile.write("\n </OrganizationRequests>");
      outFile.write("\n <OrganizationRequests DN=\"o="+org+","+rootsuffix+"\">");
      outFile.write("\n    <RegisterServices>");
      outFile.write("\n     <Service_Name>iPlanetAMAuthSafeWordService</Service_Name>");
      outFile.write("\n    </RegisterServices>");
      outFile.write("\n </OrganizationRequests>");
      outFile.write("\n <OrganizationRequests DN=\"o="+org+","+rootsuffix+"\">");
      outFile.write("\n    <RegisterServices>");
      outFile.write("\n     <Service_Name>iPlanetAMAuthRadiusService</Service_Name>");
      outFile.write("\n    </RegisterServices>");
      outFile.write("\n </OrganizationRequests>");
      outFile.write("\n <OrganizationRequests DN=\"o="+org+","+rootsuffix+"\">");
      outFile.write("\n    <RegisterServices>");
                        outFile.write("\n     <Service_Name>iPlanetAMAuthUnixService</Service_Name>");
      outFile.write("\n    </RegisterServices>");
      outFile.write("\n </OrganizationRequests>");
      outFile.write("\n <OrganizationRequests DN=\"o="+org+","+rootsuffix+"\">");
      outFile.write("\n    <RegisterServices>");
                        outFile.write("\n     <Service_Name>iPlanetAMAuthCertService</Service_Name>");
      outFile.write("\n    </RegisterServices>");
      outFile.write("\n </OrganizationRequests>");
      outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
      outFile.write("\n     <CreateServiceTemplate>");
      outFile.write("\n       <Service_Name>iPlanetAMAuthLDAPService</Service_Name>");
      outFile.write("\n     </CreateServiceTemplate>");
      outFile.write("\n </OrganizationRequests>");
      outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
      outFile.write("\n     <CreateServiceTemplate>");
      outFile.write("\n       <Service_Name>iPlanetAMAuthMembershipService</Service_Name>");
      outFile.write("\n     </CreateServiceTemplate>");
      outFile.write("\n </OrganizationRequests>");

      outFile.write("\n<OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
      outFile.write("\n    <ModifyServiceTemplate serviceName=\"iPlanetAMAuthMembershipService\" schemaType=\"Organization\">");
      outFile.write("\n        <AttributeValuePair>");
      outFile.write("\n               <Attribute name=\"iplanet-am-auth-membership-base-dn\"/>");
      outFile.write("\n               <Value>" + constructOrgDN(org, rootsuffix) + "</Value>");
      outFile.write("\n        </AttributeValuePair>");
                  outFile.write("\n        <AttributeValuePair>");
                  outFile.write("\n            <Attribute name=\"iplanet-am-auth-membership-bind-passwd\"/>");
                  outFile.write("\n            <Value>"+ldapUserPasswd+"</Value>");
                   outFile.write("\n        </AttributeValuePair>");
      outFile.write("\n     </ModifyServiceTemplate>");
      outFile.write("\n </OrganizationRequests>");

      outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
      outFile.write("\n     <CreateServiceTemplate>");
      outFile.write("\n       <Service_Name>iPlanetAMAuthAnonymousService</Service_Name>");
      outFile.write("\n     </CreateServiceTemplate>");
      outFile.write("\n </OrganizationRequests>");
      outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
      outFile.write("\n     <CreateServiceTemplate>");
      outFile.write("\n       <Service_Name>iPlanetAMAuthSafeWordService</Service_Name>");
      outFile.write("\n     </CreateServiceTemplate>");
      outFile.write("\n </OrganizationRequests>");
      outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
      outFile.write("\n     <CreateServiceTemplate>");
      outFile.write("\n         <Service_Name>iPlanetAMAuthRadiusService</Service_Name>");
      outFile.write("\n     </CreateServiceTemplate>");
      outFile.write("\n </OrganizationRequests>");
      outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
      outFile.write("\n     <CreateServiceTemplate>");
      outFile.write("\n        <Service_Name>iPlanetAMAuthUnixService</Service_Name>");
      outFile.write("\n     </CreateServiceTemplate>");
      outFile.write("\n </OrganizationRequests>");
      outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
      outFile.write("\n     <CreateServiceTemplate>");
      outFile.write("\n       <Service_Name>iPlanetAMAuthCertService</Service_Name>");
      outFile.write("\n     </CreateServiceTemplate>");
      outFile.write("\n </OrganizationRequests>");
      outFile.write("\n <OrganizationRequests DN=\"" + constructOrgDN(org, rootsuffix) + "\">");
      outFile.write("\n     <ModifyServiceTemplate serviceName=\"iPlanetAMAuthService\" schemaType=\"Organization\">");
      outFile.write("\n         <AttributeValuePair>");
      outFile.write("\n            <Attribute name=\"iplanet-am-auth-allowed-modules\"/>");
      outFile.write("\n            <Value>LDAP</Value>");
      outFile.write("\n            <Value>Anonymous</Value>");
      outFile.write("\n            <Value>Membership</Value>");
      outFile.write("\n            <Value>SafeWord</Value>");
      outFile.write("\n            <Value>RADIUS</Value>");
      outFile.write("\n            <Value>Unix</Value>");
      outFile.write("\n            <Value>Cert</Value>");
      outFile.write("\n         </AttributeValuePair>");
      outFile.write("\n     </ModifyServiceTemplate>");
      outFile.write("\n </OrganizationRequests>");
    }
    return;
  }
  static String getOrgName(String dn){
    String orgName=new String();

    //System.out.println("Orgname.."+dn);
    orgName=dn.substring(3,dn.indexOf(","));
    return orgName;
  }


    /*
     * The Global Desktop Service attributes need updated
     *
     * 1) sunPortalDesktopAuthorizedAuthlessUIDs = null
     * 2) sunPortalDesktopDefaultAuthlessUID = null
     *
     * Adding code to set the Console Service attributes also.
     * Without it, when a new user is created via the Memebership auth module
     *  the Desktop Service is not available.
     *
     * @param outputFile  the output file to write to
     */
    public static void setGlobalServiceAttr(String outputFile) {

      try {
  outFile = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8");
  printHeader();
  outFile.write("\n <SchemaRequests serviceName=\"SunPortalDesktopService\"" +
          " SchemaType=\"Global\">");
  outFile.write("\n   <RemoveDefaultValues>");
  outFile.write("\n     <Attribute name=\"sunPortalDesktopAuthorizedAuthlessUIDs\"/>");
  outFile.write("\n     <Attribute name=\"sunPortalDesktopDefaultAuthlessUID\"/>");
  outFile.write("\n   </RemoveDefaultValues>");
  outFile.write("\n </SchemaRequests>");

  outFile.write("\n <SchemaRequests serviceName=\"iPlanetAMAdminConsoleService\"" +
          " SchemaType=\"Organization\">");
  outFile.write("\n   <ModifyDefaultValues>");
  outFile.write("\n         <AttributeValuePair>");
  outFile.write("\n         <Attribute name=\"iplanet-am-required-services\"/>");
  outFile.write("\n           <Value>SunPortalDesktopService</Value>");
  outFile.write("\n           <Value>SunPortalNetmailService</Value>");
  outFile.write("\n           <Value>iPlanetAMWebAgentService</Value>");
  outFile.write("\n         </AttributeValuePair>");
  outFile.write("\n   </ModifyDefaultValues>");
  outFile.write("\n </SchemaRequests>");
  outFile.write("\n</Requests>");
  outFile.close();
      } catch (Exception e) {
  System.out.println("Error:" + e.toString());
  e.printStackTrace();
      }

    }

static String ConstructDN(String roleFileName){
  String rolename;
  String tmp;
  String dnToRet;//The DN to be returned

  // Given the relative path of the current file. This function constructs the DN of the required Role i.e SUbORganization..*


  //System.out.println("PAth:"+roleFileName);

  dnToRet=new String();
  tmp=roleFileName;
  while(tmp.indexOf("/")>= 0){
    //System.out.println("Temp:"+tmp);
    dnToRet += "," + orgNaming + tmp.substring(tmp.lastIndexOf("/")+1);
    tmp=tmp.substring(0,tmp.lastIndexOf("/"));
  }

  //System.out.println("To return:"+dnToRet);
  return dnToRet;
  }

       static String setNetMailServiceAttributes(String attrName, String allAttrs[]){
    StringBuffer sb =new StringBuffer();
    int attrType=-1;

    sb.append("\n  <Attribute name=");

    attrType= attrType(attrName);
    switch(attrType){
      case  NETMAIL_USER_IMAP_SERVER:
        sb.append("\"sunPortalNetmailIMAPServerName\"/>");
        break;

      case  NETMAIL_USER_SMTP_SERVER:
        sb.append("\"sunPortalNetmailSMTPServerName\"/>");
        break;

      case  NETMAIL_USER_DEFAULTMAILDOMAIN:
        sb.append("\"sunPortalNetmailDefaultMailDomain\"/>");
        break;

      case  NETMAIL_ROOT_FOLDER:
        sb.append("\"sunPortalNetmailRootFolder\"/>");
        break;

      case  NETMAIL_SENT_FOLDER:
        sb.append("\"sunPortalNetmailSentMessagesFolder\"/>");
        break;

      case  NETMAIL_REPLY_WITHAUTHOR:
        sb.append("\"sunPortalNetmailReplyWithAuthor\"/>");
        break;

      case  NETMAIL_REPLY_WITHDATE:
        sb.append("\"sunPortalNetmailReplyWithDate\"/>");
        break;

      case  NETMAIL_REPLY_WITHBODY:
        sb.append("\"sunPortalNetmailReplyWithBody\"/>");
        break;

      case  NETMAIL_INDENT_PREFIX:
        sb.append("\"sunPortalNetmailIndentPrefix\"/>");
        break;

      case  NETMAIL_ADD_SIGNATURE:
        sb.append("\"sunPortalNetmailAddSignature\"/>");
        break;

      case  NETMAIL_INITIAL_HDRS:
        sb.append("\"sunPortalNetmailInitialHeaders\"/>");
        break;

      case  NETMAIL_INACTIVITY_INTERVAL:
        sb.append("\"sunPortalNetmailInactivityInterval\"/>");
        break;

      case  NETMAIL_MAX_ATTACH_LEN:
        sb.append("\"sunPortalNetmailMaxAttachLen\"/>");
        break;

      case  NETMAIL_AUTOLOAD:
        sb.append("\"sunPortalNetmailAutoload\"/>");
        break;

      case  NETMAIL_AUTOSAVE:
        sb.append("\"sunPortalNetmailAutosave\"/>");
        break;

      case  NETMAIL_AUTOPURGE:
        sb.append("\"sunPortalNetmailAutopurge\"/>");
        break;

      case  NETMAIL_AUTOFOLDERLOAD:
        sb.append("\"sunPortalNetmailAutoFolderLoad\"/>");
        break;

      case  NETMAIL_MULTIPLE_RDW:
        sb.append("\"sunPortalNetmailMultipleReadWindows\"/>");
        break;

      case  NETMAIL_HEADERS_PAGE:
        sb.append("\"sunPortalNetmailHeadersPerPage\"/>");
        break;

      case  NETMAIL_NEWEST_FIRST:
        sb.append("\"sunPortalNetmailNewestFirst\"/>");
        break;

      case  NETMAIL_LDAPSERVERS:
        sb.append("\"sunPortalNetmailLDAPServers\"/>");
        for(int i=1;i<allAttrs.length;++i)
        sb.append("\n     <Value>"+allAttrs[i]+"</Value>");
        return sb.toString();//Multiple entries...appending and returning at this point

      case  NETMAIL_NOPREFSLIST:
        sb.append("\"sunPortalNetmailNoPrefsList\"/>");
        for(int i=1;i<allAttrs.length;++i)
        sb.append("\n     <Value>"+allAttrs[i]+"</Value>");
        return sb.toString();//Multiple entries...appending and returning at this point

    }
    sb.append("\n     <Value>"+allAttrs[1]+"</Value>");
    return sb.toString();
       }
static void InitHashMap(){

  ATTRIBUTES.put((new String("iwtUser-IMAPServerName-at")).toLowerCase(), new Integer(NETMAIL_USER_IMAP_SERVER));
  ATTRIBUTES.put((new String("iwtUser-SMTPServerName-at")).toLowerCase(), new Integer(NETMAIL_USER_SMTP_SERVER));
  ATTRIBUTES.put((new String("iwtUser-defaultMailDomain-at")).toLowerCase(), new Integer(NETMAIL_USER_DEFAULTMAILDOMAIN));
  ATTRIBUTES.put((new String("iwtNetMail-rootFolder-at")).toLowerCase(), new Integer(NETMAIL_ROOT_FOLDER));
  ATTRIBUTES.put((new String("iwtNetMail-sentMessagesFolder-at")).toLowerCase(), new Integer(NETMAIL_SENT_FOLDER));
  ATTRIBUTES.put((new String("iwtNetMail-replyWithAuthor-at")).toLowerCase(), new Integer(NETMAIL_REPLY_WITHAUTHOR));
  ATTRIBUTES.put((new String("iwtNetMail-replyWithDate-at")).toLowerCase(), new Integer(NETMAIL_REPLY_WITHDATE));
  ATTRIBUTES.put((new String("iwtNetMail-replyWithBody-at")).toLowerCase(), new Integer(NETMAIL_REPLY_WITHBODY));
  ATTRIBUTES.put((new String("iwtNetMail-indentPrefix-at")).toLowerCase(), new Integer(NETMAIL_INDENT_PREFIX));
  ATTRIBUTES.put((new String("iwtNetMail-addSignature-at")).toLowerCase(), new Integer(NETMAIL_ADD_SIGNATURE));
  ATTRIBUTES.put((new String("iwtNetMail-initialHeaders-at")).toLowerCase(), new Integer(NETMAIL_INITIAL_HDRS));
  ATTRIBUTES.put((new String("iwtNetMail-inactivityInterval-at")).toLowerCase(), new Integer(NETMAIL_INACTIVITY_INTERVAL));
  ATTRIBUTES.put((new String("iwtNetMail-maxAttachLen-at")).toLowerCase(), new Integer(NETMAIL_MAX_ATTACH_LEN));
  ATTRIBUTES.put((new String("iwtNetMail-autoload-at")).toLowerCase(), new Integer(NETMAIL_AUTOLOAD));
  ATTRIBUTES.put((new String("iwtNetMail-autosave-at")).toLowerCase(), new Integer(NETMAIL_AUTOSAVE));
  ATTRIBUTES.put((new String("iwtNetMail-autopurge-at")).toLowerCase(), new Integer(NETMAIL_AUTOPURGE));
  ATTRIBUTES.put((new String("iwtNetMail-autoFolderload-at")).toLowerCase(), new Integer(NETMAIL_AUTOFOLDERLOAD));
  ATTRIBUTES.put((new String("iwtNetMail-multipleReadWindows-at")).toLowerCase(), new Integer(NETMAIL_MULTIPLE_RDW));
  ATTRIBUTES.put((new String("iwtNetMail-headersPerPage-at")).toLowerCase(), new Integer(NETMAIL_HEADERS_PAGE));
  ATTRIBUTES.put((new String("iwtNetMail-newestFirst-at")).toLowerCase(), new Integer(NETMAIL_NEWEST_FIRST));
  ATTRIBUTES.put((new String("iwtNetMail-LDAPServers-at")).toLowerCase(), new Integer(NETMAIL_LDAPSERVERS));
  ATTRIBUTES.put((new String("iwtNetMail-noPrefsList-at")).toLowerCase(), new Integer(NETMAIL_NOPREFSLIST));

}

  static int attrType(String attrName){
    /* Returns the type of attribute that is being handled currently....*/

    try{
      return ((Integer)ATTRIBUTES.get(attrName.toLowerCase())).intValue();
    }
    catch(Exception e){
      return -1;
    }
  }

  static OutputStreamWriter outOrgsList_LDAP;//List of org's with LDAP server authentication as internal is written to this.


    /*
     * Flat Role conversion helper method responsible for evaluating the profileid
     * and construnctin the conforming rolename.
     *
     * @param String representing the role.ldif profileid
     * @return String representing concatenated roles forming one rolename with
     *         conforming to the flat role naming convention
     */
    static String getMangledRoleWithOrgFromProfileId(String profiledn) {
  String dn       = profiledn;
  String orgName  = dn.substring(1, dn.indexOf("/",1));

  if (dn.indexOf("/",1) >=0) {
      dn = dn.substring(dn.indexOf("/",1));
  }

  StringTokenizer strTok   = new StringTokenizer(dn,"/");
  String          roleName = "";

  while(strTok.hasMoreTokens()){
      roleName += "_" + strTok.nextToken();

      if (roleName.startsWith("_")) {
    roleName = roleName.substring(1, roleName.length());
      }
  }

  return constructRoleDN(roleName, orgName);
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.