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