Mostly formatting changes.

This commit is contained in:
Juan Carlos Luciani 2006-05-08 21:48:05 +00:00
parent 79e2f829f4
commit 0983950115
15 changed files with 3006 additions and 2979 deletions

View File

@ -46,233 +46,237 @@ import org.xml.sax.helpers.XMLReaderFactory;
* </auth_req> * </auth_req>
* *
*/ */
public class AuthReqMsg { public class AuthReqMsg
{
protected String m_realm = null;
protected String m_authMechToken = null;
/*
* Class for handling Authentication Request parsing events.
*/
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
{
private final static int AWAITING_ROOT_ELEMENT_START = 0;
private final static int AWAITING_ROOT_ELEMENT_END = 1;
private final static int AWAITING_REALM_ELEMENT_START = 2;
private final static int AWAITING_REALM_ELEMENT_END = 3;
private final static int AWAITING_REALM_DATA = 4;
private final static int AWAITING_AUTH_MECH_TOKEN_ELEMENT_START = 5;
private final static int AWAITING_AUTH_MECH_TOKEN_ELEMENT_END = 6;
private final static int AWAITING_AUTH_MECH_TOKEN_DATA = 7;
private final static int DONE_PARSING = 8;
private AuthReqMsg m_authReqMsg;
private int m_state;
/* protected String m_realm = null;
* Constructor protected String m_authMechToken = null;
*/
public SAXHandler (AuthReqMsg authReqMsg)
{
super();
// Initialize our members
m_authReqMsg = authReqMsg;
m_state = AWAITING_ROOT_ELEMENT_START;
}
/* /*
* endDocument() implementation. * Class for handling Authentication Request parsing events.
*/ */
public void endDocument () throws SAXException private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
{ {
// Verify that we obtained all of the required elements private final static int AWAITING_ROOT_ELEMENT_START = 0;
if (m_state != DONE_PARSING) private final static int AWAITING_ROOT_ELEMENT_END = 1;
{ private final static int AWAITING_REALM_ELEMENT_START = 2;
System.err.println("AuthReqMsg SAXHandler.endDocument()- Missing element"); private final static int AWAITING_REALM_ELEMENT_END = 3;
throw new SAXException("Missing element"); private final static int AWAITING_REALM_DATA = 4;
} private final static int AWAITING_AUTH_MECH_TOKEN_ELEMENT_START = 5;
} private final static int AWAITING_AUTH_MECH_TOKEN_ELEMENT_END = 6;
private final static int AWAITING_AUTH_MECH_TOKEN_DATA = 7;
/* private final static int DONE_PARSING = 8;
* startElement() implementation.
*/
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
{
// Proceed based on our state
switch (m_state) {
case AWAITING_ROOT_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.authRequestElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_REALM_ELEMENT_START;
}
else
{
System.err.println("AuthReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_REALM_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.realmElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_REALM_DATA;
}
else
{
System.err.println("AuthReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_AUTH_MECH_TOKEN_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.authMechTokenElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_AUTH_MECH_TOKEN_DATA;
}
else
{
System.err.println("AuthReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("AuthReqMsg SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/* private AuthReqMsg m_authReqMsg;
* endElement() immplementation. private int m_state;
*/
public void endElement (String uri, String name, String qName) throws SAXException
{
// Proceed based on our state
switch (m_state) {
case AWAITING_ROOT_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.authRequestElementName.equals(qName))
{
// Advance to the next state
m_state = DONE_PARSING;
}
else
{
System.err.println("AuthReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_REALM_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.realmElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_AUTH_MECH_TOKEN_ELEMENT_START;
}
else
{
System.err.println("AuthReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_AUTH_MECH_TOKEN_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.authMechTokenElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_ROOT_ELEMENT_END;
}
else
{
System.err.println("AuthReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("AuthReqMsg SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* character() implementation.
*/
public void characters (char ch[], int start, int length) throws SAXException
{
// Proceed based on our state
switch (m_state) {
case AWAITING_REALM_DATA:
// Consume the data
m_authReqMsg.m_realm = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_REALM_ELEMENT_END;
break;
case AWAITING_AUTH_MECH_TOKEN_DATA:
// Consume the data
m_authReqMsg.m_authMechToken = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_AUTH_MECH_TOKEN_ELEMENT_END;
break;
default:
// Do nothing
break;
}
}
}
/*
* Constructor
*/
public AuthReqMsg (InputStream inStream) throws Exception
{
try
{
// Parse the AuthReqMsg
XMLReader xr = XMLReaderFactory.createXMLReader();
SAXHandler handler = new SAXHandler(this);
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
InputSource source = new InputSource(inStream);
xr.parse(source);
}
catch (SAXException e)
{
System.err.println("AuthReqMsg()- Parse exception: " + e.toString());
throw new Exception("Protocol error");
}
}
/*
* Method to get the authentication realm.
*/
public String getRealm() throws Exception
{
return m_realm;
}
/* /*
* Method to get the authentication mechanism token. * Constructor
*/ */
public String getAuthMechToken() throws Exception public SAXHandler (AuthReqMsg authReqMsg)
{ {
return m_authMechToken; super();
}
// Initialize our members
m_authReqMsg = authReqMsg;
m_state = AWAITING_ROOT_ELEMENT_START;
}
/*
* endDocument() implementation.
*/
public void endDocument () throws SAXException
{
// Verify that we obtained all of the required elements
if (m_state != DONE_PARSING)
{
System.err.println("AuthReqMsg SAXHandler.endDocument()- Missing element");
throw new SAXException("Missing element");
}
}
/*
* startElement() implementation.
*/
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
{
// Proceed based on our state
switch (m_state)
{
case AWAITING_ROOT_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.authRequestElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_REALM_ELEMENT_START;
}
else
{
System.err.println("AuthReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_REALM_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.realmElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_REALM_DATA;
}
else
{
System.err.println("AuthReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_AUTH_MECH_TOKEN_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.authMechTokenElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_AUTH_MECH_TOKEN_DATA;
}
else
{
System.err.println("AuthReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("AuthReqMsg SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* endElement() immplementation.
*/
public void endElement (String uri, String name, String qName) throws SAXException
{
// Proceed based on our state
switch (m_state)
{
case AWAITING_ROOT_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.authRequestElementName.equals(qName))
{
// Advance to the next state
m_state = DONE_PARSING;
}
else
{
System.err.println("AuthReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_REALM_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.realmElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_AUTH_MECH_TOKEN_ELEMENT_START;
}
else
{
System.err.println("AuthReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_AUTH_MECH_TOKEN_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.authMechTokenElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_ROOT_ELEMENT_END;
}
else
{
System.err.println("AuthReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("AuthReqMsg SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* character() implementation.
*/
public void characters (char ch[], int start, int length) throws SAXException
{
// Proceed based on our state
switch (m_state)
{
case AWAITING_REALM_DATA:
// Consume the data
m_authReqMsg.m_realm = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_REALM_ELEMENT_END;
break;
case AWAITING_AUTH_MECH_TOKEN_DATA:
// Consume the data
m_authReqMsg.m_authMechToken = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_AUTH_MECH_TOKEN_ELEMENT_END;
break;
default:
// Do nothing
break;
}
}
}
/*
* Constructor
*/
public AuthReqMsg (InputStream inStream) throws Exception
{
try
{
// Parse the AuthReqMsg
XMLReader xr = XMLReaderFactory.createXMLReader();
SAXHandler handler = new SAXHandler(this);
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
InputSource source = new InputSource(inStream);
xr.parse(source);
}
catch (SAXException e)
{
System.err.println("AuthReqMsg()- Parse exception: " + e.toString());
throw new Exception("Protocol error");
}
}
/*
* Method to get the authentication realm.
*/
public String getRealm() throws Exception
{
return m_realm;
}
/*
* Method to get the authentication mechanism token.
*/
public String getAuthMechToken() throws Exception
{
return m_authMechToken;
}
} }

View File

@ -49,64 +49,65 @@ package com.novell.casa.authtoksvc;
* in the HTTP 1.1 Specification. * in the HTTP 1.1 Specification.
* *
*/ */
public class AuthRespMsg { public class AuthRespMsg
{
String m_msg;
/*
* Constructor for a msg that does not include the session token.
*/
public AuthRespMsg (
String statusDescription,
String statusCode) throws Exception
{
// Get a StringBuffer to help us with the construction of the message
StringBuffer sb = new StringBuffer();
// Start building the message
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
sb.append("<" + ProtoDefs.authResponseElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.statusElementName + ">"
+ "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
+ statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.authResponseElementName + ">" + "\r\n");
// The message has now been built, save it.
m_msg = sb.toString();
}
/* String m_msg;
* Constructor for a msg that includes the session token.
*/ /*
public AuthRespMsg ( * Constructor for a msg that does not include the session token.
String statusDescription, */
String statusCode, public AuthRespMsg (
String sessionToken, String statusDescription,
String sessionTokenLifetime) throws Exception String statusCode) throws Exception
{ {
// Get a StringBuffer to help us with the construction of the message // Get a StringBuffer to help us with the construction of the message
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
// Start building the message // Start building the message
sb.append(ProtoDefs.xmlDeclaration + "\r\n"); sb.append(ProtoDefs.xmlDeclaration + "\r\n");
sb.append("<" + ProtoDefs.authResponseElementName + ">" + "\r\n"); sb.append("<" + ProtoDefs.authResponseElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.statusElementName + ">" sb.append("<" + ProtoDefs.statusElementName + ">"
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">" + "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n"); + statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.sessionTokenElementName + ">" sb.append("</" + ProtoDefs.authResponseElementName + ">" + "\r\n");
+ "<" + ProtoDefs.lifetimeElementName + ">" + sessionTokenLifetime + "</" + ProtoDefs.lifetimeElementName + ">"
+ sessionToken + "</" + ProtoDefs.sessionTokenElementName + ">" + "\r\n"); // The message has now been built, save it.
sb.append("</" + ProtoDefs.authResponseElementName + ">" + "\r\n"); m_msg = sb.toString();
}
// The message has now been built, save it.
m_msg = sb.toString(); /*
} * Constructor for a msg that includes the session token.
*/
/* public AuthRespMsg (
* Returns a string containing the AuthRespMsg. String statusDescription,
*/ String statusCode,
public String toString() String sessionToken,
{ String sessionTokenLifetime) throws Exception
return m_msg; {
} // Get a StringBuffer to help us with the construction of the message
StringBuffer sb = new StringBuffer();
// Start building the message
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
sb.append("<" + ProtoDefs.authResponseElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.statusElementName + ">"
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">"
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.sessionTokenElementName + ">"
+ "<" + ProtoDefs.lifetimeElementName + ">" + sessionTokenLifetime + "</" + ProtoDefs.lifetimeElementName + ">"
+ sessionToken + "</" + ProtoDefs.sessionTokenElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.authResponseElementName + ">" + "\r\n");
// The message has now been built, save it.
m_msg = sb.toString();
}
/*
* Returns a string containing the AuthRespMsg.
*/
public String toString()
{
return m_msg;
}
} }

View File

@ -47,406 +47,410 @@ import org.xml.sax.helpers.XMLReaderFactory;
* </auth_token> * </auth_token>
* *
*/ */
public class AuthToken { public class AuthToken
{
private String m_token;
private String m_lifetime;
private String m_identityTokenType;
private StringBuffer m_identityToken;
private String m_signature;
/*
* Class for handling parsing events.
*/
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
{
private final static int AWAITING_ROOT_ELEMENT_START = 0;
private final static int AWAITING_ROOT_ELEMENT_END = 1;
private final static int AWAITING_SIGNATURE_ELEMENT_START = 2;
private final static int AWAITING_SIGNATURE_ELEMENT_END = 3;
private final static int AWAITING_SIGNATURE_DATA = 4;
private final static int AWAITING_LIFETIME_ELEMENT_START = 5;
private final static int AWAITING_LIFETIME_ELEMENT_END = 6;
private final static int AWAITING_LIFETIME_DATA = 7;
private final static int AWAITING_IDENT_TOKEN_ELEMENT_START = 8;
private final static int AWAITING_IDENT_TOKEN_ELEMENT_END = 9;
private final static int AWAITING_IDENT_TOKEN_DATA = 10;
private final static int AWAITING_TYPE_ELEMENT_START = 11;
private final static int AWAITING_TYPE_ELEMENT_END = 12;
private final static int AWAITING_TYPE_DATA = 13;
private final static int DONE_PARSING = 14;
private AuthToken m_AuthToken;
private int m_state;
/* private String m_token;
* Constructor private String m_lifetime;
*/ private String m_identityTokenType;
public SAXHandler (AuthToken AuthToken) private StringBuffer m_identityToken;
{ private String m_signature;
super();
// Initialize our members
m_AuthToken = AuthToken;
m_state = AWAITING_ROOT_ELEMENT_START;
}
/* /*
* endDocument() implementation. * Class for handling parsing events.
*/ */
public void endDocument () throws SAXException private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
{ {
// Verify that we obtained all of the required elements private final static int AWAITING_ROOT_ELEMENT_START = 0;
if (m_state != DONE_PARSING) private final static int AWAITING_ROOT_ELEMENT_END = 1;
{ private final static int AWAITING_SIGNATURE_ELEMENT_START = 2;
System.err.println("AuthToken SAXHandler.endDocument()- Missing element"); private final static int AWAITING_SIGNATURE_ELEMENT_END = 3;
throw new SAXException("Missing element"); private final static int AWAITING_SIGNATURE_DATA = 4;
} private final static int AWAITING_LIFETIME_ELEMENT_START = 5;
} private final static int AWAITING_LIFETIME_ELEMENT_END = 6;
private final static int AWAITING_LIFETIME_DATA = 7;
/* private final static int AWAITING_IDENT_TOKEN_ELEMENT_START = 8;
* startElement() implementation. private final static int AWAITING_IDENT_TOKEN_ELEMENT_END = 9;
*/ private final static int AWAITING_IDENT_TOKEN_DATA = 10;
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException private final static int AWAITING_TYPE_ELEMENT_START = 11;
{ private final static int AWAITING_TYPE_ELEMENT_END = 12;
// Proceed based on our state private final static int AWAITING_TYPE_DATA = 13;
switch (m_state) { private final static int DONE_PARSING = 14;
case AWAITING_ROOT_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.authTokenElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SIGNATURE_ELEMENT_START;
}
else
{
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SIGNATURE_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.signatureElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SIGNATURE_DATA;
}
else
{
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_LIFETIME_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.lifetimeElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_LIFETIME_DATA;
}
else
{
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break; private AuthToken m_AuthToken;
private int m_state;
case AWAITING_IDENT_TOKEN_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.identTokenElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_TYPE_ELEMENT_START;
}
else
{
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_TYPE_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.typeElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_TYPE_DATA;
}
else
{
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("AuthToken SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/* /*
* endElement() immplementation. * Constructor
*/ */
public void endElement (String uri, String name, String qName) throws SAXException public SAXHandler (AuthToken AuthToken)
{ {
// Proceed based on our state super();
switch (m_state) {
case AWAITING_ROOT_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.authTokenElementName.equals(qName))
{
// Advance to the next state
m_state = DONE_PARSING;
}
else
{
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SIGNATURE_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.signatureElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_LIFETIME_ELEMENT_START;
}
else
{
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_LIFETIME_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.lifetimeElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_IDENT_TOKEN_ELEMENT_START;
}
else
{
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_TYPE_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.typeElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_IDENT_TOKEN_DATA;
}
else
{
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_IDENT_TOKEN_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.identTokenElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_ROOT_ELEMENT_END;
}
else
{
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("AuthToken SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* character() implementation.
*/
public void characters (char ch[], int start, int length) throws SAXException
{
// Proceed based on our state
switch (m_state) {
case AWAITING_SIGNATURE_DATA:
// Consume the data
m_AuthToken.m_signature = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_SIGNATURE_ELEMENT_END;
break;
case AWAITING_LIFETIME_DATA:
// Consume the data
m_AuthToken.m_lifetime = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_LIFETIME_ELEMENT_END;
break;
case AWAITING_TYPE_DATA:
// Consume the data
m_AuthToken.m_identityTokenType = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_TYPE_ELEMENT_END;
break;
case AWAITING_IDENT_TOKEN_DATA:
case AWAITING_IDENT_TOKEN_ELEMENT_END:
// Consume the data
m_AuthToken.m_identityToken.append(ch, start, length);
// Advance to the next state
m_state = AWAITING_IDENT_TOKEN_ELEMENT_END;
break;
default:
// Do nothing
break;
}
}
}
/*
* Constructor.
*/
public AuthToken (
String identityId,
String realm,
String targetService,
String targetHost) throws Exception
{
try
{
// Verify that we have support for the specified service.
// tbd
// For now lets use the services of the only IdentityToken provider
// that we have.
//
// tbd - Add code to allow for the consumption of tokens
// from different providers.
CasaIdentityToken identityToken = new CasaIdentityToken();
identityToken.initialize(identityId,
realm,
targetService,
targetHost);
m_identityToken = new StringBuffer();
m_identityToken.append(identityToken.getEncodedToken());
m_identityTokenType = identityToken.getProviderType();
m_lifetime = "56"; // tbd
// Generate a signature
// tbd - Over identToken, identToken type, and lifetime data.
m_signature = "tbd";
// Get a StringBuffer to help us with the construction of the token // Initialize our members
StringBuffer sb = new StringBuffer(); m_AuthToken = AuthToken;
m_state = AWAITING_ROOT_ELEMENT_START;
// Start building the message }
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
sb.append("<" + ProtoDefs.authTokenElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.signatureElementName + ">" + m_signature + "</" + ProtoDefs.signatureElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.lifetimeElementName + ">" + m_lifetime + "</" + ProtoDefs.lifetimeElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.identTokenElementName + ">"
+ "<" + ProtoDefs.typeElementName + ">" + m_identityTokenType + "</" + ProtoDefs.typeElementName + ">"
+ m_identityToken + "</" + ProtoDefs.identTokenElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.authTokenElementName + ">" + "\r\n");
// Save the token
m_token = sb.toString();
}
catch (Exception e)
{
// tbd
System.err.println("AuthToken()- Exception: " + e.toString());
}
}
/* /*
* Constructor given an authentication token string. The constructor * endDocument() implementation.
* validates the token as part of its processing. */
*/ public void endDocument () throws SAXException
public AuthToken(String token) throws Exception {
{ // Verify that we obtained all of the required elements
// Decode the token string if (m_state != DONE_PARSING)
m_token = Base64Coder.decode(token); {
System.err.println("AuthToken SAXHandler.endDocument()- Missing element");
// Instantiate string buffer for the identity token throw new SAXException("Missing element");
m_identityToken = new StringBuffer(); }
}
// Now parse the token into its elements
try
{
// Parse the AuthToken
XMLReader xr = XMLReaderFactory.createXMLReader();
SAXHandler handler = new SAXHandler(this);
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
ByteArrayInputStream inStream = new ByteArrayInputStream(m_token.getBytes());
InputSource source = new InputSource(inStream);
xr.parse(source);
// Verify the signature
// tbd
// Verify that the token has not expired
// tbd
}
catch (SAXException e)
{
System.err.println("AuthToken()- Parse exception: " + e.toString());
throw new Exception("Protocol error");
}
}
/* /*
* Returns a string containing the Base64 encode token. * startElement() implementation.
*/ */
public String toString() public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
{ {
return Base64Coder.encode(m_token); // Proceed based on our state
} switch (m_state)
{
/*
* Returns the lifetime of the token. case AWAITING_ROOT_ELEMENT_START:
*/ // Verify that we are processing the expected tag
public String getLifetime() if (ProtoDefs.authTokenElementName.equals(qName))
{ {
// tbd // Advance to the next state
return "60"; m_state = AWAITING_SIGNATURE_ELEMENT_START;
} }
else
/* {
* Returns the identity token. System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
*/ throw new SAXException("Un-expected element");
public String getIdentityToken() }
{ break;
return m_identityToken.toString();
} case AWAITING_SIGNATURE_ELEMENT_START:
// Verify that we are processing the expected tag
/* if (ProtoDefs.signatureElementName.equals(qName))
* Returns the identity token type. {
*/ // Advance to the next state
public String getIdentityTokenType() m_state = AWAITING_SIGNATURE_DATA;
{ }
return m_identityTokenType; else
} {
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_LIFETIME_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.lifetimeElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_LIFETIME_DATA;
}
else
{
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_IDENT_TOKEN_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.identTokenElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_TYPE_ELEMENT_START;
}
else
{
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_TYPE_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.typeElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_TYPE_DATA;
}
else
{
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("AuthToken SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* endElement() immplementation.
*/
public void endElement (String uri, String name, String qName) throws SAXException
{
// Proceed based on our state
switch (m_state)
{
case AWAITING_ROOT_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.authTokenElementName.equals(qName))
{
// Advance to the next state
m_state = DONE_PARSING;
}
else
{
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SIGNATURE_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.signatureElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_LIFETIME_ELEMENT_START;
}
else
{
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_LIFETIME_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.lifetimeElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_IDENT_TOKEN_ELEMENT_START;
}
else
{
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_TYPE_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.typeElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_IDENT_TOKEN_DATA;
}
else
{
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_IDENT_TOKEN_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.identTokenElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_ROOT_ELEMENT_END;
}
else
{
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("AuthToken SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* character() implementation.
*/
public void characters (char ch[], int start, int length) throws SAXException
{
// Proceed based on our state
switch (m_state)
{
case AWAITING_SIGNATURE_DATA:
// Consume the data
m_AuthToken.m_signature = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_SIGNATURE_ELEMENT_END;
break;
case AWAITING_LIFETIME_DATA:
// Consume the data
m_AuthToken.m_lifetime = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_LIFETIME_ELEMENT_END;
break;
case AWAITING_TYPE_DATA:
// Consume the data
m_AuthToken.m_identityTokenType = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_TYPE_ELEMENT_END;
break;
case AWAITING_IDENT_TOKEN_DATA:
case AWAITING_IDENT_TOKEN_ELEMENT_END:
// Consume the data
m_AuthToken.m_identityToken.append(ch, start, length);
// Advance to the next state
m_state = AWAITING_IDENT_TOKEN_ELEMENT_END;
break;
default:
// Do nothing
break;
}
}
}
/*
* Constructor.
*/
public AuthToken (
String identityId,
String realm,
String targetService,
String targetHost) throws Exception
{
try
{
// Verify that we have support for the specified service.
// tbd
// For now lets use the services of the only IdentityToken provider
// that we have.
//
// tbd - Add code to allow for the consumption of tokens
// from different providers.
CasaIdentityToken identityToken = new CasaIdentityToken();
identityToken.initialize(identityId,
realm,
targetService,
targetHost);
m_identityToken = new StringBuffer();
m_identityToken.append(identityToken.getEncodedToken());
m_identityTokenType = identityToken.getProviderType();
m_lifetime = "56"; // tbd
// Generate a signature
// tbd - Over identToken, identToken type, and lifetime data.
m_signature = "tbd";
// Get a StringBuffer to help us with the construction of the token
StringBuffer sb = new StringBuffer();
// Start building the message
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
sb.append("<" + ProtoDefs.authTokenElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.signatureElementName + ">" + m_signature + "</" + ProtoDefs.signatureElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.lifetimeElementName + ">" + m_lifetime + "</" + ProtoDefs.lifetimeElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.identTokenElementName + ">"
+ "<" + ProtoDefs.typeElementName + ">" + m_identityTokenType + "</" + ProtoDefs.typeElementName + ">"
+ m_identityToken + "</" + ProtoDefs.identTokenElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.authTokenElementName + ">" + "\r\n");
// Save the token
m_token = sb.toString();
}
catch (Exception e)
{
// tbd
System.err.println("AuthToken()- Exception: " + e.toString());
}
}
/*
* Constructor given an authentication token string. The constructor
* validates the token as part of its processing.
*/
public AuthToken(String token) throws Exception
{
// Decode the token string
m_token = Base64Coder.decode(token);
// Instantiate string buffer for the identity token
m_identityToken = new StringBuffer();
// Now parse the token into its elements
try
{
// Parse the AuthToken
XMLReader xr = XMLReaderFactory.createXMLReader();
SAXHandler handler = new SAXHandler(this);
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
ByteArrayInputStream inStream = new ByteArrayInputStream(m_token.getBytes());
InputSource source = new InputSource(inStream);
xr.parse(source);
// Verify the signature
// tbd
// Verify that the token has not expired
// tbd
}
catch (SAXException e)
{
System.err.println("AuthToken()- Parse exception: " + e.toString());
throw new Exception("Protocol error");
}
}
/*
* Returns a string containing the Base64 encode token.
*/
public String toString()
{
return Base64Coder.encode(m_token);
}
/*
* Returns the lifetime of the token.
*/
public String getLifetime()
{
// tbd
return "60";
}
/*
* Returns the identity token.
*/
public String getIdentityToken()
{
return m_identityToken.toString();
}
/*
* Returns the identity token type.
*/
public String getIdentityTokenType()
{
return m_identityTokenType;
}
} }

View File

@ -39,99 +39,98 @@ import javax.servlet.http.HttpServletResponse;
* service. * service.
* *
*/ */
public class GetAuthPolicy extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet public class GetAuthPolicy extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
{ {
private static final long serialVersionUID = -8264027868130334613L; private static final long serialVersionUID = -8264027868130334613L;
/* /*
* Constructor. * Constructor.
*/ */
public GetAuthPolicy() public GetAuthPolicy()
{ {
super(); super();
} }
/*
* doGet() implementation.
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost(request, response);
}
/*
* doPost() implementation.
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// Get ready to send back a reply
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try /*
{ * doGet() implementation.
// Read and parse the GetAuthPolicyReqMsg sent from the client */
InputStream inStream = request.getInputStream(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
GetAuthPolicyReqMsg getAuthPolicyReqMsg = new GetAuthPolicyReqMsg(inStream); {
// Get the auth policy for the service
byte[] authPolicy = getAuthPolicyFileData(getAuthPolicyReqMsg.getServiceName(),
getAuthPolicyReqMsg.getHostName());
// Write out the response doPost(request, response);
GetAuthPolicyRespMsg getAuthPolicyRespMsg = new GetAuthPolicyRespMsg(ProtoDefs.httpOkStatusMsg, }
ProtoDefs.httpOkStatusCode,
new String(Base64Coder.encode(authPolicy))); /*
out.println(getAuthPolicyRespMsg.toString()); * doPost() implementation.
} */
catch (Exception e) protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{ {
// tbd // Get ready to send back a reply
System.err.println("GetAuthPolicy.doPost()- Exception caught: " + e.toString()); response.setContentType("text/html");
PrintWriter out = response.getWriter();
// Write out the response
try try
{ {
GetAuthPolicyRespMsg getAuthPolicyRespMsg = new GetAuthPolicyRespMsg(ProtoDefs.httpServerErrorStatusMsg, // Read and parse the GetAuthPolicyReqMsg sent from the client
ProtoDefs.httpServerErrorStatusCode); InputStream inStream = request.getInputStream();
out.println(getAuthPolicyRespMsg.toString()); GetAuthPolicyReqMsg getAuthPolicyReqMsg = new GetAuthPolicyReqMsg(inStream);
}
catch (Exception e2) // Get the auth policy for the service
{ byte[] authPolicy = getAuthPolicyFileData(getAuthPolicyReqMsg.getServiceName(),
System.err.println("GetAuthPolicy.doPost()- Exception trying to construct response msg: " + e2.toString()); getAuthPolicyReqMsg.getHostName());
}
} // Write out the response
GetAuthPolicyRespMsg getAuthPolicyRespMsg = new GetAuthPolicyRespMsg(ProtoDefs.httpOkStatusMsg,
// Done sending out the reply ProtoDefs.httpOkStatusCode,
out.close(); new String(Base64Coder.encode(authPolicy)));
} out.println(getAuthPolicyRespMsg.toString());
}
/* catch (Exception e)
* Returns the data associated with the authentication policy file {
* associated with the specified service. // tbd
*/ System.err.println("GetAuthPolicy.doPost()- Exception caught: " + e.toString());
private byte[] getAuthPolicyFileData(String serviceName, String hostName)
{ // Write out the response
// tdb - Read the file associated with the specified service try
StringBuffer sb = new StringBuffer(); {
GetAuthPolicyRespMsg getAuthPolicyRespMsg = new GetAuthPolicyRespMsg(ProtoDefs.httpServerErrorStatusMsg,
// Start building the policy data ProtoDefs.httpServerErrorStatusCode);
sb.append(ProtoDefs.xmlDeclaration + "\r\n"); out.println(getAuthPolicyRespMsg.toString());
sb.append("<" + ProtoDefs.authPolicyElementName + ">" + "\r\n"); }
sb.append("<" + ProtoDefs.authSourceElementName + ">" + "\r\n"); catch (Exception e2)
sb.append("<" + ProtoDefs.realmElementName + ">" + "jctree" + "</" + ProtoDefs.realmElementName + ">" + "\r\n"); {
sb.append("<" + ProtoDefs.mechanismElementName + ">" + "Krb5Authenticate" + "</" + ProtoDefs.mechanismElementName + ">" + "\r\n"); System.err.println("GetAuthPolicy.doPost()- Exception trying to construct response msg: " + e2.toString());
sb.append("<" + ProtoDefs.mechanismInfoElementName + ">" + "host/jcstation.dnsdhcp.provo.novell.com" + "</" + ProtoDefs.mechanismInfoElementName + ">" + "\r\n"); }
sb.append("</" + ProtoDefs.authSourceElementName + ">" + "\r\n"); }
sb.append("<" + ProtoDefs.authSourceElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.realmElementName + ">" + "jctree" + "</" + ProtoDefs.realmElementName + ">" + "\r\n"); // Done sending out the reply
sb.append("<" + ProtoDefs.mechanismElementName + ">" + "PwdAuthenticate" + "</" + ProtoDefs.mechanismElementName + ">" + "\r\n"); out.close();
sb.append("<" + ProtoDefs.mechanismInfoElementName + ">" + "" + "</" + ProtoDefs.mechanismInfoElementName + ">" + "\r\n"); }
sb.append("</" + ProtoDefs.authSourceElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.authPolicyElementName + ">" + "\r\n"); /*
String s = sb.toString(); * Returns the data associated with the authentication policy file
return s.getBytes(); * associated with the specified service.
} */
} private byte[] getAuthPolicyFileData(String serviceName, String hostName)
{
// tdb - Read the file associated with the specified service
StringBuffer sb = new StringBuffer();
// Start building the policy data
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
sb.append("<" + ProtoDefs.authPolicyElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.authSourceElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.realmElementName + ">" + "jctree" + "</" + ProtoDefs.realmElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.mechanismElementName + ">" + "Krb5Authenticate" + "</" + ProtoDefs.mechanismElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.mechanismInfoElementName + ">" + "host/jcstation.dnsdhcp.provo.novell.com" + "</" + ProtoDefs.mechanismInfoElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.authSourceElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.authSourceElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.realmElementName + ">" + "jctree" + "</" + ProtoDefs.realmElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.mechanismElementName + ">" + "PwdAuthenticate" + "</" + ProtoDefs.mechanismElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.mechanismInfoElementName + ">" + "" + "</" + ProtoDefs.mechanismInfoElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.authSourceElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.authPolicyElementName + ">" + "\r\n");
String s = sb.toString();
return s.getBytes();
}
}

View File

@ -45,234 +45,238 @@ import org.xml.sax.helpers.XMLReaderFactory;
* </get_auth_policy_req> * </get_auth_policy_req>
* *
*/ */
public class GetAuthPolicyReqMsg { public class GetAuthPolicyReqMsg
{
protected String m_serviceName = null; protected String m_serviceName = null;
protected String m_hostName = null; protected String m_hostName = null;
/*
* Class for handling GetAuthPolicyReq msg parsing events.
*/
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
{
private final static int AWAITING_ROOT_ELEMENT_START = 0;
private final static int AWAITING_ROOT_ELEMENT_END = 1;
private final static int AWAITING_SERVICE_ELEMENT_START = 2;
private final static int AWAITING_SERVICE_ELEMENT_END = 3;
private final static int AWAITING_SERVICE_DATA = 4;
private final static int AWAITING_HOST_ELEMENT_START = 5;
private final static int AWAITING_HOST_ELEMENT_END = 6;
private final static int AWAITING_HOST_DATA = 7;
private final static int DONE_PARSING = 8;
private GetAuthPolicyReqMsg m_GetAuthPolicyReqMsg;
private int m_state;
/* /*
* Constructor * Class for handling GetAuthPolicyReq msg parsing events.
*/ */
public SAXHandler (GetAuthPolicyReqMsg GetAuthPolicyReqMsg) private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
{ {
super(); private final static int AWAITING_ROOT_ELEMENT_START = 0;
private final static int AWAITING_ROOT_ELEMENT_END = 1;
// Initialize our members private final static int AWAITING_SERVICE_ELEMENT_START = 2;
m_GetAuthPolicyReqMsg = GetAuthPolicyReqMsg; private final static int AWAITING_SERVICE_ELEMENT_END = 3;
m_state = AWAITING_ROOT_ELEMENT_START; private final static int AWAITING_SERVICE_DATA = 4;
} private final static int AWAITING_HOST_ELEMENT_START = 5;
private final static int AWAITING_HOST_ELEMENT_END = 6;
private final static int AWAITING_HOST_DATA = 7;
private final static int DONE_PARSING = 8;
/* private GetAuthPolicyReqMsg m_GetAuthPolicyReqMsg;
* endDocument() implementation. private int m_state;
*/
public void endDocument () throws SAXException
{
// Verify that we obtained all of the required elements
if (m_state != DONE_PARSING)
{
System.err.println("GetAuthPolicyReqMsg SAXHandler.endDocument()- Missing element");
throw new SAXException("Missing element");
}
}
/*
* startElement() implementation.
*/
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
{
// Proceed based on our state
switch (m_state) {
case AWAITING_ROOT_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.getAuthPolicyRequestElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SERVICE_ELEMENT_START;
}
else
{
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SERVICE_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.serviceElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SERVICE_DATA;
}
else
{
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_HOST_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.hostElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_HOST_DATA;
}
else
{
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break; /*
* Constructor
default: */
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- State error"); public SAXHandler (GetAuthPolicyReqMsg GetAuthPolicyReqMsg)
throw new SAXException("State error"); {
} super();
}
/* // Initialize our members
* endElement() immplementation. m_GetAuthPolicyReqMsg = GetAuthPolicyReqMsg;
*/ m_state = AWAITING_ROOT_ELEMENT_START;
public void endElement (String uri, String name, String qName) throws SAXException }
{
// Proceed based on our state
switch (m_state) {
case AWAITING_ROOT_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.getAuthPolicyRequestElementName.equals(qName))
{
// Advance to the next state
m_state = DONE_PARSING;
}
else
{
System.err.println("GetAuthPolicyReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SERVICE_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.serviceElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_HOST_ELEMENT_START;
}
else
{
System.err.println("GetAuthPolicyReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_HOST_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.hostElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_ROOT_ELEMENT_END;
}
else
{
System.err.println("GetAuthPolicyReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* character() implementation.
*/
public void characters (char ch[], int start, int length) throws SAXException
{
// Proceed based on our state
switch (m_state) {
case AWAITING_SERVICE_DATA:
// Consume the data
m_GetAuthPolicyReqMsg.m_serviceName = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_SERVICE_ELEMENT_END;
break;
case AWAITING_HOST_DATA:
// Consume the data
m_GetAuthPolicyReqMsg.m_hostName = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_HOST_ELEMENT_END;
break;
default:
// Do nothing
break;
}
}
}
/*
* Constructor
*/
public GetAuthPolicyReqMsg (InputStream inStream) throws Exception
{
try
{
// Parse the GetAuthPolicyReqMsg
XMLReader xr = XMLReaderFactory.createXMLReader();
SAXHandler handler = new SAXHandler(this);
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
InputSource source = new InputSource(inStream);
xr.parse(source);
}
catch (SAXException e)
{
System.err.println("GetAuthPolicyReqMsg()- Parse exception: " + e.toString());
throw new Exception("Protocol error");
}
}
/* /*
* Method to get the service name. * endDocument() implementation.
*/ */
public String getServiceName() throws Exception public void endDocument () throws SAXException
{ {
return m_serviceName; // Verify that we obtained all of the required elements
} if (m_state != DONE_PARSING)
{
/* System.err.println("GetAuthPolicyReqMsg SAXHandler.endDocument()- Missing element");
* Method to get the host name. throw new SAXException("Missing element");
*/ }
public String getHostName() throws Exception }
{
return m_hostName; /*
} * startElement() implementation.
*/
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
{
// Proceed based on our state
switch (m_state)
{
case AWAITING_ROOT_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.getAuthPolicyRequestElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SERVICE_ELEMENT_START;
}
else
{
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SERVICE_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.serviceElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SERVICE_DATA;
}
else
{
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_HOST_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.hostElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_HOST_DATA;
}
else
{
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* endElement() immplementation.
*/
public void endElement (String uri, String name, String qName) throws SAXException
{
// Proceed based on our state
switch (m_state)
{
case AWAITING_ROOT_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.getAuthPolicyRequestElementName.equals(qName))
{
// Advance to the next state
m_state = DONE_PARSING;
}
else
{
System.err.println("GetAuthPolicyReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SERVICE_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.serviceElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_HOST_ELEMENT_START;
}
else
{
System.err.println("GetAuthPolicyReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_HOST_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.hostElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_ROOT_ELEMENT_END;
}
else
{
System.err.println("GetAuthPolicyReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* character() implementation.
*/
public void characters (char ch[], int start, int length) throws SAXException
{
// Proceed based on our state
switch (m_state)
{
case AWAITING_SERVICE_DATA:
// Consume the data
m_GetAuthPolicyReqMsg.m_serviceName = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_SERVICE_ELEMENT_END;
break;
case AWAITING_HOST_DATA:
// Consume the data
m_GetAuthPolicyReqMsg.m_hostName = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_HOST_ELEMENT_END;
break;
default:
// Do nothing
break;
}
}
}
/*
* Constructor
*/
public GetAuthPolicyReqMsg (InputStream inStream) throws Exception
{
try
{
// Parse the GetAuthPolicyReqMsg
XMLReader xr = XMLReaderFactory.createXMLReader();
SAXHandler handler = new SAXHandler(this);
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
InputSource source = new InputSource(inStream);
xr.parse(source);
}
catch (SAXException e)
{
System.err.println("GetAuthPolicyReqMsg()- Parse exception: " + e.toString());
throw new Exception("Protocol error");
}
}
/*
* Method to get the service name.
*/
public String getServiceName() throws Exception
{
return m_serviceName;
}
/*
* Method to get the host name.
*/
public String getHostName() throws Exception
{
return m_hostName;
}
} }

View File

@ -50,61 +50,62 @@ package com.novell.casa.authtoksvc;
* in the HTTP 1.1 Specification. * in the HTTP 1.1 Specification.
* *
*/ */
public class GetAuthPolicyRespMsg { public class GetAuthPolicyRespMsg
{
String m_msg;
/*
* Constructor for a msg that does not include the authentication policy.
*/
public GetAuthPolicyRespMsg (
String statusDescription,
String statusCode) throws Exception
{
// Get a StringBuffer to help us with the construction of the message
StringBuffer sb = new StringBuffer();
// Start building the message
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
sb.append("<" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.statusElementName + ">"
+ "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
+ statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
// The message has now been built, save it.
m_msg = sb.toString();
}
/* String m_msg;
* Constructor for a msg that includes the authentication policy.
*/ /*
public GetAuthPolicyRespMsg ( * Constructor for a msg that does not include the authentication policy.
String statusDescription, */
String statusCode, public GetAuthPolicyRespMsg (
String authPolicy) throws Exception String statusDescription,
{ String statusCode) throws Exception
// Get a StringBuffer to help us with the construction of the message {
StringBuffer sb = new StringBuffer(); // Get a StringBuffer to help us with the construction of the message
StringBuffer sb = new StringBuffer();
// Start building the message
sb.append(ProtoDefs.xmlDeclaration + "\r\n"); // Start building the message
sb.append("<" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n"); sb.append(ProtoDefs.xmlDeclaration + "\r\n");
sb.append("<" + ProtoDefs.statusElementName + ">" sb.append("<" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">" sb.append("<" + ProtoDefs.statusElementName + ">"
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n"); + "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
sb.append("<" + ProtoDefs.authPolicyElementName + ">" + authPolicy + "</" + ProtoDefs.authPolicyElementName + ">" + "\r\n"); + statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n"); sb.append("</" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
// The message has now been built, save it. // The message has now been built, save it.
m_msg = sb.toString(); m_msg = sb.toString();
} }
/* /*
* Returns a string containing the GetAuthPolicyRespMsg. * Constructor for a msg that includes the authentication policy.
*/ */
public String toString() public GetAuthPolicyRespMsg (
{ String statusDescription,
return m_msg; String statusCode,
} String authPolicy) throws Exception
{
// Get a StringBuffer to help us with the construction of the message
StringBuffer sb = new StringBuffer();
// Start building the message
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
sb.append("<" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.statusElementName + ">"
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">"
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.authPolicyElementName + ">" + authPolicy + "</" + ProtoDefs.authPolicyElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
// The message has now been built, save it.
m_msg = sb.toString();
}
/*
* Returns a string containing the GetAuthPolicyRespMsg.
*/
public String toString()
{
return m_msg;
}
} }

View File

@ -46,282 +46,286 @@ import org.xml.sax.helpers.XMLReaderFactory;
* </get_auth_token_req> * </get_auth_token_req>
* *
*/ */
public class GetAuthTokReqMsg { public class GetAuthTokReqMsg
{
protected String m_serviceName = null; protected String m_serviceName = null;
protected String m_hostName = null; protected String m_hostName = null;
protected String m_sessionToken = null; protected String m_sessionToken = null;
/*
* Class for handling GetAuthTokReq msg parsing events.
*/
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
{
private final static int AWAITING_ROOT_ELEMENT_START = 0;
private final static int AWAITING_ROOT_ELEMENT_END = 1;
private final static int AWAITING_SERVICE_ELEMENT_START = 2;
private final static int AWAITING_SERVICE_ELEMENT_END = 3;
private final static int AWAITING_SERVICE_DATA = 4;
private final static int AWAITING_HOST_ELEMENT_START = 5;
private final static int AWAITING_HOST_ELEMENT_END = 6;
private final static int AWAITING_HOST_DATA = 7;
private final static int AWAITING_SESSION_TOKEN_ELEMENT_START = 8;
private final static int AWAITING_SESSION_TOKEN_ELEMENT_END = 9;
private final static int AWAITING_SESSION_TOKEN_DATA = 10;
private final static int DONE_PARSING = 11;
private GetAuthTokReqMsg m_GetAuthTokReqMsg;
private int m_state;
/* /*
* Constructor * Class for handling GetAuthTokReq msg parsing events.
*/ */
public SAXHandler (GetAuthTokReqMsg GetAuthTokReqMsg) private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
{ {
super(); private final static int AWAITING_ROOT_ELEMENT_START = 0;
private final static int AWAITING_ROOT_ELEMENT_END = 1;
// Initialize our members private final static int AWAITING_SERVICE_ELEMENT_START = 2;
m_GetAuthTokReqMsg = GetAuthTokReqMsg; private final static int AWAITING_SERVICE_ELEMENT_END = 3;
m_state = AWAITING_ROOT_ELEMENT_START; private final static int AWAITING_SERVICE_DATA = 4;
} private final static int AWAITING_HOST_ELEMENT_START = 5;
private final static int AWAITING_HOST_ELEMENT_END = 6;
private final static int AWAITING_HOST_DATA = 7;
private final static int AWAITING_SESSION_TOKEN_ELEMENT_START = 8;
private final static int AWAITING_SESSION_TOKEN_ELEMENT_END = 9;
private final static int AWAITING_SESSION_TOKEN_DATA = 10;
private final static int DONE_PARSING = 11;
/* private GetAuthTokReqMsg m_GetAuthTokReqMsg;
* endDocument() implementation. private int m_state;
*/
public void endDocument () throws SAXException
{
// Verify that we obtained all of the required elements
if (m_state != DONE_PARSING)
{
System.err.println("GetAuthTokReqMsg SAXHandler.endDocument()- Missing element");
throw new SAXException("Missing element");
}
}
/*
* startElement() implementation.
*/
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
{
// Proceed based on our state
switch (m_state) {
case AWAITING_ROOT_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.getAuthTokRequestElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SERVICE_ELEMENT_START;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SERVICE_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.serviceElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SERVICE_DATA;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_HOST_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.hostElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_HOST_DATA;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break; /*
* Constructor
case AWAITING_SESSION_TOKEN_ELEMENT_START: */
// Verify that we are processing the expected tag public SAXHandler (GetAuthTokReqMsg GetAuthTokReqMsg)
if (ProtoDefs.sessionTokenElementName.equals(qName)) {
{ super();
// Advance to the next state
m_state = AWAITING_SESSION_TOKEN_DATA;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/* // Initialize our members
* endElement() immplementation. m_GetAuthTokReqMsg = GetAuthTokReqMsg;
*/ m_state = AWAITING_ROOT_ELEMENT_START;
public void endElement (String uri, String name, String qName) throws SAXException }
{
// Proceed based on our state
switch (m_state) {
case AWAITING_ROOT_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.getAuthTokRequestElementName.equals(qName))
{
// Advance to the next state
m_state = DONE_PARSING;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SERVICE_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.serviceElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_HOST_ELEMENT_START;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_HOST_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.hostElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SESSION_TOKEN_ELEMENT_START;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SESSION_TOKEN_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.sessionTokenElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_ROOT_ELEMENT_END;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* character() implementation.
*/
public void characters (char ch[], int start, int length) throws SAXException
{
// Proceed based on our state
switch (m_state) {
case AWAITING_SERVICE_DATA:
// Consume the data
m_GetAuthTokReqMsg.m_serviceName = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_SERVICE_ELEMENT_END;
break;
case AWAITING_HOST_DATA:
// Consume the data
m_GetAuthTokReqMsg.m_hostName = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_HOST_ELEMENT_END;
break;
case AWAITING_SESSION_TOKEN_DATA:
// Consume the data
m_GetAuthTokReqMsg.m_sessionToken = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_SESSION_TOKEN_ELEMENT_END;
break;
default:
// Do nothing
break;
}
}
}
/*
* Constructor
*/
public GetAuthTokReqMsg (InputStream inStream) throws Exception
{
try
{
// Parse the GetAuthTokReqMsg
XMLReader xr = XMLReaderFactory.createXMLReader();
SAXHandler handler = new SAXHandler(this);
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
InputSource source = new InputSource(inStream);
xr.parse(source);
}
catch (SAXException e)
{
System.err.println("GetAuthTokReqMsg()- Parse exception: " + e.toString());
throw new Exception("Protocol error");
}
}
/* /*
* Method to get the service name. * endDocument() implementation.
*/ */
public String getServiceName() throws Exception public void endDocument () throws SAXException
{ {
return m_serviceName; // Verify that we obtained all of the required elements
} if (m_state != DONE_PARSING)
{
/* System.err.println("GetAuthTokReqMsg SAXHandler.endDocument()- Missing element");
* Method to get the host name. throw new SAXException("Missing element");
*/ }
public String getHostName() throws Exception }
{
return m_hostName; /*
} * startElement() implementation.
*/
/* public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
* Method to get the session token. {
*/ // Proceed based on our state
public String getSessionToken() throws Exception switch (m_state)
{ {
return m_sessionToken;
} case AWAITING_ROOT_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.getAuthTokRequestElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SERVICE_ELEMENT_START;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SERVICE_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.serviceElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SERVICE_DATA;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_HOST_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.hostElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_HOST_DATA;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SESSION_TOKEN_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.sessionTokenElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SESSION_TOKEN_DATA;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* endElement() immplementation.
*/
public void endElement (String uri, String name, String qName) throws SAXException
{
// Proceed based on our state
switch (m_state)
{
case AWAITING_ROOT_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.getAuthTokRequestElementName.equals(qName))
{
// Advance to the next state
m_state = DONE_PARSING;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SERVICE_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.serviceElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_HOST_ELEMENT_START;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_HOST_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.hostElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SESSION_TOKEN_ELEMENT_START;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SESSION_TOKEN_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.sessionTokenElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_ROOT_ELEMENT_END;
}
else
{
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* character() implementation.
*/
public void characters (char ch[], int start, int length) throws SAXException
{
// Proceed based on our state
switch (m_state)
{
case AWAITING_SERVICE_DATA:
// Consume the data
m_GetAuthTokReqMsg.m_serviceName = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_SERVICE_ELEMENT_END;
break;
case AWAITING_HOST_DATA:
// Consume the data
m_GetAuthTokReqMsg.m_hostName = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_HOST_ELEMENT_END;
break;
case AWAITING_SESSION_TOKEN_DATA:
// Consume the data
m_GetAuthTokReqMsg.m_sessionToken = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_SESSION_TOKEN_ELEMENT_END;
break;
default:
// Do nothing
break;
}
}
}
/*
* Constructor
*/
public GetAuthTokReqMsg (InputStream inStream) throws Exception
{
try
{
// Parse the GetAuthTokReqMsg
XMLReader xr = XMLReaderFactory.createXMLReader();
SAXHandler handler = new SAXHandler(this);
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
InputSource source = new InputSource(inStream);
xr.parse(source);
}
catch (SAXException e)
{
System.err.println("GetAuthTokReqMsg()- Parse exception: " + e.toString());
throw new Exception("Protocol error");
}
}
/*
* Method to get the service name.
*/
public String getServiceName() throws Exception
{
return m_serviceName;
}
/*
* Method to get the host name.
*/
public String getHostName() throws Exception
{
return m_hostName;
}
/*
* Method to get the session token.
*/
public String getSessionToken() throws Exception
{
return m_sessionToken;
}
} }

View File

@ -50,65 +50,66 @@ package com.novell.casa.authtoksvc;
* in the HTTP 1.1 Specification. * in the HTTP 1.1 Specification.
* *
*/ */
public class GetAuthTokRespMsg { public class GetAuthTokRespMsg
{
String m_msg;
/*
* Constructor for a msg that does not include the authentication token.
*/
public GetAuthTokRespMsg (
String statusDescription,
String statusCode) throws Exception
{
// Get a StringBuffer to help us with the construction of the message
StringBuffer sb = new StringBuffer();
// Start building the message
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
sb.append("<" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.statusElementName + ">"
+ "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
+ statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
// The message has now been built, save it.
m_msg = sb.toString();
}
/* String m_msg;
* Constructor for a msg that includes the authentication token.
*/ /*
public GetAuthTokRespMsg ( * Constructor for a msg that does not include the authentication token.
String statusDescription, */
String statusCode, public GetAuthTokRespMsg (
String authToken, String statusDescription,
String authTokenLifetime) throws Exception String statusCode) throws Exception
{ {
// Get a StringBuffer to help us with the construction of the message // Get a StringBuffer to help us with the construction of the message
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
// Start building the message // Start building the message
sb.append(ProtoDefs.xmlDeclaration + "\r\n"); sb.append(ProtoDefs.xmlDeclaration + "\r\n");
sb.append("<" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n"); sb.append("<" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.statusElementName + ">" sb.append("<" + ProtoDefs.statusElementName + ">"
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">" + "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n"); + statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.authTokenElementName + ">" sb.append("</" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
+ "<" + ProtoDefs.lifetimeElementName + ">" + authTokenLifetime + "</" + ProtoDefs.lifetimeElementName + ">"
+ authToken + "</" + ProtoDefs.authTokenElementName + ">" + "\r\n"); // The message has now been built, save it.
sb.append("</" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n"); m_msg = sb.toString();
}
// The message has now been built, save it.
m_msg = sb.toString(); /*
} * Constructor for a msg that includes the authentication token.
*/
/* public GetAuthTokRespMsg (
* Returns a string containing the GetAuthTokRespMsg. String statusDescription,
*/ String statusCode,
public String toString() String authToken,
{ String authTokenLifetime) throws Exception
return m_msg; {
} // Get a StringBuffer to help us with the construction of the message
StringBuffer sb = new StringBuffer();
// Start building the message
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
sb.append("<" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.statusElementName + ">"
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">"
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.authTokenElementName + ">"
+ "<" + ProtoDefs.lifetimeElementName + ">" + authTokenLifetime + "</" + ProtoDefs.lifetimeElementName + ">"
+ authToken + "</" + ProtoDefs.authTokenElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
// The message has now been built, save it.
m_msg = sb.toString();
}
/*
* Returns a string containing the GetAuthTokRespMsg.
*/
public String toString()
{
return m_msg;
}
} }

View File

@ -39,97 +39,97 @@ import javax.servlet.http.HttpServletResponse;
* to a particular service. * to a particular service.
* *
*/ */
public class GetAuthToken extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet public class GetAuthToken extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
{ {
private static final long serialVersionUID = -5792862615065914894L; private static final long serialVersionUID = -5792862615065914894L;
/* /*
* Constructor. * Constructor.
*/ */
public GetAuthToken() public GetAuthToken()
{ {
super(); super();
} }
/*
* doGet() implementation.
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// Just let doPost() handle it.
doPost(request, response);
}
/*
* doPost() implementation.
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// Get ready to send back a reply
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try /*
{ * doGet() implementation.
// Read and parse the GetAuthTokReqMsg sent from the client */
InputStream inStream = request.getInputStream(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
GetAuthTokReqMsg getAuthTokReqMsg = new GetAuthTokReqMsg(inStream); {
// Just let doPost() handle it.
// Now create a session token (This validates the session token provided). doPost(request, response);
SessionToken sessionToken = new SessionToken(getAuthTokReqMsg.getSessionToken()); }
try /*
{ * doPost() implementation.
// Create the Authentication Token */
AuthToken authToken = new AuthToken(sessionToken.getIdentId(), protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
sessionToken.getRealm(), {
getAuthTokReqMsg.getServiceName(), // Get ready to send back a reply
getAuthTokReqMsg.getHostName()); response.setContentType("text/html");
PrintWriter out = response.getWriter();
// Write out the response
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpOkStatusMsg, try
ProtoDefs.httpOkStatusCode, {
authToken.toString(), // Read and parse the GetAuthTokReqMsg sent from the client
authToken.getLifetime()); InputStream inStream = request.getInputStream();
out.println(getAuthTokRespMsg.toString()); GetAuthTokReqMsg getAuthTokReqMsg = new GetAuthTokReqMsg(inStream);
}
catch (Exception e) // Now create a session token (This validates the session token provided).
{ SessionToken sessionToken = new SessionToken(getAuthTokReqMsg.getSessionToken());
// tbd, use a custom exception and then set the status based
// on the type of exeption cached. try
{
// Write out the response // Create the Authentication Token
try AuthToken authToken = new AuthToken(sessionToken.getIdentId(),
{ sessionToken.getRealm(),
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpServerErrorStatusMsg, getAuthTokReqMsg.getServiceName(),
ProtoDefs.httpUnauthorizedStatusCode); getAuthTokReqMsg.getHostName());
out.println(getAuthTokRespMsg.toString());
} // Write out the response
catch (Exception e2) GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpOkStatusMsg,
{ ProtoDefs.httpOkStatusCode,
System.err.println("GetAuthToken.doPost()- Exception trying to construct response msg: " + e2.toString()); authToken.toString(),
} authToken.getLifetime());
} out.println(getAuthTokRespMsg.toString());
} }
catch (Exception e) catch (Exception e)
{ {
// tbd // tbd, use a custom exception and then set the status based
System.err.println("GetAuthToken.doPost()- Exception caught: " + e.toString()); // on the type of exeption cached.
// Write out the response // Write out the response
try try
{ {
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpServerErrorStatusMsg, GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpServerErrorStatusMsg,
ProtoDefs.httpServerErrorStatusCode); ProtoDefs.httpUnauthorizedStatusCode);
out.println(getAuthTokRespMsg.toString()); out.println(getAuthTokRespMsg.toString());
} }
catch (Exception e2) catch (Exception e2)
{ {
System.err.println("GetAuthToken.doPost()- Exception trying to construct response msg: " + e2.toString()); System.err.println("GetAuthToken.doPost()- Exception trying to construct response msg: " + e2.toString());
} }
} }
}
// Done sending out the reply catch (Exception e)
out.close(); {
} // tbd
System.err.println("GetAuthToken.doPost()- Exception caught: " + e.toString());
// Write out the response
try
{
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpServerErrorStatusMsg,
ProtoDefs.httpServerErrorStatusCode);
out.println(getAuthTokRespMsg.toString());
}
catch (Exception e2)
{
System.err.println("GetAuthToken.doPost()- Exception trying to construct response msg: " + e2.toString());
}
}
// Done sending out the reply
out.close();
}
} }

View File

@ -29,65 +29,66 @@ package com.novell.casa.authtoksvc;
* *
* This is the interface to Identity Token Providers. * This is the interface to Identity Token Providers.
*/ */
public interface IdentityToken { public interface IdentityToken
{
/*
* Initialize the token with parameters.
*/
void initialize (
String identityId,
String sourceName,
String targetService,
String targetHost) throws Exception;
/* /*
* Initialize the token object with encoded token string. * Initialize the token with parameters.
*/ */
void initialize (String encodedToken) throws Exception; void initialize (
String identityId,
String sourceName,
String targetService,
String targetHost) throws Exception;
/* /*
* Returns encoded token string. * Initialize the token object with encoded token string.
* */
* IMPORTANT: The token string can not contain the substring "]]>" void initialize (String encodedToken) throws Exception;
* within it.
*/
String getEncodedToken() throws Exception;
/*
* Returns a string containing the identity token provider type.
*/
String getProviderType() throws Exception;
/* /*
* Returns a string containing the identity id. * Returns encoded token string.
*/ *
String getIdentityId() throws Exception; * IMPORTANT: The token string can not contain the substring "]]>"
* within it.
/* */
* Returns a string containing the name associated with the String getEncodedToken() throws Exception;
* identity source.
*/ /*
String getSourceName() throws Exception; * Returns a string containing the identity token provider type.
*/
/* String getProviderType() throws Exception;
* Returns a string containing the url associated with the
* identity source. /*
*/ * Returns a string containing the identity id.
String getSourceUrl() throws Exception; */
String getIdentityId() throws Exception;
/*
* Returns a string containing the name of the targeted service. /*
*/ * Returns a string containing the name associated with the
String getTargetService() throws Exception; * identity source.
*/
/* String getSourceName() throws Exception;
* Returns a string containig the name of the host where the
* targeted service resides. /*
*/ * Returns a string containing the url associated with the
String getTargetHost() throws Exception; * identity source.
*/
/* String getSourceUrl() throws Exception;
* Returns the attributes of the identity.
*/ /*
javax.naming.directory.Attributes getAttributes() throws Exception; * Returns a string containing the name of the targeted service.
*/
String getTargetService() throws Exception;
/*
* Returns a string containig the name of the host where the
* targeted service resides.
*/
String getTargetHost() throws Exception;
/*
* Returns the attributes of the identity.
*/
javax.naming.directory.Attributes getAttributes() throws Exception;
} }

View File

@ -57,222 +57,222 @@ import org.bandit.ia.IAContext;
* This class processes authentication requests utilizing a kerberos-V token. * This class processes authentication requests utilizing a kerberos-V token.
* *
*/ */
public class Krb5Authenticate extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet public class Krb5Authenticate extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
{ {
private static final long serialVersionUID = 7247746330553668339L; private static final long serialVersionUID = 7247746330553668339L;
/* /*
* tbd - This needs to be somewhere else so that the same parameter * tbd - This needs to be somewhere else so that the same parameter
* can be accessed by other authentication mechanisms. * can be accessed by other authentication mechanisms.
* *
* Configurable operating parameters * Configurable operating parameters
* *
*/ */
public String sessionTokenLifetime = "360"; public String sessionTokenLifetime = "360";
/*
* GSS Long Lived variables
*/
protected GSSManager m_manager;
protected Oid m_krb5;
protected GSSName m_svcName;
protected GSSCredential m_credential;
/* /*
* Krb5 Token Class. * GSS Long Lived variables
*/ */
private class Krb5Token protected GSSManager m_manager;
{ protected Oid m_krb5;
private String m_principalName = ""; protected GSSName m_svcName;
protected GSSCredential m_credential;
/* /*
* The format of the Krb5 token is as follows: * Krb5 Token Class.
* */
* Base64.encode(GSS-API Token data)); private class Krb5Token
*/ {
public Krb5Token(String encodedToken, Krb5Authenticate parent) throws Exception private String m_principalName = "";
{
// Decode the token
char[] tokenChars = new char[encodedToken.length()];
encodedToken.getChars(0, tokenChars.length, tokenChars, 0);
byte[] tokenBytes = Base64Coder.decode(tokenChars);
try
{
// Create a context and validate the token
GSSContext context = parent.m_manager.createContext(parent.m_credential);
System.err.println("tokenLength = " + tokenBytes.length);
context.acceptSecContext(tokenBytes, 0, tokenBytes.length);
// Save the principal name of the authenticated entity
GSSName principalName = context.getSrcName();
m_principalName = principalName.toString();
// Clean up
context.dispose();
}
catch(GSSException e)
{
System.err.println("Krb5Authenticate Krb5Token()- GSS Exception caught: " + e.getLocalizedMessage());
throw new Exception("Authentication Failure");
}
}
/*
* Returns the name of the authenticated principal
*/
public String getPrincipalName()
{
return m_principalName;
}
}
/*
* Constructor
*/
public Krb5Authenticate() throws Exception
{
super();
try
{
// Initalize our GSS variables
//
// Get an instance of the default GSSManager
m_manager = GSSManager.getInstance();
// Create an OID specifying the Krb5 mechanism
m_krb5 = new Oid("1.2.840.113554.1.2.2");
// Create our host based service name
// tbd - obtain the service name from configuration
//GSSName svcName = manager.createName(ourServiceName, GSSName.NT_HOSTBASED_SERVICE, krb5);
m_svcName = m_manager.createName("host@jcstation.dnsdhcp.provo.novell.com",
GSSName.NT_HOSTBASED_SERVICE,
m_krb5);
// Now acquire our credentials
m_credential = m_manager.createCredential(m_svcName,
GSSCredential.INDEFINITE_LIFETIME,
m_krb5,
GSSCredential.ACCEPT_ONLY);
}
catch(GSSException e)
{
System.err.println("Krb5Authenticate()- GSS Exception caught: " + e.getLocalizedMessage());
throw new Exception("Failed to instantiate needed GSS objects");
}
}
/*
* doGet() implementation.
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost(request, response);
}
/*
* doPost() implementation.
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// Get ready to send back a reply
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try /*
{ * The format of the Krb5 token is as follows:
// Read and parse the AuthReqMsg sent from the client *
InputStream inStream = request.getInputStream(); * Base64.encode(GSS-API Token data));
AuthReqMsg authReqMsg = new AuthReqMsg(inStream); */
public Krb5Token(String encodedToken, Krb5Authenticate parent) throws Exception
// Now parse the PW Token {
Krb5Token krb5Token = new Krb5Token(authReqMsg.getAuthMechToken(), this); // Decode the token
char[] tokenChars = new char[encodedToken.length()];
encodedToken.getChars(0, tokenChars.length, tokenChars, 0);
byte[] tokenBytes = Base64Coder.decode(tokenChars);
// Open a directory context and use it to identify the users try
// associated with the specified surname. {
Hashtable env = new Hashtable(); // Create a context and validate the token
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.bandit.ia.IAInitialCtxFactory"); GSSContext context = parent.m_manager.createContext(parent.m_credential);
env.put(IAContext.IA_REALM_CONFIG_LOCATION, "/home/jluciani/workspace/IdentityAbstraction/realms.xml"); System.err.println("tokenLength = " + tokenBytes.length);
context.acceptSecContext(tokenBytes, 0, tokenBytes.length);
// Save the principal name of the authenticated entity
GSSName principalName = context.getSrcName();
m_principalName = principalName.toString();
// Clean up
context.dispose();
}
catch (GSSException e)
{
System.err.println("Krb5Authenticate Krb5Token()- GSS Exception caught: " + e.getLocalizedMessage());
throw new Exception("Authentication Failure");
}
}
/*
* Returns the name of the authenticated principal
*/
public String getPrincipalName()
{
return m_principalName;
}
}
/*
* Constructor
*/
public Krb5Authenticate() throws Exception
{
super();
try
{
// Initalize our GSS variables
//
// Get an instance of the default GSSManager
m_manager = GSSManager.getInstance();
// Create an OID specifying the Krb5 mechanism
m_krb5 = new Oid("1.2.840.113554.1.2.2");
// Create our host based service name
// tbd - obtain the service name from configuration
//GSSName svcName = manager.createName(ourServiceName, GSSName.NT_HOSTBASED_SERVICE, krb5);
m_svcName = m_manager.createName("host@jcstation.dnsdhcp.provo.novell.com",
GSSName.NT_HOSTBASED_SERVICE,
m_krb5);
// Now acquire our credentials
m_credential = m_manager.createCredential(m_svcName,
GSSCredential.INDEFINITE_LIFETIME,
m_krb5,
GSSCredential.ACCEPT_ONLY);
}
catch (GSSException e)
{
System.err.println("Krb5Authenticate()- GSS Exception caught: " + e.getLocalizedMessage());
throw new Exception("Failed to instantiate needed GSS objects");
}
}
/*
* doGet() implementation.
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost(request, response);
}
/*
* doPost() implementation.
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// Get ready to send back a reply
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try
{
// Read and parse the AuthReqMsg sent from the client
InputStream inStream = request.getInputStream();
AuthReqMsg authReqMsg = new AuthReqMsg(inStream);
// Now parse the PW Token
Krb5Token krb5Token = new Krb5Token(authReqMsg.getAuthMechToken(), this);
// Open a directory context and use it to identify the users
// associated with the specified surname.
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.bandit.ia.IAInitialCtxFactory");
env.put(IAContext.IA_REALM_CONFIG_LOCATION, "/home/jluciani/workspace/IdentityAbstraction/realms.xml");
// env.put(IAContext.IA_REALM_SELECTOR, ""); // env.put(IAContext.IA_REALM_SELECTOR, "");
DirContext ctx = new InitialDirContext(env); DirContext ctx = new InitialDirContext(env);
// Now search for a user with a matching kerberos principal name // Now search for a user with a matching kerberos principal name
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
matchAttrs.put(new BasicAttribute("krbPrincipalName", krb5Token.getPrincipalName())); matchAttrs.put(new BasicAttribute("krbPrincipalName", krb5Token.getPrincipalName()));
NamingEnumeration answer = ctx.search("o=novell", matchAttrs); NamingEnumeration answer = ctx.search("o=novell", matchAttrs);
// Proceed based on the result of the search // Proceed based on the result of the search
String identId = null; String identId = null;
if (answer.hasMore()) if (answer.hasMore())
{ {
// The search succeeded, set the identity id. // The search succeeded, set the identity id.
SearchResult sr = (SearchResult)answer.next(); SearchResult sr = (SearchResult)answer.next();
identId = sr.getName() + ",o=novell"; identId = sr.getName() + ",o=novell";
} }
// Create response based on the identity resolution results // Create response based on the identity resolution results
if (identId != null) if (identId != null)
{ {
// An identity was resolved, get a SessionToken for it. // An identity was resolved, get a SessionToken for it.
SessionToken sessionToken = new SessionToken(identId, authReqMsg.getRealm(), sessionTokenLifetime); SessionToken sessionToken = new SessionToken(identId, authReqMsg.getRealm(), sessionTokenLifetime);
// Write out the response // Write out the response
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpOkStatusMsg, AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpOkStatusMsg,
ProtoDefs.httpOkStatusCode, ProtoDefs.httpOkStatusCode,
sessionToken.toString(), sessionToken.toString(),
sessionTokenLifetime); sessionTokenLifetime);
out.println(authRespMsg.toString()); out.println(authRespMsg.toString());
} }
else else
{ {
// Write out the response // Write out the response
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpUnauthorizedStatusMsg, AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpUnauthorizedStatusMsg,
ProtoDefs.httpUnauthorizedStatusCode); ProtoDefs.httpUnauthorizedStatusCode);
out.println(authRespMsg.toString()); out.println(authRespMsg.toString());
} }
} }
catch (NamingException e) catch (NamingException e)
{ {
// tbd // tbd
// Log the error // Log the error
System.err.println("Krb5Authenticate.doPost()- Exception caught: " + e.getExplanation()); System.err.println("Krb5Authenticate.doPost()- Exception caught: " + e.getExplanation());
// Write out the response // Write out the response
try try
{ {
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg, AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
ProtoDefs.httpServerErrorStatusCode); ProtoDefs.httpServerErrorStatusCode);
out.println(authRespMsg.toString()); out.println(authRespMsg.toString());
} }
catch (Exception e2) catch (Exception e2)
{ {
System.err.println("Krb5Authenticate.doPost()- Exception trying to construct response msg: " + e2.toString()); System.err.println("Krb5Authenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
} }
} }
catch (Exception e) catch (Exception e)
{ {
// tbd // tbd
System.err.println("Krb5Authenticate.doPost()- Exception: " + e.toString()); System.err.println("Krb5Authenticate.doPost()- Exception: " + e.toString());
// Write out the response // Write out the response
try try
{ {
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg, AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
ProtoDefs.httpServerErrorStatusCode); ProtoDefs.httpServerErrorStatusCode);
out.println(authRespMsg.toString()); out.println(authRespMsg.toString());
} }
catch (Exception e2) catch (Exception e2)
{ {
System.err.println("Krb5Authenticate.doPost()- Exception trying to construct response msg: " + e2.toString()); System.err.println("Krb5Authenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
} }
} }
// Done sending out the reply // Done sending out the reply
out.close(); out.close();
} }
} }

View File

@ -31,53 +31,54 @@ package com.novell.casa.authtoksvc;
* protocol. * protocol.
* *
*/ */
public class ProtoDefs { public class ProtoDefs
{
/* /*
* XML Declaration used in the Casa Client/Server protocol * XML Declaration used in the Casa Client/Server protocol
*/ */
public final static String xmlDeclaration = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; public final static String xmlDeclaration = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
/* /*
* XML Element Name Constants for the documents exchanged between the * XML Element Name Constants for the documents exchanged between the
* Casa Client and the Casa Server. * Casa Client and the Casa Server.
*/ */
public final static String authRequestElementName = "auth_req"; public final static String authRequestElementName = "auth_req";
public final static String authResponseElementName = "auth_resp"; public final static String authResponseElementName = "auth_resp";
public final static String getAuthPolicyRequestElementName = "get_auth_policy_req"; public final static String getAuthPolicyRequestElementName = "get_auth_policy_req";
public final static String getAuthPolicyResponseElementName = "get_auth_policy_resp"; public final static String getAuthPolicyResponseElementName = "get_auth_policy_resp";
public final static String getAuthTokRequestElementName = "get_auth_tok_req"; public final static String getAuthTokRequestElementName = "get_auth_tok_req";
public final static String getAuthTokResponseElementName = "get_auth_tok_resp"; public final static String getAuthTokResponseElementName = "get_auth_tok_resp";
public final static String authMechTokenElementName = "auth_mech_token"; public final static String authMechTokenElementName = "auth_mech_token";
public final static String statusElementName = "status"; public final static String statusElementName = "status";
public final static String sessionTokenElementName = "session_token"; public final static String sessionTokenElementName = "session_token";
public final static String authTokenElementName = "auth_token"; public final static String authTokenElementName = "auth_token";
public final static String authPolicyElementName = "auth_policy"; public final static String authPolicyElementName = "auth_policy";
public final static String identTokenElementName = "ident_token"; public final static String identTokenElementName = "ident_token";
public final static String lifetimeElementName = "lifetime"; public final static String lifetimeElementName = "lifetime";
public final static String signatureElementName = "signature"; public final static String signatureElementName = "signature";
public final static String typeElementName = "type"; public final static String typeElementName = "type";
public final static String descriptionElementName = "description"; public final static String descriptionElementName = "description";
public final static String serviceElementName = "service"; public final static String serviceElementName = "service";
public final static String hostElementName = "host"; public final static String hostElementName = "host";
public final static String identIdElementName = "ident_id"; public final static String identIdElementName = "ident_id";
public final static String realmElementName = "realm"; public final static String realmElementName = "realm";
public final static String authSourceElementName = "auth_source"; public final static String authSourceElementName = "auth_source";
public final static String mechanismElementName = "mechanism"; public final static String mechanismElementName = "mechanism";
public final static String mechanismInfoElementName = "mechanism_info"; public final static String mechanismInfoElementName = "mechanism_info";
/* /*
* Configurable operating parameters * Configurable operating parameters
*/ */
public String sessionTokenLifetime = "360"; public String sessionTokenLifetime = "360";
/* /*
* HTTP Status Codes and Messages * HTTP Status Codes and Messages
*/ */
public final static String httpOkStatusCode = "200"; public final static String httpOkStatusCode = "200";
public final static String httpOkStatusMsg = "OK"; public final static String httpOkStatusMsg = "OK";
public final static String httpUnauthorizedStatusCode = "401"; public final static String httpUnauthorizedStatusCode = "401";
public final static String httpUnauthorizedStatusMsg = "Unauthorized"; public final static String httpUnauthorizedStatusMsg = "Unauthorized";
public final static String httpServerErrorStatusCode = "500"; public final static String httpServerErrorStatusCode = "500";
public final static String httpServerErrorStatusMsg = "Internal Server Error"; public final static String httpServerErrorStatusMsg = "Internal Server Error";
} }

View File

@ -55,128 +55,128 @@ import org.bandit.ia.IAContext;
* password materials. * password materials.
* *
*/ */
public class PwdAuthenticate extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet public class PwdAuthenticate extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
{ {
private static final long serialVersionUID = 3710685782114934264L; private static final long serialVersionUID = 3710685782114934264L;
/* /*
* tbd - This needs to be somewhere else so that the same parameter * tbd - This needs to be somewhere else so that the same parameter
* can be accessed by other authentication mechanisms. * can be accessed by other authentication mechanisms.
* *
* Configurable operating parameters * Configurable operating parameters
* *
*/ */
public String sessionTokenLifetime = "360"; public String sessionTokenLifetime = "360";
/*
* Password Token Class.
*/
private class PwToken
{
private String m_username = "";
private String m_password = "";
/* /*
* The format of the Pw token is as follows: * Password Token Class.
* */
* Base64.encode(new String("username\r\n" + "password\r\n")); private class PwToken
*/ {
public PwToken(String encodedToken) throws IOException private String m_username = "";
{ private String m_password = "";
// Decode the token
String token = Base64Coder.decode(encodedToken);
BufferedReader tokenReader = new BufferedReader(new StringReader(token));
// The second line contains the "username"
m_username = tokenReader.readLine();
// The third line contains the "password"
m_password = tokenReader.readLine();
}
/*
* Returns the username
*/
public String getUsername()
{
return m_username;
}
/*
* Returns the password
*/
public String getPassword()
{
return m_password;
}
}
/*
* Constructor
*/
public PwdAuthenticate()
{
super();
}
/*
* doGet() implementation.
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// Just let doPost() handle it.
doPost(request, response);
}
/*
* doPost() implementation.
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// Get ready to send back a reply
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try /*
{ * The format of the Pw token is as follows:
// Read and parse the AuthReqMsg sent from the client *
InputStream inStream = request.getInputStream(); * Base64.encode(new String("username\r\n" + "password\r\n"));
AuthReqMsg authReqMsg = new AuthReqMsg(inStream); */
public PwToken(String encodedToken) throws IOException
{
// Decode the token
String token = Base64Coder.decode(encodedToken);
// Now parse the PW Token BufferedReader tokenReader = new BufferedReader(new StringReader(token));
PwToken pwToken = new PwToken(authReqMsg.getAuthMechToken());
// Open a directory context and use it to identify the users // The second line contains the "username"
// associated with the specified surname. m_username = tokenReader.readLine();
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.bandit.ia.IAInitialCtxFactory"); // The third line contains the "password"
env.put(IAContext.IA_REALM_CONFIG_LOCATION, "/home/jluciani/workspace/IdentityAbstraction/realms.xml"); m_password = tokenReader.readLine();
}
/*
* Returns the username
*/
public String getUsername()
{
return m_username;
}
/*
* Returns the password
*/
public String getPassword()
{
return m_password;
}
}
/*
* Constructor
*/
public PwdAuthenticate()
{
super();
}
/*
* doGet() implementation.
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// Just let doPost() handle it.
doPost(request, response);
}
/*
* doPost() implementation.
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// Get ready to send back a reply
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try
{
// Read and parse the AuthReqMsg sent from the client
InputStream inStream = request.getInputStream();
AuthReqMsg authReqMsg = new AuthReqMsg(inStream);
// Now parse the PW Token
PwToken pwToken = new PwToken(authReqMsg.getAuthMechToken());
// Open a directory context and use it to identify the users
// associated with the specified surname.
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.bandit.ia.IAInitialCtxFactory");
env.put(IAContext.IA_REALM_CONFIG_LOCATION, "/home/jluciani/workspace/IdentityAbstraction/realms.xml");
// env.put(IAContext.IA_REALM_SELECTOR, ""); // env.put(IAContext.IA_REALM_SELECTOR, "");
DirContext ctx = new InitialDirContext(env); DirContext ctx = new InitialDirContext(env);
// Now search for a user with a matching surname // Now search for a user with a matching surname
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
matchAttrs.put(new BasicAttribute("cn", pwToken.getUsername())); matchAttrs.put(new BasicAttribute("cn", pwToken.getUsername()));
NamingEnumeration answer = ctx.search("o=novell", matchAttrs); NamingEnumeration answer = ctx.search("o=novell", matchAttrs);
// Enumerate through the users returned checking the password // Enumerate through the users returned checking the password
String identId = null; String identId = null;
while (answer.hasMore()) while (answer.hasMore())
{ {
SearchResult sr = (SearchResult)answer.next(); SearchResult sr = (SearchResult)answer.next();
System.err.println(sr.getName());
// Open a directory context for the user as a way of verifying its password System.err.println(sr.getName());
try
{ // Open a directory context for the user as a way of verifying its password
Hashtable env2 = new Hashtable(); try
env2.put(Context.INITIAL_CONTEXT_FACTORY, "org.bandit.ia.IAInitialCtxFactory"); {
env2.put(IAContext.IA_REALM_CONFIG_LOCATION, "/home/jluciani/workspace/IdentityAbstraction/realms.xml"); Hashtable env2 = new Hashtable();
env2.put(Context.INITIAL_CONTEXT_FACTORY, "org.bandit.ia.IAInitialCtxFactory");
env2.put(IAContext.IA_REALM_CONFIG_LOCATION, "/home/jluciani/workspace/IdentityAbstraction/realms.xml");
// env2.put(IAContext.IA_REALM_SELECTOR, ""); // env2.put(IAContext.IA_REALM_SELECTOR, "");
// env2.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); // env2.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
@ -185,78 +185,78 @@ import org.bandit.ia.IAContext;
// env2.put(Context.SECURITY_PRINCIPAL, sr.getName() + ",o=novell"); // env2.put(Context.SECURITY_PRINCIPAL, sr.getName() + ",o=novell");
// env2.put(Context.SECURITY_CREDENTIALS, pwToken.getPassword()); // env2.put(Context.SECURITY_CREDENTIALS, pwToken.getPassword());
if ((new InitialDirContext(env2)) != null) if ((new InitialDirContext(env2)) != null)
{ {
// The password must be valid, set the identity Id. // The password must be valid, set the identity Id.
identId = sr.getName() + ",o=novell"; identId = sr.getName() + ",o=novell";
break; break;
} }
} }
catch (NamingException e) catch (NamingException e)
{ {
System.err.println("PwdAuthenticate.doPost()- Naming Exception: " + e.getExplanation()); System.err.println("PwdAuthenticate.doPost()- Naming Exception: " + e.getExplanation());
} }
} }
// Create response based on the identity resolution results // Create response based on the identity resolution results
if (identId != null) if (identId != null)
{ {
// An identity was resolved, get a SessionToken for it. // An identity was resolved, get a SessionToken for it.
SessionToken sessionToken = new SessionToken(identId, authReqMsg.getRealm(), sessionTokenLifetime); SessionToken sessionToken = new SessionToken(identId, authReqMsg.getRealm(), sessionTokenLifetime);
// Write out the response // Write out the response
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpOkStatusMsg, AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpOkStatusMsg,
ProtoDefs.httpOkStatusCode, ProtoDefs.httpOkStatusCode,
sessionToken.toString(), sessionToken.toString(),
sessionTokenLifetime); sessionTokenLifetime);
out.println(authRespMsg.toString()); out.println(authRespMsg.toString());
} }
else else
{ {
// Write out the response // Write out the response
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpUnauthorizedStatusMsg, AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpUnauthorizedStatusMsg,
ProtoDefs.httpUnauthorizedStatusCode); ProtoDefs.httpUnauthorizedStatusCode);
out.println(authRespMsg.toString()); out.println(authRespMsg.toString());
} }
} }
catch (NamingException e) catch (NamingException e)
{ {
// tbd // tbd
// Log the error // Log the error
System.err.println("PwdAuthenticate.doPost()- Naming Exception on Proxy User: " + e.getExplanation()); System.err.println("PwdAuthenticate.doPost()- Naming Exception on Proxy User: " + e.getExplanation());
// Write out the response // Write out the response
try try
{ {
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg, AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
ProtoDefs.httpServerErrorStatusCode); ProtoDefs.httpServerErrorStatusCode);
out.println(authRespMsg.toString()); out.println(authRespMsg.toString());
} }
catch (Exception e2) catch (Exception e2)
{ {
System.err.println("PwdAuthenticate.doPost()- Exception trying to construct response msg: " + e2.toString()); System.err.println("PwdAuthenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
} }
} }
catch (Exception e) catch (Exception e)
{ {
// tbd // tbd
System.err.println("PwdAuthenticate.doPost()- Naming Exception on Proxy User: " + e.toString()); System.err.println("PwdAuthenticate.doPost()- Naming Exception on Proxy User: " + e.toString());
// Write out the response // Write out the response
try try
{ {
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg, AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
ProtoDefs.httpServerErrorStatusCode); ProtoDefs.httpServerErrorStatusCode);
out.println(authRespMsg.toString()); out.println(authRespMsg.toString());
} }
catch (Exception e2) catch (Exception e2)
{ {
System.err.println("PwdAuthenticate.doPost()- Exception trying to construct response msg: " + e2.toString()); System.err.println("PwdAuthenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
} }
} }
// Done sending out the reply // Done sending out the reply
out.close(); out.close();
} }
} }

View File

@ -48,365 +48,369 @@ import org.xml.sax.helpers.XMLReaderFactory;
* </session_token> * </session_token>
* *
*/ */
public class SessionToken { public class SessionToken
{
private String m_id;
private String m_realm;
private String m_lifetime;
private String m_signature;
private String m_token;
/* private String m_id;
* Class for handling parsing events. private String m_realm;
*/ private String m_lifetime;
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler private String m_signature;
{ private String m_token;
private final static int AWAITING_ROOT_ELEMENT_START = 0;
private final static int AWAITING_ROOT_ELEMENT_END = 1;
private final static int AWAITING_SIGNATURE_ELEMENT_START = 2;
private final static int AWAITING_SIGNATURE_ELEMENT_END = 3;
private final static int AWAITING_SIGNATURE_DATA = 4;
private final static int AWAITING_LIFETIME_ELEMENT_START = 5;
private final static int AWAITING_LIFETIME_ELEMENT_END = 6;
private final static int AWAITING_LIFETIME_DATA = 7;
private final static int AWAITING_REALM_ELEMENT_START = 8;
private final static int AWAITING_REALM_ELEMENT_END = 9;
private final static int AWAITING_REALM_DATA = 10;
private final static int AWAITING_IDENT_ID_ELEMENT_START = 11;
private final static int AWAITING_IDENT_ID_ELEMENT_END = 12;
private final static int AWAITING_IDENT_ID_DATA = 13;
private final static int DONE_PARSING = 14;
private SessionToken m_SessionToken;
private int m_state;
/* /*
* Constructor * Class for handling parsing events.
*/ */
public SAXHandler (SessionToken SessionToken) private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
{ {
super(); private final static int AWAITING_ROOT_ELEMENT_START = 0;
private final static int AWAITING_ROOT_ELEMENT_END = 1;
// Initialize our members private final static int AWAITING_SIGNATURE_ELEMENT_START = 2;
m_SessionToken = SessionToken; private final static int AWAITING_SIGNATURE_ELEMENT_END = 3;
m_state = AWAITING_ROOT_ELEMENT_START; private final static int AWAITING_SIGNATURE_DATA = 4;
} private final static int AWAITING_LIFETIME_ELEMENT_START = 5;
private final static int AWAITING_LIFETIME_ELEMENT_END = 6;
private final static int AWAITING_LIFETIME_DATA = 7;
private final static int AWAITING_REALM_ELEMENT_START = 8;
private final static int AWAITING_REALM_ELEMENT_END = 9;
private final static int AWAITING_REALM_DATA = 10;
private final static int AWAITING_IDENT_ID_ELEMENT_START = 11;
private final static int AWAITING_IDENT_ID_ELEMENT_END = 12;
private final static int AWAITING_IDENT_ID_DATA = 13;
private final static int DONE_PARSING = 14;
/* private SessionToken m_SessionToken;
* endDocument() implementation. private int m_state;
*/
public void endDocument () throws SAXException
{
// Verify that we obtained all of the required elements
if (m_state != DONE_PARSING)
{
System.err.println("SessionToken SAXHandler.endDocument()- Missing element");
throw new SAXException("Missing element");
}
}
/*
* startElement() implementation.
*/
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
{
// Proceed based on our state
switch (m_state) {
case AWAITING_ROOT_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.sessionTokenElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SIGNATURE_ELEMENT_START;
}
else
{
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SIGNATURE_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.signatureElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_SIGNATURE_DATA;
}
else
{
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_LIFETIME_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.lifetimeElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_LIFETIME_DATA;
}
else
{
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break; /*
* Constructor
case AWAITING_REALM_ELEMENT_START: */
// Verify that we are processing the expected tag public SAXHandler (SessionToken SessionToken)
if (ProtoDefs.realmElementName.equals(qName)) {
{ super();
// Advance to the next state
m_state = AWAITING_REALM_DATA;
}
else
{
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_IDENT_ID_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.identIdElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_IDENT_ID_DATA;
}
else
{
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("SessionToken SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/* // Initialize our members
* endElement() immplementation. m_SessionToken = SessionToken;
*/ m_state = AWAITING_ROOT_ELEMENT_START;
public void endElement (String uri, String name, String qName) throws SAXException }
{
// Proceed based on our state
switch (m_state) {
case AWAITING_ROOT_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.sessionTokenElementName.equals(qName))
{
// Advance to the next state
m_state = DONE_PARSING;
}
else
{
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SIGNATURE_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.signatureElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_LIFETIME_ELEMENT_START;
}
else
{
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_LIFETIME_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.lifetimeElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_REALM_ELEMENT_START;
}
else
{
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_REALM_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.realmElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_IDENT_ID_ELEMENT_START;
}
else
{
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_IDENT_ID_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.identIdElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_ROOT_ELEMENT_END;
}
else
{
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("SessionToken SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* character() implementation.
*/
public void characters (char ch[], int start, int length) throws SAXException
{
// Proceed based on our state
switch (m_state) {
case AWAITING_SIGNATURE_DATA:
// Consume the data
m_SessionToken.m_signature = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_SIGNATURE_ELEMENT_END;
break;
case AWAITING_LIFETIME_DATA:
// Consume the data
m_SessionToken.m_lifetime = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_LIFETIME_ELEMENT_END;
break;
case AWAITING_REALM_DATA:
// Consume the data
m_SessionToken.m_realm = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_REALM_ELEMENT_END;
break;
case AWAITING_IDENT_ID_DATA:
// Consume the data
m_SessionToken.m_id = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_IDENT_ID_ELEMENT_END;
break;
default:
// Do nothing
break;
}
}
}
/*
* Constructor
*/
public SessionToken(String id, String realm, String lifetime) throws Exception
{
// Save copies of the input parameters
m_id = id;
m_realm = realm;
m_lifetime = lifetime;
// Generate a signature
// tbd - Over id, realm, and lifetime data.
m_signature = "tbd";
// Get a StringBuffer to help us with the construction of the token /*
StringBuffer sb = new StringBuffer(); * endDocument() implementation.
*/
// Start building the message public void endDocument () throws SAXException
sb.append(ProtoDefs.xmlDeclaration + "\r\n"); {
sb.append("<" + ProtoDefs.sessionTokenElementName + ">" + "\r\n"); // Verify that we obtained all of the required elements
sb.append("<" + ProtoDefs.signatureElementName + ">" + m_signature + "</" + ProtoDefs.signatureElementName + ">" + "\r\n"); if (m_state != DONE_PARSING)
sb.append("<" + ProtoDefs.lifetimeElementName + ">" + m_lifetime + "</" + ProtoDefs.lifetimeElementName + ">" + "\r\n"); {
sb.append("<" + ProtoDefs.realmElementName + ">" + m_realm + "</" + ProtoDefs.realmElementName + ">" + "\r\n"); System.err.println("SessionToken SAXHandler.endDocument()- Missing element");
sb.append("<" + ProtoDefs.identIdElementName + ">" + m_id + "</" + ProtoDefs.identIdElementName + ">" + "\r\n"); throw new SAXException("Missing element");
sb.append("</" + ProtoDefs.sessionTokenElementName + ">" + "\r\n"); }
}
// Save the token
m_token = sb.toString();
}
/* /*
* Constructor given a session token string. The constructor * startElement() implementation.
* validates the token as part of its processing. */
*/ public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
public SessionToken(String token) throws Exception {
{ // Proceed based on our state
// Decode the token string switch (m_state)
m_token = Base64Coder.decode(token); {
// Now parse the token into its elements case AWAITING_ROOT_ELEMENT_START:
try // Verify that we are processing the expected tag
{ if (ProtoDefs.sessionTokenElementName.equals(qName))
// Parse the SessionToken {
XMLReader xr = XMLReaderFactory.createXMLReader(); // Advance to the next state
SAXHandler handler = new SAXHandler(this); m_state = AWAITING_SIGNATURE_ELEMENT_START;
xr.setContentHandler(handler); }
xr.setErrorHandler(handler); else
{
ByteArrayInputStream inStream = new ByteArrayInputStream(m_token.getBytes()); System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
InputSource source = new InputSource(inStream); throw new SAXException("Un-expected element");
xr.parse(source); }
break;
// Verify the signature
// tbd
// Verify that the token has not expired
// tbd
}
catch (SAXException e)
{
System.err.println("SessionToken()- Parse exception: " + e.toString());
throw new Exception("Protocol error");
}
}
/* case AWAITING_SIGNATURE_ELEMENT_START:
* Returns a string containing the session token. // Verify that we are processing the expected tag
*/ if (ProtoDefs.signatureElementName.equals(qName))
public String toString() {
{ // Advance to the next state
return Base64Coder.encode(m_token); m_state = AWAITING_SIGNATURE_DATA;
} }
else
/* {
* Method to get the Identity Id System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
*/ throw new SAXException("Un-expected element");
public String getIdentId() throws Exception }
{ break;
return m_id;
} case AWAITING_LIFETIME_ELEMENT_START:
// Verify that we are processing the expected tag
/* if (ProtoDefs.lifetimeElementName.equals(qName))
* Method to get the Identity Repository Reference (Realm). {
*/ // Advance to the next state
public String getRealm() throws Exception m_state = AWAITING_LIFETIME_DATA;
{ }
return m_realm; else
} {
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_REALM_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.realmElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_REALM_DATA;
}
else
{
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_IDENT_ID_ELEMENT_START:
// Verify that we are processing the expected tag
if (ProtoDefs.identIdElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_IDENT_ID_DATA;
}
else
{
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("SessionToken SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* endElement() immplementation.
*/
public void endElement (String uri, String name, String qName) throws SAXException
{
// Proceed based on our state
switch (m_state)
{
case AWAITING_ROOT_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.sessionTokenElementName.equals(qName))
{
// Advance to the next state
m_state = DONE_PARSING;
}
else
{
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_SIGNATURE_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.signatureElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_LIFETIME_ELEMENT_START;
}
else
{
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_LIFETIME_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.lifetimeElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_REALM_ELEMENT_START;
}
else
{
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_REALM_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.realmElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_IDENT_ID_ELEMENT_START;
}
else
{
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
case AWAITING_IDENT_ID_ELEMENT_END:
// Verify that we are processing the expected tag
if (ProtoDefs.identIdElementName.equals(qName))
{
// Advance to the next state
m_state = AWAITING_ROOT_ELEMENT_END;
}
else
{
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
throw new SAXException("Un-expected element");
}
break;
default:
System.err.println("SessionToken SAXHandler.startElement()- State error");
throw new SAXException("State error");
}
}
/*
* character() implementation.
*/
public void characters (char ch[], int start, int length) throws SAXException
{
// Proceed based on our state
switch (m_state)
{
case AWAITING_SIGNATURE_DATA:
// Consume the data
m_SessionToken.m_signature = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_SIGNATURE_ELEMENT_END;
break;
case AWAITING_LIFETIME_DATA:
// Consume the data
m_SessionToken.m_lifetime = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_LIFETIME_ELEMENT_END;
break;
case AWAITING_REALM_DATA:
// Consume the data
m_SessionToken.m_realm = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_REALM_ELEMENT_END;
break;
case AWAITING_IDENT_ID_DATA:
// Consume the data
m_SessionToken.m_id = new String(ch, start, length);
// Advance to the next state
m_state = AWAITING_IDENT_ID_ELEMENT_END;
break;
default:
// Do nothing
break;
}
}
}
/*
* Constructor
*/
public SessionToken(String id, String realm, String lifetime) throws Exception
{
// Save copies of the input parameters
m_id = id;
m_realm = realm;
m_lifetime = lifetime;
// Generate a signature
// tbd - Over id, realm, and lifetime data.
m_signature = "tbd";
// Get a StringBuffer to help us with the construction of the token
StringBuffer sb = new StringBuffer();
// Start building the message
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
sb.append("<" + ProtoDefs.sessionTokenElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.signatureElementName + ">" + m_signature + "</" + ProtoDefs.signatureElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.lifetimeElementName + ">" + m_lifetime + "</" + ProtoDefs.lifetimeElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.realmElementName + ">" + m_realm + "</" + ProtoDefs.realmElementName + ">" + "\r\n");
sb.append("<" + ProtoDefs.identIdElementName + ">" + m_id + "</" + ProtoDefs.identIdElementName + ">" + "\r\n");
sb.append("</" + ProtoDefs.sessionTokenElementName + ">" + "\r\n");
// Save the token
m_token = sb.toString();
}
/*
* Constructor given a session token string. The constructor
* validates the token as part of its processing.
*/
public SessionToken(String token) throws Exception
{
// Decode the token string
m_token = Base64Coder.decode(token);
// Now parse the token into its elements
try
{
// Parse the SessionToken
XMLReader xr = XMLReaderFactory.createXMLReader();
SAXHandler handler = new SAXHandler(this);
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
ByteArrayInputStream inStream = new ByteArrayInputStream(m_token.getBytes());
InputSource source = new InputSource(inStream);
xr.parse(source);
// Verify the signature
// tbd
// Verify that the token has not expired
// tbd
}
catch (SAXException e)
{
System.err.println("SessionToken()- Parse exception: " + e.toString());
throw new Exception("Protocol error");
}
}
/*
* Returns a string containing the session token.
*/
public String toString()
{
return Base64Coder.encode(m_token);
}
/*
* Method to get the Identity Id
*/
public String getIdentId() throws Exception
{
return m_id;
}
/*
* Method to get the Identity Repository Reference (Realm).
*/
public String getRealm() throws Exception
{
return m_realm;
}
} }