Novell Home

eGuide Fix for Timeshifts

Novell Cool Solutions: Tip
By Andrey Karyagin

Digg This - Slashdot This

Posted: 12 Oct 2005
 

Problem

I tried the eGuide 2.12 Generic Control UI to view/edit the loginExpirationTime and passwordExpirationTime attributes. I found that the server side of eGuide translates the UTC time stored in eDirectory to the local timezone, in the following manner:

  1. The eGuide server reads the loginExpirationTime value.
  2. It translates the YYYYMMDDhhmmssZ string to human-readable form, according to server time zone settings and browser locale settings.
  3. The resulting web page contains local date/time presentation of the original value. This human-readable form is available for editing.

Nevertheless, the reverse conversion from local date/time to UTC does not take place when I click Save to store the changed value in the LDAP catalogue. The local date/time value is stored directly in eDirectory. As a result, I see a four-hour time difference with the value I've just entered when the browser re-reads the stored value. (Four hours is the time difference between UTC and Moscow Summer Time). It appears to me that eGuide uses the following code to prepare the web page:

debug("The time is: " + s2);
SimpleDateFormat simpledateformat = new 
SimpleDateFormat("yyyyMMddHHmmss'Z'", ServletUtil.getLocale(m_hParams));
Date date = simpledateformat.parse(s2);
DateFormat dateformat = DateFormat.getDateTimeInstance(1, 1, 
ServletUtil.getLocale(m_hParams));
long l = 0L;
GregorianCalendar gregoriancalendar = new 
GregorianCalendar(TimeZone.getDefault());
gregoriancalendar.setTime(date);
l = gregoriancalendar.get(15) + gregoriancalendar.get(16);
Date date1 = new Date(date.getTime() + l);
String s4 = dateformat.format(date1);
stringbuffer.append("<value><![CDATA[").append(s4).append("]]></value>").append(Util.nl);

Unfortunately, the timezone and daylight saving time are not being subtracted BEFORE storing the UTC date/time in LDAP catalogue. I hope this bug will be fixed in the next version of DefaultDataHandler.java and eguideprovider.jar.

Solution

Patch versions of DefaultDataHandler.java and the compiled DefaultDataHandler.class are included, and the .java file is shown below. The original DefaultDataHandler.class within eguideprovider.jar should be replaced with this one. With this patch it is possible to view/edit all SYN_TIME attributes without the erroneous time shift.

.java Code

// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 

package com.novell.eguide.handler;

import com.novell.eguide.ServletUtil;
import com.novell.eguide.ldap.DirectoryObject;
import com.novell.eguide.ldap.Util;
import com.novell.eguide.ns.*;
import com.novell.eguide.schema.AttributeScheme;
import java.io.StringReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import netscape.ldap.*;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

// Referenced classes of package com.novell.eguide.handler:
//            DataHandler

public class DefaultDataHandler extends DataHandler
{

    public DefaultDataHandler()
    {
    }

    public String getString(LDAPAttribute ldapattribute, AttributeScheme attributescheme, DirectoryObject directoryobject)
    {
        StringBuffer stringbuffer = new StringBuffer(32);
        if(attributescheme.getKeyName().equalsIgnoreCase("userpassword"))
        {
            stringbuffer.append("").append(Util.nl);
            return stringbuffer.toString();
        }
        if(ldapattribute == null)
            return null;
        debug("Writing out data for " + attributescheme.getKeyName());
        String s = attributescheme.getSyntaxDescription();
        if(s.equals("Binary"))
        {
            Enumeration enumeration = ldapattribute.getByteValues();
            if(enumeration != null)
            {
                debug("Writing out Binary data " + attributescheme.getKeyName());
                String s1;
                for(; enumeration.hasMoreElements(); stringbuffer.append("<value><![CDATA[").append(s1).append("]]></value>").append(Util.nl))
                    s1 = new String((byte[])enumeration.nextElement());

                return stringbuffer.toString();
            }
        } else
        if(s.equals("Tagged Data"))
        {
            Enumeration enumeration1 = ldapattribute.getByteValues();
            if(enumeration1 != null)
            {
                debug("Writing out Binary data " + attributescheme.getKeyName());
                for(; enumeration1.hasMoreElements(); stringbuffer.append("]]></value>").append(Util.nl))
                {
                    stringbuffer.append("<value><![CDATA[");
                    byte abyte0[] = (byte[])enumeration1.nextElement();
                    byte abyte2[] = new byte[1];
                    byte abyte4[] = new byte[abyte0.length - 2];
                    debug("The netaddress length is : " + abyte0.length);
                    debug("The hex representation is : " + NSUtil.toHexString(abyte0));
                    for(int i = 0; i < abyte0.length; i++)
                        if(i > 1)
                            abyte4[i - 2] = abyte0[i];
                        else
                        if(i < 1)
                            abyte2[i] = abyte0[i];

                    try
                    {
                        debug("Getting value list.");
                        debug("The type is: " + new String(abyte2));
                        NetAddressFacade netaddressfacade = new NetAddressFacade(Long.parseLong(new String(abyte2)), abyte4);
                        stringbuffer.append(netaddressfacade.getAddressString());
                    }
                    catch(Exception exception1)
                    {
                        debug("Caught exception on tagged String.");
                    }
                }

                return stringbuffer.toString();
            }
        } else
        if(s.equals("Tagged String"))
        {
            Enumeration enumeration2 = ldapattribute.getByteValues();
            if(enumeration2 != null)
            {
                debug("Writing out Binary data " + attributescheme.getKeyName());
                for(; enumeration2.hasMoreElements(); stringbuffer.append("]]></value>").append(Util.nl))
                {
                    stringbuffer.append("<value><![CDATA[");
                    byte abyte1[] = (byte[])enumeration2.nextElement();
                    byte abyte3[] = new byte[1];
                    byte abyte5[] = new byte[abyte1.length - 2];
                    debug("The netaddress length is : " + abyte1.length);
                    debug("The hex representation is : " + NSUtil.toHexString(abyte1));
                    for(int j = 0; j < abyte1.length; j++)
                        if(j > 1)
                            abyte5[j - 2] = abyte1[j];
                        else
                        if(j < 1)
                            abyte3[j] = abyte1[j];

                    try
                    {
                        debug("Getting value list.");
                        debug("The type is: " + new String(abyte3));
                        EmailAddressFacade emailaddressfacade = new EmailAddressFacade(Long.parseLong(new String(abyte3)), new String(abyte5));
                        stringbuffer.append(emailaddressfacade.getAddress());
                    }
                    catch(Exception exception2)
                    {
                        debug("Caught exception on tagged String.");
                    }
                }

                return stringbuffer.toString();
            }
        } else
        if(s.equals("Generalized Time"))
        {
            Enumeration enumeration3 = ldapattribute.getStringValues();
            if(enumeration3 != null)
            {
                debug("Writing out String data " + attributescheme.getKeyName());
                while(enumeration3.hasMoreElements()) 
                {
                    String s2 = (String)enumeration3.nextElement();
                    try
                    {
                        debug("The time is: " + s2);
                        SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMddHHmmss'Z'", ServletUtil.getLocale(m_hParams));
                        Date date = simpledateformat.parse(s2);
                        DateFormat dateformat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, ServletUtil.getLocale(m_hParams));
                        long l = 0L;
                        GregorianCalendar gregoriancalendar = new GregorianCalendar(TimeZone.getDefault());
                        gregoriancalendar.setTime(date);
                        l = gregoriancalendar.get(15) + gregoriancalendar.get(16);
                        Date date1 = new Date(date.getTime() + l);
                        String s4 = dateformat.format(date1);
                        stringbuffer.append("<value><![CDATA[").append(s4).append("]]></value>").append(Util.nl);
                    }
                    catch(Exception exception)
                    {
                        debug("Caught an exception formatting the date.  Just printing out the string.");
                        stringbuffer.append("<value><![CDATA[").append(s2).append("]]></value>").append(Util.nl);
                    }
                }
                return stringbuffer.toString();
            }
        } else
        {
            Enumeration enumeration4 = ldapattribute.getStringValues();
            if(enumeration4 != null)
            {
                debug("Writing out String data " + attributescheme.getKeyName());
                while(enumeration4.hasMoreElements()) 
                {
                    String s3 = new String((String)enumeration4.nextElement());
                    if(!s3.equals(""))
                        stringbuffer.append("<value><![CDATA[").append(s3).append("]]></value>").append(Util.nl);
                }
                return stringbuffer.toString();
            }
        }
        return stringbuffer.toString();
    }

    public boolean setString(LDAPConnection ldapconnection, LDAPEntry ldapentry, AttributeScheme attributescheme, String s)
        throws LDAPException, Exception
    {
        LDAPModificationSet ldapmodificationset = new LDAPModificationSet();
        String s1 = attributescheme.getAttrName();
        if(s == null)
            return false;
        SAXBuilder saxbuilder = new SAXBuilder(false);
        Document document = saxbuilder.build(new StringReader(s));
        Element element = document.getRootElement();
        boolean flag = element.getChildren("nochange").isEmpty();
        if(!flag)
            return false;
        debug("Attribute contained a value in directory: " + s1);
        boolean flag1 = element.getChildren("value").isEmpty();
        LDAPAttribute ldapattribute = ldapentry.getAttribute(s1);
        String s2 = attributescheme.getSyntaxDescription();
        if(s2.equals("Tagged Data") || s2.equals("Tagged Name And String"))
            throw new Exception(" edit mode currently not available.");
        if(ldapattribute == null)
            debug("Attribute value does not exist in directory: " + s1);
        else
        if(flag1)
            if(attributescheme.isMultiValue())
            {
                LDAPAttribute ldapattribute1 = new LDAPAttribute(s1);
                String as1[] = ldapattribute.getStringValueArray();
                for(int i = 0; i < as1.length; i++)
                {
                    debug("Value: " + as1[i]);
                    ldapattribute1.addValue(as1[i]);
                }

                debug("Removing values from the attribute: " + s1);
                ldapmodificationset.add(1, ldapattribute1);
            } else
            {
                String as[] = ldapattribute.getStringValueArray();
                String s3 = as[0];
                debug("Value: " + s3);
                LDAPAttribute ldapattribute4 = new LDAPAttribute(s1);
                ldapattribute4.addValue(s3);
                debug("Removing the value from the attribute: " + s1);
                ldapmodificationset.add(1, ldapattribute4);
            }
        if(!flag1)
            if(attributescheme.isMultiValue())
            {
                LDAPAttribute ldapattribute2 = new LDAPAttribute(s1);
                List list = element.getChildren("value");
                for(int j = 0; j < list.size(); j++)
                {
                    Element element1 = (Element)list.get(j);
                    String s5 = element1.getText();
                    if(s2.equals("Binary"))
                        ldapattribute2.addValue(s5.getBytes("UTF-8"));
                    else
                    if(s2.equals("Generalized Time"))
                    {
                        debug("Getting the Date object, parsing: " + s5);
                        Date date1 = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, ServletUtil.getLocale(m_hParams)).parse(s5);

                        long l = 0L;
                        GregorianCalendar gregoriancalendar = new GregorianCalendar(TimeZone.getDefault());
                        gregoriancalendar.setTime(date1);
                        l = gregoriancalendar.get(15) + gregoriancalendar.get(16);
                        Date date = new Date(date1.getTime() - l);

                        SimpleDateFormat simpledateformat1 = new SimpleDateFormat("yyyyMMddHHmmss'Z'", ServletUtil.getLocale(m_hParams));
                        String s7 = simpledateformat1.format(date);
                        debug("Adding Generalized Time to the directory: " + s7);
                        ldapattribute2.addValue(s7);
                    } else
                    {
                        ldapattribute2.addValue(s5);
                    }
                    debug("Value: " + s5);
                }

                debug("Replacing values for the attribute: " + s1);
                ldapmodificationset.add(2, ldapattribute2);
            } else
            {
                LDAPAttribute ldapattribute3 = new LDAPAttribute(s1);
                List list1 = element.getChildren("value");
                String s4 = "";
                if(list1.size() > 0)
                {
                    Element element2 = (Element)list1.get(0);
                    s4 = element2.getText();
                } else
                {
                    ldapattribute3.addValue(s4);
                }
                if(s2.equals("Binary"))
                {
                    debug("Value: " + s4);
                    ldapattribute3.addValue(s4.getBytes("UTF-8"));
                } else
                if(s2.equals("Generalized Time"))
                {
                    debug("Getting the Date object, parsing: " + s4);
                    Date date = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, ServletUtil.getLocale(m_hParams)).parse(s4);

                        long l = 0L;
                        GregorianCalendar gregoriancalendar = new GregorianCalendar(TimeZone.getDefault());
                        gregoriancalendar.setTime(date);
                        l = gregoriancalendar.get(15) + gregoriancalendar.get(16);
                        Date date1= new Date(date.getTime() - l);

                    SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMddHHmmss'Z'", ServletUtil.getLocale(m_hParams));
                    String s6 = simpledateformat.format(date1);
                    debug("Adding Generalized Time to the directory: " + s6);
                    ldapattribute3.addValue(s6);
                } else
                {
                    debug("Value: " + s4);
                    ldapattribute3.addValue(s4);
                }
                debug("Replacing values for the attribute: " + s1);
                ldapmodificationset.add(2, ldapattribute3);
            }
        ldapconnection.modify(ldapentry.getDN(), ldapmodificationset);
        debug("Entry modified");
        return true;
    }
}


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell