123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
/* * Program: CredentialTokenizer.java * Purpose: Example to illustrate how to create a security token * @author Ray Lai (ray.lai@sun.com) * @version 1.0 * Updated: April 15, 2005, 10:23 PM * Copyright: (c) 2005 by Sun Microsystems/Ray Lai under Common Development and Distribution License * Remarks: Full program and documentation will be available under developer.java.net * For simplicity, logger class is removed; X509CertToken are not included in this demo. * X509CertToken and BinaryToken will be included in the full program under developer.java.net. * ===================================================================================== */ package com.csp.identity; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; public class CredentialTokenizer { protected com.csp.identity.TokenContextImpl context; protected com.csp.identity.UsernameToken usernameToken; protected java.security.cert.X509Certificate cert; // in dev/production, you won't put the subject, principal or password here protected final String testPrincipal = "username"; protected final String testPassword = "password"; /** Constructor - Creates a new instance of CredentialTokenizer */ public CredentialTokenizer() { context = new com.csp.identity.TokenContextImpl(); // For UsernameToken System.out.println("Credential Tokenizer - this demo will create a username token"); System.out.println(); context.setTokenType(com.csp.identity.UsernameToken.TOKEN_TYPE); context.createToken(testPrincipal, testPassword); System.out.println("Username=" + testPrincipal); System.out.println("Username token=" + (String)context.getToken()); } public static void main(String[] args) { new CredentialTokenizer(); } }