Filter:   InfoImg
download CredentialTokenizer.java
Language: Java
Copyright: (c) 2005 by Sun Microsystems/Ray Lai under Common Development and Distribution License
LOC: 27
Project Info
identity management security patterns(identitypatterns)
Server: java.net
Type: cvs
...terns\src\com\csp\identity\
   Assertion.java
   AssertionBuilder.java
   AssertionContext.java
   AssertionContextImpl.java
   Attribute.java
   AttributeStatement.java
   ...nticationStatement.java
   ...nDecisionStatement.java
   BinaryToken.java
   CredentialTokenizer.java
   SecurityToken.java
   SSOContext.java
   SSOContextImpl.java
   SSODelegator.java
   SSODelegatorException.java
   SSODelegatorFactory.java
   ...legatorFactoryImpl.java
   ...er_SampleFunction1.java
   SSOServiceProvider.java
   ...rviceProviderImpl1.java
   ...rviceProviderImpl2.java
   Subject.java
   TokenContext.java
   TokenContextImpl.java
   UsernameToken.java
   X509CertToken.java

 /*
 * 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();
    }
}