A
download TokenContextImpl.java
Language: Java
Copyright: (c) 2005 by Sun Microsystems/Ray Lai under Common Development and Distribution License
LOC: 44
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:    TokenContextImpl.java
 * Purpose:    Implementation class for Security Token
 * @author     Ray Lai (ray.lai@sun.com)
 * @version    1.0
 * Updated:    April 15, 2005, 4:53 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.
 * =====================================================================================
 */

package com.csp.identity;

public class TokenContextImpl implements com.csp.identity.TokenContext {
    
    protected com.csp.identity.UsernameToken  usernameToken;
    protected com.csp.identity.BinaryToken    binaryToken;    
    protected com.csp.identity.X509CertToken  x509CertToken;
    protected String                          tokenType;
    
    /** Constructor - Creates a new instance of CredentialTokenizer */
    public TokenContextImpl() {
        usernameToken = null;
        binaryToken = null;
        x509CertToken = null;
    }
    
    /**
     * Define token type
     * - use the constant in each security token subclass to define
     *
     * @param tokenType  security token type, e.g. USERNAME_TOKEN, X509CERT_TOKEN, BINARY_TOKEN, KERBEROS_TICKET
     **/
    public void setTokenType(String tokenType) {
        this.tokenType = tokenType;
    }
    
    /**
     * create security token based on the subject, principal and security token
     *
     * @param principal      principal
     * @param securityToken  security token can be binary,username, X.509v3 certificate, Kerberos ticket, etc     *
     **/
    public void createToken(String principal, Object securityToken) {
        if (this.tokenType.equals(com.csp.identity.UsernameToken.TOKEN_TYPE)) {
            usernameToken = new com.csp.identity.UsernameToken(principal, (String)securityToken);
        }
        else if (this.tokenType.equals(com.csp.identity.BinaryToken.TOKEN_TYPE)) {
            binaryToken = new com.csp.identity.BinaryToken(principal, (String)securityToken);            
        }
    }
    
    /**
     * get security token
     *
     * @return Object  any security token type, e.g. String, X.509v3 certificate
     **/
    public Object getToken() {
        if (this.tokenType.equals(com.csp.identity.UsernameToken.TOKEN_TYPE)) {
            return (Object)usernameToken.getToken();
        }
        else if (this.tokenType.equals(com.csp.identity.BinaryToken.TOKEN_TYPE)) {
            return (Object)binaryToken.getToken();
        }        
        else return null;
    }
   
    /**
     * get principal
     *
     * @return principal  return principal in String
     **/
    public String getPrincipal() {
       if (this.tokenType.equals(com.csp.identity.UsernameToken.TOKEN_TYPE)) {
            return usernameToken.getPrincipal();
        }
        else if (this.tokenType.equals(com.csp.identity.BinaryToken.TOKEN_TYPE)) {
            return binaryToken.getPrincipal();
        }        
        else return null;
    }

    /**
     * get protocol binding for the security token
     *
     * @return protocolBinding  protocol binding in String
     **/    
    public String getProtocolBinding() {
        return null;
    }
}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us