Pages

Wednesday, March 14, 2012

PART I, writing an app with google provisioning api in Luminis

Since my first encounter with the Tomcat and javaservlets, I had learned a few things about Javascript, that I want to post in here, but not at the moment.  Today I want to describe the process of writing an application that eventually will allow the student using our Luminis system to get a new password for their brand new gmail account.
See, Luminis stores the password of the user inside the LDAP  userPassword entry. It is stored using  a SSHA algorithm, seeded SHA. This is a very good encryption scheme, I believe, but it is not compatible with the Google Directory Sync application (GDSync), not even using the latest version of it today. (I'll check later on the current version number to post it here).
So the idea of reading the ldap directory entry using the GDSync application is not available. That gives us with several different options:
Create random passwords, populate some ldap entry not in use in the Luminis LDAP and make GDSync read it and use it for the initial password of the gmail account. How to let the student know what is the new password?
  One idea, a not very secure one, is to tell them that the initial password is some combination of birth date, some digits of their SS, phone number, part of their first name of last name, etc.
Another idea, send them the new password by mail...I personally hate that idea because of the effort, time and cost of the implementation when you are dealing with thousands of students. 

And my favorite idea, let the student be the one in control of when to change the password and aware of where to receive it.
So I have a plan to implement that favorite idea. Some parts of this plan are not yet implemented, so in future posts you will find the actual implementation:

In the Luminis Login page, the student will be presented with another form to enter his current username and password. Instead of login to Luminis, I will check his/her credentials against the Lumins LDAP and if it authenticate, another html form will be displayed. This form is going to be an HTML showing the student, all the emails account that he/she has registered in the Banner Database. So the student will select to which of the emails he will receive the new temporary password of his gmail account. The submit button will then call the servlet that eventually run the Google Apps provisioning API, that will update the gmail account, and then send the student the email with the information.

Because I just started with this Google Apps API, lets talk about how to make it work in the Luminis 4x server.
   Our Luminis sever had already all the software in place. mail.jar, sevlet-api.jar, jdk (1.5), activation.jar and ant. Ant is the only one that had the incorrect version, so I had to get the latest source (1.8.3) unzip it, and export the variable ANT_HOME to point to the folder that was created by the unzip action. I don't know how to use ant anyway, and all the tests I  have done so far have been using the compiler directly and only one java source at the time. Probably that's why it took me a while to get all  necessary jar files point by the CLASSPATH variable before my first successful compilation; CalendarTest.java, which is provided by the Getting Started with the Google Data Java Client Library (code.google.com/apis/gdata/articles/java_client_lib.html). At this moment my CLASSPATH is looking ugly and like this:

$ echo $CLASSPATH
/opt/luminis/products/tomcat/tomcat-cp/common/lib/servlet-api.jar:/opt/luminis/webapps
/luminis/WEB-INF/lib/ojdbc14.jar::/opt/luminis/webapps/luminis/WEB-INF/lib/ldapjdk.jar
:./:/home/lumadmin/gdata_staging/gdata/java/lib/gdata-calendar-2.0.jar:/home/lumadmin/
gdata_staging/gdata/java/sample/util/lib/sample-util.jar:/home/lumadmin/gdata_staging/
gdata/java/deps/jsr305.jar:/home/lumadmin/gdata_staging/gdata/java/deps/google-collect
-1.0-rc1.jar:/home/lumadmin/gdata_staging/gdata/java/lib/gdata-appsforyourdomain-1.0.j
ar:/home/lumadmin/gdata_staging/gdata/java/sample/appsforyourdomain/lib/AppsForYourDom
ainClient.jar


CalendarTest.java:
import com.google.gdata.client.*;
import com.google.gdata.client.calendar.*;
import com.google.gdata.data.*;
import com.google.gdata.data.acl.*;
import com.google.gdata.data.calendar.*;
import com.google.gdata.data.extensions.*;
import com.google.gdata.util.*;

import java.net.*;
import java.io.*;

import sample.util.*; 
public class CalendarTest {

    public static void main(String[] args) {
        CalendarService myService = new CalendarService("exampleCo-exampleApp-1.0");
        myService.setUserCredentials("root@gmail.com", "pa$$word");

        URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/allcalendars/full");
        CalendarFeed resultFeed = myService.getFeed(feedUrl, CalendarFeed.class);

        System.out.println("Your calendars:");
        System.out.println();

        for (int i = 0; i < resultFeed.getEntries().size(); i++) {
          CalendarEntry entry = resultFeed.getEntries().get(i);
          System.out.println("\t" + entry.getTitle().getPlainText());
        }

    }
}
The above code did not compile. I have to change it to add a try/catch block before it compiled successfully. It seems that I am not the only one because I found another person in some forum asking for that problem.


So, now the first code. This is obvious, just the first code, it is extremely raw, with no validation code, no error handling, but it does change the password of the gmail account.



import java.net.URL;
import java.util.List;
import com.google.gdata.client.appsforyourdomain.UserService;
import com.google.gdata.data.appsforyourdomain.provisioning.UserEntry;
import com.google.gdata.data.appsforyourdomain.provisioning.UserFeed;
import sample.appsforyourdomain.AppsForYourDomainClient;
 
public class changepassword {
   public void update(String username,String password){
 String domain="yourdomain"; String admin="adminaccount"; String adminpwd="adminpwd";
       try
       {
       // Create a new Apps Provisioning service
 AppsForYourDomainClient client=new AppsForYourDomainClient(admin, adminpwd,domain);
 UserEntry user = client.retrieveUser(username);
 user.getLogin().setPassword(password);
 client.updateUser(username,user);
             }
            catch(Exception e) { System.out.print(e);}
        }
   public static void main(String args[])
   {
   String user="student_username"; String passwd="student_new_password_on_gmail";
   changepassword upusr=new changepassword();
   upusr.update(user,passwd);
   }
}

The above code compiles, and it works.  There it is. Now, you have a basic class that will change the password on the gmail account. Much more to come, as I advance in the other parts of the plan.
I think that if you are also starting like me testing the waters of luminis/gmail/ java/tomcat/servlets this might be of some help.

Sunday, March 11, 2012

Kony2012 and the professional journalist



This is a digression from my favorite field, technology. Usually I don't feel so compel to broadcast my points of view about non-technical stuff. But the viral video of Kony 2012 has produced so much rage inside me that I have to speak about it.
I knew about LRA before watching the video, I knew the government had sent a group of military experts to help the Uganda's army stop LRA and their crimes. I learned about when it happened, it was 'covered' in the news at the time, last months of 2011. But, probably like many others that heard the news, I forgot about it. I did not research, I did not feel the pain of those children.
Now it comes the video. Millions of people are shaken inside, millions have cried with Jacob and for the thousands of others like him. The producer artfully touches the emotional fiber of the viewer in his attempt to involve him in his crusade. His goal, bring Joseph Kony, a Uganda's warlord to the spotlight, in the hope that public awareness might bring governments around the world to join forces capturing Kony.

That's the main idea portrayed by the video. Is the video successful ? Yes, millions now know about the atrocities committed by Kony and others of his kind.

Why I am upset? Have you seen CNN or MSNBC lately? Probably Fox News too, I can't  muster the strength to watch Fox News, sorry..., but I suppose they are having the same spin in this story. If not, please let me know. At least, CNN and MSNBC which I watch regularly, have shown several fragments discussing the video. For them, the video was well produced, but misleading. Why, because the producer said that Kony is in Uganda, he is not anymore.
CNN brought one girl who suffered on herself the evilness of Kony's army. Her point of view, is that the video is wrong because it makes Kony a celebrity, and he does not deserve to be a celebrity. She thinks that the tormented children were the ones that should be in the center of the video.
I have nothing against this girl. That's her opinion,  That video, brought her to CNN, and that video stirred  the public opinion about a subject NONE of the professional journalist of CNN, MSNBC (again I don't know about FOX), had given any important coverage so far. The journalist failed, if they ever tried, to make the public aware and outraged of what has been happening for years in Africa. But now they dare to criticize the producer of this video, an outsider, not one of us, the respectable  journalists of the big media chains.
How important is, if this Kony is or is not in Uganda right now?. How important is that the video does not give any importance to the Uganda government army?. How important is that Kony is on the run? How important is that now he is killing fewer people than before? Isn't  it much more important that the world knows now and demand an end to this criminal?

Kony is not as relevant now as he was before, granted. But where in the world were these critics  while Kony was relevant and children in Uganda were been killed, mutilated and raped for years.  They had the chance of telling the world while it was happening, but they did not. On the other hand if a random guy start playing good basketball in the NBA, (remember Linsanity?), they can't stop writing about it.
How pathetic,


Now I feel better,