Skip to Content
0
Former Member
Nov 15, 2006 at 03:03 PM

SSO2 Ticket using sapsecu and sapssoext in Java

186 Views

Hi All,

I am trying to do single sign on using SSO2 Ticket (using sapsecu and sapssoext) in Java.

I used sapssoext.dll version

6400.108.12.16936

and sapsecu.dll version is 5.4.28.3. I am using EP 6.0. After executing below code exception is

java.lang.Exception: MySapEvalLogonTicketEx failed: standard error= 5, ssf error= 22.

Please help me in resolving this.

import java.io.*;

public class SSO2Ticket {

public static final int ISSUER_CERT_SUBJECT = 0;

public static final int ISSUER_CERT_ISSUER = 1;

public static final int ISSUER_CERT_SERIALNO = 2;

private static boolean initialized = false;

public static String SECLIBRARY;

public static String SSO2TICKETLIBRARY = "sapssoext";

static {

if (System.getProperty("os.name").startsWith("Win")) {

SECLIBRARY = "sapsecu.dll";

} else {

SECLIBRARY = "libsapsecu.so";

}

try {

System.loadLibrary(SSO2TICKETLIBRARY);

System.out.println("SAPSSOEXT loaded.");

} catch (Throwable e) {

System.out.println(

"Error during initialization of SSO2TICKET:

"

+ e.getMessage());

}

System.out.println("static part ends.

");

}

/**

  • Initialization

*

  • @param seclib location of ssf-implemenation

*

  • @return true/false whether initailisation was ok

*/

private static native synchronized boolean init(String seclib);

/**

  • Returns internal version.

*

  • @return version

*/

public static native synchronized String getVersion();

/**

  • eval ticket

*

  • @param ticket the ticket

  • @param pab location of pab

  • @param pab_password password for access the pab

*

  • @return = (String)user, = (String)sysid, = (String)client , =

(byte[])certificate

*

*/

public static native synchronized Object[] evalLogonTicket(

String ticket,

String pab,

String pab_password)

throws Exception;

/**

  • Parse certificate

  • @param cert Certificate received from evalLogonTicket

  • @param info_id One of the requst id´s

*

  • @return Info string from certificate

*

*/

public static native synchronized String parseCertificate(

byte[] cert,

int info_id);

public static void main(String[] args) throws Exception {

byte[] certificate;

String ticket;

String pab;

String ssf_library;

try {

// plausi check

// if (getCommandParam(args, "-i") == null) {

// PrintHelp();

// return;

// }

System.out.println("Start SSO2TICKET main");

System.out.println("----

-


test version -

-


");

String version = SSO2Ticket.getVersion();

System.out.println("Version of SAPSSOEXT: " + version);

// read ticket into a String

ticket = getTicket("C:

ssosample

ticket.txt");

//getTicket()

// get PAB (public key) of issuing system

//pab = getFullFilePath(getCommandParam(args, "-p"));

pab = getFullFilePath("C:

verify.pse

verify.pse");

ssf_library = "C:

sapsecu.dll";

if (ssf_library == null)

ssf_library = SECLIBRARY;

if (!init(ssf_library)) {

System.out.println("Could not load library: " + ssf_library);

return;

}

// evaluate the ticket

// System.out.println(pab);

// System.out.println(ticket);

Object o[] = evalLogonTicket(ticket, pab != null ? pab : "SAPdefault",null);

// print out all parameters received from SAPSSOEXT

PrintResults(

(String) o[0],

(String) o[1],

(String) o[2],

parseCertificate((byte[]) o[3], ISSUER_CERT_SUBJECT),

parseCertificate((byte[]) o[3], ISSUER_CERT_ISSUER),

ticket);

} catch (Exception e) {

System.out.println(e);

} catch (Throwable te) {

System.out.println(te);

}

}

// print the parameters from ticket

static void PrintResults(

String user,

String sysid,

String client,

String subject,

String issuer,

String ticket) {

System.out.println("***********************************************");

System.out.println(" Output of program:");

System.out.println("***********************************************");

System.out.println("

");

System.out.println("The ticket

" + ticket + "

");

System.out.println("was successfully validated.");

System.out.println("User : " + user);

System.out.println("Ident of ticket issuing system:");

System.out.println("Sysid : " + sysid);

System.out.println("Client : " + client);

System.out.println("Certificate data of issuing system:");

System.out.println("Subject : " + subject);

System.out.println("Issuer : " + issuer);

System.out.println("

");

}

// read the ticket string from a File

public static String getTicket(String filename)

throws FileNotFoundException {

try {

BufferedReader in = new BufferedReader(new FileReader(filename));

String str;

StringBuffer strBuffer = new StringBuffer();

while ((str = in.readLine()) != null) {

strBuffer.append(str);

}

in.close();

return strBuffer.toString();

} catch (Exception e) {

// Let the user know what went wrong.

System.out.println("The file could not be read:");

System.out.println(e.getMessage());

throw new FileNotFoundException(

"File " + filename + " could not be read");

}

}

// parse the arguments for an option

static String getCommandParam(String[] args, String option) {

for (int i = 0; i 0) {

path = file.getAbsolutePath();

} else {

path = file.getAbsolutePath() + ".pse";

}

if (!new File(path).exists())

throw new FileNotFoundException(

"File " + filename + " does not exists");

return path;

}

}