// zxid.java - Java CGI script that calls libzxid using JNI // Copyright (c) 2007-2009 Symlabs (symlabs@symlabs.com), All Rights Reserved. // Author: Sampo Kellomaki (sampo@iki.fi) // This is confidential unpublished proprietary source code of the author. // NO WARRANTY, not even implied warranties. Contains trade secrets. // Distribution prohibited unless authorized in writing. // Licensed under Apache License 2.0, see file COPYING. // $Id: zxid.java,v 1.13 2009-11-29 12:23:06 sampo Exp $ // 12.1.2007, created --Sampo import zxidjava.*; public class zxid { static { System.loadLibrary("zxidjni"); } public static void main(String argv[]) throws java.io.IOException { int ret; zx_str rets; zxid_conf cf; System.err.print("Start...\n"); cf = zxidjni.new_conf("/var/zxid/"); String url = "https://sp1.zxidsp.org:8443/zxid-java.sh"; String cdc_url = "https://sp1.zxidcommon.org:8443/zxid-java.sh"; zxidjni.url_set(cf, url); zxidjni.set_opt(cf, 1, 1); String qs = System.getenv("QUERY_STRING"); // Deprecation warnings about this are bogus and indicative of Java designer's disregard of their user base - indeed disconnect from reality, see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4199068 zxid_cgi cgi = zxidjni.new_cgi(cf, qs); char op = cgi.getOp(); if (op == 'P') { int len = Integer.parseInt(System.getenv("CONTENT_LENGTH")); byte[] b = new byte[len]; int got = System.in.read(b, 0, len); qs = new String(b, 0, got); System.err.print("post\n"); zxidjni.parse_cgi(cgi, qs); op = cgi.getOp(); } if (op == 0) op = 'M'; zxid_ses ses; String sid = cgi.getSid(); if (sid != null && sid.length() > 0) { ses = zxidjni.fetch_ses(cf, sid); if (ses != null) { if (mgmt_screen(cf, cgi, ses, op) != 0) System.exit(0); } } ses = zxidjni.fetch_ses(cf, ""); // Just allocate an empty one System.err.println("Not logged in case op="+op+" qs:"+qs); switch (op) { case 'M': // Invoke LECP or redirect to CDC reader. //if (zxidjni.lecp_check(cf, cgi) != 0) System.exit(0); System.out.print("Location: " + cdc_url + "?o=C\r\n\r\n"); System.exit(0); case 'C': // CDC Read: Common Domain Cookie Reader zxidjni.cdc_read(cf, cgi); System.exit(0); case 'E': // Return from CDC read, or start here to by-pass CDC read. //if (zxidjni.lecp_check(cf, cgi) != 0) System.exit(0); if (zxidjni.cdc_check(cf, cgi) != 0) System.exit(0); break; case 'L': System.err.print("Start login\n"); url = zxidjni.start_sso_url(cf, cgi).getS(); if (url.length() > 0) { System.err.print("login redir\n"); System.out.print("Location: " + url + "\r\n\r\n"); System.exit(0); } System.err.print("Login trouble"); break; case 'A': ret = zxidjni.sp_deref_art(cf, cgi, ses); System.err.println("deref art ret="+ret); if (ret == zxidjniConstants.ZXID_REDIR_OK) System.exit(0); if (ret == zxidjniConstants.ZXID_SSO_OK) if (mgmt_screen(cf, cgi, ses, op) != 0) System.exit(0); break; case 'P': // *** broken with newer swig generated -noproxy code rets = zxidjni.sp_dispatch(cf, cgi, ses); System.err.println("saml_resp ret=" + rets); if (rets.getS() == "O") System.exit(0); if (rets.getS() == "K") if (mgmt_screen(cf, cgi, ses, op) != 0) System.exit(0); break; case 'Q': rets = zxidjni.sp_dispatch(cf, cgi, ses); if (rets.getS() == "O") System.exit(0); if (rets.getS() == "K") if (mgmt_screen(cf, cgi, ses, op) != 0) System.exit(0); break; case 'B': System.out.print("CONTENT-TYPE: text/xml\r\n\r\n"); String md = zxidjni.sp_meta(cf, cgi).getS(); System.out.print(md); System.exit(0); default: System.err.println("Unknown op="+op); } System.out.print("CONTENT-TYPE: text/html\r\n\r\n"); System.out.print("
\n"); System.out.print("
\n