killbulle wrote:
> 
> Hi, wadim i'a m interessed by your agent
> here we have implemented a version the CAS part(token generation and
> workflow modification), i will share it in few days
> Regards Marc
> 

Hi Marc,

here it is:
package domino.cas;

import java.io.PrintWriter;
import java.io.StringReader;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

import javax.xml.parsers.SAXParserFactory;

import lotus.domino.AgentBase;
import lotus.domino.AgentContext;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.Session;
...
import edu.yale.its.tp.cas.client.ServiceTicketValidator;

public class JavaAgent extends AgentBase {
        
  private static SAXParserFactory spf = SAXParserFactory.newInstance(); 
  private static final String ENCODING = "latin1";

  public void NotesMain() {
    try {       
      String version = System.getProperty("java.version");
      //SSL issues with Java < 1.4...
      if(version == null ||
Float.valueOf(version.substring(0,3)).floatValue() < (float) 1.4) {
        System.err.println("This agent requires java version 1.4 or
higher.");
        return;
      }                 
                        
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();

      Database db = agentContext.getCurrentDatabase();
      Document profile = db.getProfileDocument("Databaseprofile", null);
      Document doc = agentContext.getDocumentContext();
                        
      System.setProperty("javax.net.ssl.trustStore",
profile.getItemValueString("trustStore"));
                        
      String query = doc.getItemValueString("Query_String");
      Map map = getQueryMap(query);
      String ticket = (String)map.get("ticket");
      Boolean renew = Boolean.valueOf((String)map.get("renew"));                
        
      String url = URLDecoder.decode((String)map.get("url"), ENCODING);
                        
      int port = Integer.parseInt(doc.getItemValueString("Server_Port"));
      String protocol = "http";
      if(port == 443) {
        protocol = "https";
      }
                        
      String service = URLEncoder.encode(
        protocol+"://"+
        doc.getItemValueString("Server_Name")+
        doc.getItemValueString("Path_Translated")+
        "?openAgent&url="+URLEncoder.encode(url, ENCODING)
      , ENCODING);
                        
      PrintWriter pw = getAgentOutput();                        
      if(ticket == null) {
        if(url != null) {
          String casUrl =
profile.getItemValueString("loginUrl")+"?service="+service;
          if(renew.booleanValue()) {
            casUrl = casUrl + "&renew=true";
          }
          pw.println(["+casUrl+"]");                                            
                                
          return;
        } else {
          //TODO Error Handling                         
        }
      } else {                          
        if(url != null) {                                       
          ServiceTicketValidator sv = new ServiceTicketValidator();
          sv.setCasValidateUrl(profile.getItemValueString("validateUrl"));
          sv.setService(service);
          sv.setServiceTicket(ticket);                          
          sv.validate();
          if(sv.isAuthenticationSuccesful()) {
            String domAuthSessId =
getDomAuthSessId(profile.getItemValueString("dominoLoginUrl"),
sv.getUser());
            if(domAuthSessId != null) {                                         
        
              pw.println("Set-Cookie: DomAuthSessId="+domAuthSessId+";
Path=/;");
              pw.println("Location: "+url);
            }
            //TODO Error Handling
          } else {                                              
            pw.println(sv.getErrorCode());
            pw.println(sv.getErrorMessage());
          }
        } else {
          //TODO Error Handling
        }
      }                 
    } catch(Exception e) {
      e.printStackTrace();
    }
}
        
private Map getQueryMap(String query) {
  StringTokenizer params = new StringTokenizer(query, "&");             
  Map map = new HashMap();
  while(params.hasMoreTokens()) {
    String param = params.nextToken();
    int i = param.indexOf("=");
    if(i > -1) {
      String name = param.substring(0,i);
      String value = param.substring(i+1);
      map.put(name, value);
    }
  }
  return map;
}
        
private String getDomAuthSessId(String url, String username) {          
  //getting DomAuthSessId
}
        
}

-- 
View this message in context: 
http://www.nabble.com/Re%3A-Lotus-Domino-SSO-Support-tp22817129p23222179.html
Sent from the CAS Users mailing list archive at Nabble.com.


-- 
You are currently subscribed to [email protected] as: 
[email protected]
To unsubscribe, change settings or access archives, see 
http://www.ja-sig.org/wiki/display/JSG/cas-user

Reply via email to