Mostly formatting changes.
This commit is contained in:
parent
79e2f829f4
commit
0983950115
@ -46,233 +46,237 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
* </auth_req>
|
||||
*
|
||||
*/
|
||||
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;
|
||||
public class AuthReqMsg
|
||||
{
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
public SAXHandler (AuthReqMsg authReqMsg)
|
||||
{
|
||||
super();
|
||||
|
||||
// Initialize our members
|
||||
m_authReqMsg = authReqMsg;
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
protected String m_realm = null;
|
||||
protected String m_authMechToken = null;
|
||||
|
||||
/*
|
||||
* 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");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
private AuthReqMsg m_authReqMsg;
|
||||
private int m_state;
|
||||
|
||||
/*
|
||||
* Method to get the authentication mechanism token.
|
||||
*/
|
||||
public String getAuthMechToken() throws Exception
|
||||
{
|
||||
return m_authMechToken;
|
||||
}
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
public SAXHandler (AuthReqMsg authReqMsg)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -49,64 +49,65 @@ package com.novell.casa.authtoksvc;
|
||||
* in the HTTP 1.1 Specification.
|
||||
*
|
||||
*/
|
||||
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();
|
||||
}
|
||||
public class AuthRespMsg
|
||||
{
|
||||
|
||||
/*
|
||||
* Constructor for a msg that includes the session token.
|
||||
*/
|
||||
public AuthRespMsg (
|
||||
String statusDescription,
|
||||
String statusCode,
|
||||
String sessionToken,
|
||||
String sessionTokenLifetime) 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 + ">" + 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;
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor for a msg that includes the session token.
|
||||
*/
|
||||
public AuthRespMsg (
|
||||
String statusDescription,
|
||||
String statusCode,
|
||||
String sessionToken,
|
||||
String sessionTokenLifetime) 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 + ">" + 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;
|
||||
}
|
||||
}
|
||||
|
@ -47,406 +47,410 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
* </auth_token>
|
||||
*
|
||||
*/
|
||||
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;
|
||||
public class AuthToken
|
||||
{
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
public SAXHandler (AuthToken AuthToken)
|
||||
{
|
||||
super();
|
||||
|
||||
// Initialize our members
|
||||
m_AuthToken = AuthToken;
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
private String m_token;
|
||||
private String m_lifetime;
|
||||
private String m_identityTokenType;
|
||||
private StringBuffer m_identityToken;
|
||||
private String m_signature;
|
||||
|
||||
/*
|
||||
* endDocument() implementation.
|
||||
*/
|
||||
public void endDocument () throws SAXException
|
||||
{
|
||||
// Verify that we obtained all of the required elements
|
||||
if (m_state != DONE_PARSING)
|
||||
{
|
||||
System.err.println("AuthToken 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.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");
|
||||
}
|
||||
/*
|
||||
* 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;
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
private AuthToken m_AuthToken;
|
||||
private int m_state;
|
||||
|
||||
/*
|
||||
* 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";
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
public SAXHandler (AuthToken AuthToken)
|
||||
{
|
||||
super();
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
// Initialize our members
|
||||
m_AuthToken = AuthToken;
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* endDocument() implementation.
|
||||
*/
|
||||
public void endDocument () throws SAXException
|
||||
{
|
||||
// Verify that we obtained all of the required elements
|
||||
if (m_state != DONE_PARSING)
|
||||
{
|
||||
System.err.println("AuthToken SAXHandler.endDocument()- Missing element");
|
||||
throw new SAXException("Missing element");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
/*
|
||||
* 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.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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -39,99 +39,98 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* service.
|
||||
*
|
||||
*/
|
||||
public class GetAuthPolicy extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
||||
{
|
||||
private static final long serialVersionUID = -8264027868130334613L;
|
||||
public class GetAuthPolicy extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
||||
{
|
||||
private static final long serialVersionUID = -8264027868130334613L;
|
||||
|
||||
/*
|
||||
* Constructor.
|
||||
*/
|
||||
public GetAuthPolicy()
|
||||
{
|
||||
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();
|
||||
/*
|
||||
* Constructor.
|
||||
*/
|
||||
public GetAuthPolicy()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Read and parse the GetAuthPolicyReqMsg sent from the client
|
||||
InputStream inStream = request.getInputStream();
|
||||
GetAuthPolicyReqMsg getAuthPolicyReqMsg = new GetAuthPolicyReqMsg(inStream);
|
||||
|
||||
// Get the auth policy for the service
|
||||
byte[] authPolicy = getAuthPolicyFileData(getAuthPolicyReqMsg.getServiceName(),
|
||||
getAuthPolicyReqMsg.getHostName());
|
||||
/*
|
||||
* doGet() implementation.
|
||||
*/
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
|
||||
// Write out the response
|
||||
GetAuthPolicyRespMsg getAuthPolicyRespMsg = new GetAuthPolicyRespMsg(ProtoDefs.httpOkStatusMsg,
|
||||
ProtoDefs.httpOkStatusCode,
|
||||
new String(Base64Coder.encode(authPolicy)));
|
||||
out.println(getAuthPolicyRespMsg.toString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// tbd
|
||||
System.err.println("GetAuthPolicy.doPost()- Exception caught: " + e.toString());
|
||||
|
||||
// Write out the response
|
||||
try
|
||||
{
|
||||
GetAuthPolicyRespMsg getAuthPolicyRespMsg = new GetAuthPolicyRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||
ProtoDefs.httpServerErrorStatusCode);
|
||||
out.println(getAuthPolicyRespMsg.toString());
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
System.err.println("GetAuthPolicy.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Done sending out the reply
|
||||
out.close();
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the data associated with the authentication policy file
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
|
||||
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 GetAuthPolicyReqMsg sent from the client
|
||||
InputStream inStream = request.getInputStream();
|
||||
GetAuthPolicyReqMsg getAuthPolicyReqMsg = new GetAuthPolicyReqMsg(inStream);
|
||||
|
||||
// Get the auth policy for the service
|
||||
byte[] authPolicy = getAuthPolicyFileData(getAuthPolicyReqMsg.getServiceName(),
|
||||
getAuthPolicyReqMsg.getHostName());
|
||||
|
||||
// Write out the response
|
||||
GetAuthPolicyRespMsg getAuthPolicyRespMsg = new GetAuthPolicyRespMsg(ProtoDefs.httpOkStatusMsg,
|
||||
ProtoDefs.httpOkStatusCode,
|
||||
new String(Base64Coder.encode(authPolicy)));
|
||||
out.println(getAuthPolicyRespMsg.toString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// tbd
|
||||
System.err.println("GetAuthPolicy.doPost()- Exception caught: " + e.toString());
|
||||
|
||||
// Write out the response
|
||||
try
|
||||
{
|
||||
GetAuthPolicyRespMsg getAuthPolicyRespMsg = new GetAuthPolicyRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||
ProtoDefs.httpServerErrorStatusCode);
|
||||
out.println(getAuthPolicyRespMsg.toString());
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
System.err.println("GetAuthPolicy.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Done sending out the reply
|
||||
out.close();
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the data associated with the authentication policy file
|
||||
* 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();
|
||||
}
|
||||
}
|
@ -45,234 +45,238 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
* </get_auth_policy_req>
|
||||
*
|
||||
*/
|
||||
public class GetAuthPolicyReqMsg {
|
||||
public class GetAuthPolicyReqMsg
|
||||
{
|
||||
|
||||
protected String m_serviceName = 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;
|
||||
protected String m_serviceName = null;
|
||||
protected String m_hostName = null;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
public SAXHandler (GetAuthPolicyReqMsg GetAuthPolicyReqMsg)
|
||||
{
|
||||
super();
|
||||
|
||||
// Initialize our members
|
||||
m_GetAuthPolicyReqMsg = GetAuthPolicyReqMsg;
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/*
|
||||
* endDocument() implementation.
|
||||
*/
|
||||
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");
|
||||
}
|
||||
private GetAuthPolicyReqMsg m_GetAuthPolicyReqMsg;
|
||||
private int m_state;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- State error");
|
||||
throw new SAXException("State error");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
public SAXHandler (GetAuthPolicyReqMsg GetAuthPolicyReqMsg)
|
||||
{
|
||||
super();
|
||||
|
||||
/*
|
||||
* 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");
|
||||
}
|
||||
}
|
||||
// Initialize our members
|
||||
m_GetAuthPolicyReqMsg = GetAuthPolicyReqMsg;
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
/*
|
||||
* endDocument() implementation.
|
||||
*/
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -50,61 +50,62 @@ package com.novell.casa.authtoksvc;
|
||||
* in the HTTP 1.1 Specification.
|
||||
*
|
||||
*/
|
||||
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();
|
||||
}
|
||||
public class GetAuthPolicyRespMsg
|
||||
{
|
||||
|
||||
/*
|
||||
* Constructor for a msg that includes the authentication policy.
|
||||
*/
|
||||
public GetAuthPolicyRespMsg (
|
||||
String statusDescription,
|
||||
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;
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor for a msg that includes the authentication policy.
|
||||
*/
|
||||
public GetAuthPolicyRespMsg (
|
||||
String statusDescription,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -46,282 +46,286 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
* </get_auth_token_req>
|
||||
*
|
||||
*/
|
||||
public class GetAuthTokReqMsg {
|
||||
public class GetAuthTokReqMsg
|
||||
{
|
||||
|
||||
protected String m_serviceName = null;
|
||||
protected String m_hostName = 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;
|
||||
protected String m_serviceName = null;
|
||||
protected String m_hostName = null;
|
||||
protected String m_sessionToken = null;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
public SAXHandler (GetAuthTokReqMsg GetAuthTokReqMsg)
|
||||
{
|
||||
super();
|
||||
|
||||
// Initialize our members
|
||||
m_GetAuthTokReqMsg = GetAuthTokReqMsg;
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/*
|
||||
* endDocument() implementation.
|
||||
*/
|
||||
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");
|
||||
}
|
||||
private GetAuthTokReqMsg m_GetAuthTokReqMsg;
|
||||
private int m_state;
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
public SAXHandler (GetAuthTokReqMsg GetAuthTokReqMsg)
|
||||
{
|
||||
super();
|
||||
|
||||
/*
|
||||
* 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");
|
||||
}
|
||||
}
|
||||
// Initialize our members
|
||||
m_GetAuthTokReqMsg = GetAuthTokReqMsg;
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
/*
|
||||
* endDocument() implementation.
|
||||
*/
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -50,65 +50,66 @@ package com.novell.casa.authtoksvc;
|
||||
* in the HTTP 1.1 Specification.
|
||||
*
|
||||
*/
|
||||
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();
|
||||
}
|
||||
public class GetAuthTokRespMsg
|
||||
{
|
||||
|
||||
/*
|
||||
* Constructor for a msg that includes the authentication token.
|
||||
*/
|
||||
public GetAuthTokRespMsg (
|
||||
String statusDescription,
|
||||
String statusCode,
|
||||
String authToken,
|
||||
String authTokenLifetime) 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 + ">" + 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;
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor for a msg that includes the authentication token.
|
||||
*/
|
||||
public GetAuthTokRespMsg (
|
||||
String statusDescription,
|
||||
String statusCode,
|
||||
String authToken,
|
||||
String authTokenLifetime) 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 + ">" + 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,97 +39,97 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* to a particular service.
|
||||
*
|
||||
*/
|
||||
public class GetAuthToken extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
||||
{
|
||||
private static final long serialVersionUID = -5792862615065914894L;
|
||||
public class GetAuthToken extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
||||
{
|
||||
private static final long serialVersionUID = -5792862615065914894L;
|
||||
|
||||
/*
|
||||
* Constructor.
|
||||
*/
|
||||
public GetAuthToken()
|
||||
{
|
||||
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();
|
||||
/*
|
||||
* Constructor.
|
||||
*/
|
||||
public GetAuthToken()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Read and parse the GetAuthTokReqMsg sent from the client
|
||||
InputStream inStream = request.getInputStream();
|
||||
GetAuthTokReqMsg getAuthTokReqMsg = new GetAuthTokReqMsg(inStream);
|
||||
|
||||
// Now create a session token (This validates the session token provided).
|
||||
SessionToken sessionToken = new SessionToken(getAuthTokReqMsg.getSessionToken());
|
||||
|
||||
try
|
||||
{
|
||||
// Create the Authentication Token
|
||||
AuthToken authToken = new AuthToken(sessionToken.getIdentId(),
|
||||
sessionToken.getRealm(),
|
||||
getAuthTokReqMsg.getServiceName(),
|
||||
getAuthTokReqMsg.getHostName());
|
||||
|
||||
// Write out the response
|
||||
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpOkStatusMsg,
|
||||
ProtoDefs.httpOkStatusCode,
|
||||
authToken.toString(),
|
||||
authToken.getLifetime());
|
||||
out.println(getAuthTokRespMsg.toString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// tbd, use a custom exception and then set the status based
|
||||
// on the type of exeption cached.
|
||||
|
||||
// Write out the response
|
||||
try
|
||||
{
|
||||
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||
ProtoDefs.httpUnauthorizedStatusCode);
|
||||
out.println(getAuthTokRespMsg.toString());
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
System.err.println("GetAuthToken.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
/*
|
||||
* 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 GetAuthTokReqMsg sent from the client
|
||||
InputStream inStream = request.getInputStream();
|
||||
GetAuthTokReqMsg getAuthTokReqMsg = new GetAuthTokReqMsg(inStream);
|
||||
|
||||
// Now create a session token (This validates the session token provided).
|
||||
SessionToken sessionToken = new SessionToken(getAuthTokReqMsg.getSessionToken());
|
||||
|
||||
try
|
||||
{
|
||||
// Create the Authentication Token
|
||||
AuthToken authToken = new AuthToken(sessionToken.getIdentId(),
|
||||
sessionToken.getRealm(),
|
||||
getAuthTokReqMsg.getServiceName(),
|
||||
getAuthTokReqMsg.getHostName());
|
||||
|
||||
// Write out the response
|
||||
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpOkStatusMsg,
|
||||
ProtoDefs.httpOkStatusCode,
|
||||
authToken.toString(),
|
||||
authToken.getLifetime());
|
||||
out.println(getAuthTokRespMsg.toString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// tbd, use a custom exception and then set the status based
|
||||
// on the type of exeption cached.
|
||||
|
||||
// Write out the response
|
||||
try
|
||||
{
|
||||
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||
ProtoDefs.httpUnauthorizedStatusCode);
|
||||
out.println(getAuthTokRespMsg.toString());
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
System.err.println("GetAuthToken.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
}
|
@ -29,65 +29,66 @@ package com.novell.casa.authtoksvc;
|
||||
*
|
||||
* This is the interface to Identity Token Providers.
|
||||
*/
|
||||
public interface IdentityToken {
|
||||
|
||||
/*
|
||||
* Initialize the token with parameters.
|
||||
*/
|
||||
void initialize (
|
||||
String identityId,
|
||||
String sourceName,
|
||||
String targetService,
|
||||
String targetHost) throws Exception;
|
||||
public interface IdentityToken
|
||||
{
|
||||
|
||||
/*
|
||||
* Initialize the token object with encoded token string.
|
||||
*/
|
||||
void initialize (String encodedToken) throws Exception;
|
||||
/*
|
||||
* Initialize the token with parameters.
|
||||
*/
|
||||
void initialize (
|
||||
String identityId,
|
||||
String sourceName,
|
||||
String targetService,
|
||||
String targetHost) throws Exception;
|
||||
|
||||
/*
|
||||
* Returns encoded token string.
|
||||
*
|
||||
* IMPORTANT: The token string can not contain the substring "]]>"
|
||||
* within it.
|
||||
*/
|
||||
String getEncodedToken() throws Exception;
|
||||
|
||||
/*
|
||||
* Returns a string containing the identity token provider type.
|
||||
*/
|
||||
String getProviderType() throws Exception;
|
||||
/*
|
||||
* Initialize the token object with encoded token string.
|
||||
*/
|
||||
void initialize (String encodedToken) throws Exception;
|
||||
|
||||
/*
|
||||
* Returns a string containing the identity id.
|
||||
*/
|
||||
String getIdentityId() throws Exception;
|
||||
|
||||
/*
|
||||
* Returns a string containing the name associated with the
|
||||
* identity source.
|
||||
*/
|
||||
String getSourceName() throws Exception;
|
||||
|
||||
/*
|
||||
* Returns a string containing the url associated with the
|
||||
* identity source.
|
||||
*/
|
||||
String getSourceUrl() 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;
|
||||
/*
|
||||
* Returns encoded token string.
|
||||
*
|
||||
* IMPORTANT: The token string can not contain the substring "]]>"
|
||||
* 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.
|
||||
*/
|
||||
String getIdentityId() throws Exception;
|
||||
|
||||
/*
|
||||
* Returns a string containing the name associated with the
|
||||
* identity source.
|
||||
*/
|
||||
String getSourceName() throws Exception;
|
||||
|
||||
/*
|
||||
* Returns a string containing the url associated with the
|
||||
* identity source.
|
||||
*/
|
||||
String getSourceUrl() 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;
|
||||
}
|
||||
|
@ -57,222 +57,222 @@ import org.bandit.ia.IAContext;
|
||||
* This class processes authentication requests utilizing a kerberos-V token.
|
||||
*
|
||||
*/
|
||||
public class Krb5Authenticate extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
||||
{
|
||||
private static final long serialVersionUID = 7247746330553668339L;
|
||||
public class Krb5Authenticate extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
||||
{
|
||||
private static final long serialVersionUID = 7247746330553668339L;
|
||||
|
||||
/*
|
||||
* tbd - This needs to be somewhere else so that the same parameter
|
||||
* can be accessed by other authentication mechanisms.
|
||||
*
|
||||
* Configurable operating parameters
|
||||
*
|
||||
*/
|
||||
public String sessionTokenLifetime = "360";
|
||||
|
||||
/*
|
||||
* GSS Long Lived variables
|
||||
*/
|
||||
protected GSSManager m_manager;
|
||||
protected Oid m_krb5;
|
||||
protected GSSName m_svcName;
|
||||
protected GSSCredential m_credential;
|
||||
/*
|
||||
* tbd - This needs to be somewhere else so that the same parameter
|
||||
* can be accessed by other authentication mechanisms.
|
||||
*
|
||||
* Configurable operating parameters
|
||||
*
|
||||
*/
|
||||
public String sessionTokenLifetime = "360";
|
||||
|
||||
/*
|
||||
* Krb5 Token Class.
|
||||
*/
|
||||
private class Krb5Token
|
||||
{
|
||||
private String m_principalName = "";
|
||||
/*
|
||||
* GSS Long Lived variables
|
||||
*/
|
||||
protected GSSManager m_manager;
|
||||
protected Oid m_krb5;
|
||||
protected GSSName m_svcName;
|
||||
protected GSSCredential m_credential;
|
||||
|
||||
/*
|
||||
* The format of the Krb5 token is as follows:
|
||||
*
|
||||
* Base64.encode(GSS-API Token data));
|
||||
*/
|
||||
public Krb5Token(String encodedToken, Krb5Authenticate parent) throws Exception
|
||||
{
|
||||
// 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();
|
||||
/*
|
||||
* Krb5 Token Class.
|
||||
*/
|
||||
private class Krb5Token
|
||||
{
|
||||
private String m_principalName = "";
|
||||
|
||||
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);
|
||||
/*
|
||||
* The format of the Krb5 token is as follows:
|
||||
*
|
||||
* Base64.encode(GSS-API Token data));
|
||||
*/
|
||||
public Krb5Token(String encodedToken, Krb5Authenticate parent) throws Exception
|
||||
{
|
||||
// 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
|
||||
// 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");
|
||||
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
|
||||
{
|
||||
// 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, "");
|
||||
|
||||
DirContext ctx = new InitialDirContext(env);
|
||||
DirContext ctx = new InitialDirContext(env);
|
||||
|
||||
// Now search for a user with a matching kerberos principal name
|
||||
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
|
||||
matchAttrs.put(new BasicAttribute("krbPrincipalName", krb5Token.getPrincipalName()));
|
||||
// Now search for a user with a matching kerberos principal name
|
||||
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
|
||||
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
|
||||
String identId = null;
|
||||
if (answer.hasMore())
|
||||
{
|
||||
// The search succeeded, set the identity id.
|
||||
SearchResult sr = (SearchResult)answer.next();
|
||||
identId = sr.getName() + ",o=novell";
|
||||
}
|
||||
|
||||
// Create response based on the identity resolution results
|
||||
if (identId != null)
|
||||
{
|
||||
// An identity was resolved, get a SessionToken for it.
|
||||
SessionToken sessionToken = new SessionToken(identId, authReqMsg.getRealm(), sessionTokenLifetime);
|
||||
|
||||
// Write out the response
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpOkStatusMsg,
|
||||
ProtoDefs.httpOkStatusCode,
|
||||
sessionToken.toString(),
|
||||
sessionTokenLifetime);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write out the response
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpUnauthorizedStatusMsg,
|
||||
ProtoDefs.httpUnauthorizedStatusCode);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
// tbd
|
||||
// Log the error
|
||||
System.err.println("Krb5Authenticate.doPost()- Exception caught: " + e.getExplanation());
|
||||
|
||||
// Write out the response
|
||||
try
|
||||
{
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||
ProtoDefs.httpServerErrorStatusCode);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
System.err.println("Krb5Authenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// tbd
|
||||
System.err.println("Krb5Authenticate.doPost()- Exception: " + e.toString());
|
||||
|
||||
// Write out the response
|
||||
try
|
||||
{
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||
ProtoDefs.httpServerErrorStatusCode);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
System.err.println("Krb5Authenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Done sending out the reply
|
||||
out.close();
|
||||
}
|
||||
// Proceed based on the result of the search
|
||||
String identId = null;
|
||||
if (answer.hasMore())
|
||||
{
|
||||
// The search succeeded, set the identity id.
|
||||
SearchResult sr = (SearchResult)answer.next();
|
||||
identId = sr.getName() + ",o=novell";
|
||||
}
|
||||
|
||||
// Create response based on the identity resolution results
|
||||
if (identId != null)
|
||||
{
|
||||
// An identity was resolved, get a SessionToken for it.
|
||||
SessionToken sessionToken = new SessionToken(identId, authReqMsg.getRealm(), sessionTokenLifetime);
|
||||
|
||||
// Write out the response
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpOkStatusMsg,
|
||||
ProtoDefs.httpOkStatusCode,
|
||||
sessionToken.toString(),
|
||||
sessionTokenLifetime);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write out the response
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpUnauthorizedStatusMsg,
|
||||
ProtoDefs.httpUnauthorizedStatusCode);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
// tbd
|
||||
// Log the error
|
||||
System.err.println("Krb5Authenticate.doPost()- Exception caught: " + e.getExplanation());
|
||||
|
||||
// Write out the response
|
||||
try
|
||||
{
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||
ProtoDefs.httpServerErrorStatusCode);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
System.err.println("Krb5Authenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// tbd
|
||||
System.err.println("Krb5Authenticate.doPost()- Exception: " + e.toString());
|
||||
|
||||
// Write out the response
|
||||
try
|
||||
{
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||
ProtoDefs.httpServerErrorStatusCode);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
System.err.println("Krb5Authenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Done sending out the reply
|
||||
out.close();
|
||||
}
|
||||
}
|
@ -31,53 +31,54 @@ package com.novell.casa.authtoksvc;
|
||||
* protocol.
|
||||
*
|
||||
*/
|
||||
public class ProtoDefs {
|
||||
public class ProtoDefs
|
||||
{
|
||||
|
||||
/*
|
||||
* XML Declaration used in the Casa Client/Server protocol
|
||||
*/
|
||||
public final static String xmlDeclaration = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
|
||||
|
||||
/*
|
||||
* XML Element Name Constants for the documents exchanged between the
|
||||
* Casa Client and the Casa Server.
|
||||
*/
|
||||
public final static String authRequestElementName = "auth_req";
|
||||
public final static String authResponseElementName = "auth_resp";
|
||||
public final static String getAuthPolicyRequestElementName = "get_auth_policy_req";
|
||||
public final static String getAuthPolicyResponseElementName = "get_auth_policy_resp";
|
||||
public final static String getAuthTokRequestElementName = "get_auth_tok_req";
|
||||
public final static String getAuthTokResponseElementName = "get_auth_tok_resp";
|
||||
public final static String authMechTokenElementName = "auth_mech_token";
|
||||
public final static String statusElementName = "status";
|
||||
public final static String sessionTokenElementName = "session_token";
|
||||
public final static String authTokenElementName = "auth_token";
|
||||
public final static String authPolicyElementName = "auth_policy";
|
||||
public final static String identTokenElementName = "ident_token";
|
||||
public final static String lifetimeElementName = "lifetime";
|
||||
public final static String signatureElementName = "signature";
|
||||
public final static String typeElementName = "type";
|
||||
public final static String descriptionElementName = "description";
|
||||
public final static String serviceElementName = "service";
|
||||
public final static String hostElementName = "host";
|
||||
public final static String identIdElementName = "ident_id";
|
||||
public final static String realmElementName = "realm";
|
||||
public final static String authSourceElementName = "auth_source";
|
||||
public final static String mechanismElementName = "mechanism";
|
||||
public final static String mechanismInfoElementName = "mechanism_info";
|
||||
|
||||
/*
|
||||
* Configurable operating parameters
|
||||
*/
|
||||
public String sessionTokenLifetime = "360";
|
||||
|
||||
/*
|
||||
* HTTP Status Codes and Messages
|
||||
*/
|
||||
public final static String httpOkStatusCode = "200";
|
||||
public final static String httpOkStatusMsg = "OK";
|
||||
public final static String httpUnauthorizedStatusCode = "401";
|
||||
public final static String httpUnauthorizedStatusMsg = "Unauthorized";
|
||||
public final static String httpServerErrorStatusCode = "500";
|
||||
public final static String httpServerErrorStatusMsg = "Internal Server Error";
|
||||
/*
|
||||
* XML Declaration used in the Casa Client/Server protocol
|
||||
*/
|
||||
public final static String xmlDeclaration = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
|
||||
|
||||
/*
|
||||
* XML Element Name Constants for the documents exchanged between the
|
||||
* Casa Client and the Casa Server.
|
||||
*/
|
||||
public final static String authRequestElementName = "auth_req";
|
||||
public final static String authResponseElementName = "auth_resp";
|
||||
public final static String getAuthPolicyRequestElementName = "get_auth_policy_req";
|
||||
public final static String getAuthPolicyResponseElementName = "get_auth_policy_resp";
|
||||
public final static String getAuthTokRequestElementName = "get_auth_tok_req";
|
||||
public final static String getAuthTokResponseElementName = "get_auth_tok_resp";
|
||||
public final static String authMechTokenElementName = "auth_mech_token";
|
||||
public final static String statusElementName = "status";
|
||||
public final static String sessionTokenElementName = "session_token";
|
||||
public final static String authTokenElementName = "auth_token";
|
||||
public final static String authPolicyElementName = "auth_policy";
|
||||
public final static String identTokenElementName = "ident_token";
|
||||
public final static String lifetimeElementName = "lifetime";
|
||||
public final static String signatureElementName = "signature";
|
||||
public final static String typeElementName = "type";
|
||||
public final static String descriptionElementName = "description";
|
||||
public final static String serviceElementName = "service";
|
||||
public final static String hostElementName = "host";
|
||||
public final static String identIdElementName = "ident_id";
|
||||
public final static String realmElementName = "realm";
|
||||
public final static String authSourceElementName = "auth_source";
|
||||
public final static String mechanismElementName = "mechanism";
|
||||
public final static String mechanismInfoElementName = "mechanism_info";
|
||||
|
||||
/*
|
||||
* Configurable operating parameters
|
||||
*/
|
||||
public String sessionTokenLifetime = "360";
|
||||
|
||||
/*
|
||||
* HTTP Status Codes and Messages
|
||||
*/
|
||||
public final static String httpOkStatusCode = "200";
|
||||
public final static String httpOkStatusMsg = "OK";
|
||||
public final static String httpUnauthorizedStatusCode = "401";
|
||||
public final static String httpUnauthorizedStatusMsg = "Unauthorized";
|
||||
public final static String httpServerErrorStatusCode = "500";
|
||||
public final static String httpServerErrorStatusMsg = "Internal Server Error";
|
||||
}
|
||||
|
@ -55,128 +55,128 @@ import org.bandit.ia.IAContext;
|
||||
* 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
|
||||
* can be accessed by other authentication mechanisms.
|
||||
*
|
||||
* Configurable operating parameters
|
||||
*
|
||||
*/
|
||||
public String sessionTokenLifetime = "360";
|
||||
|
||||
/*
|
||||
* Password Token Class.
|
||||
*/
|
||||
private class PwToken
|
||||
{
|
||||
private String m_username = "";
|
||||
private String m_password = "";
|
||||
/*
|
||||
* tbd - This needs to be somewhere else so that the same parameter
|
||||
* can be accessed by other authentication mechanisms.
|
||||
*
|
||||
* Configurable operating parameters
|
||||
*
|
||||
*/
|
||||
public String sessionTokenLifetime = "360";
|
||||
|
||||
/*
|
||||
* The format of the Pw token is as follows:
|
||||
*
|
||||
* Base64.encode(new String("username\r\n" + "password\r\n"));
|
||||
*/
|
||||
public PwToken(String encodedToken) throws IOException
|
||||
{
|
||||
// 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();
|
||||
/*
|
||||
* Password Token Class.
|
||||
*/
|
||||
private class PwToken
|
||||
{
|
||||
private String m_username = "";
|
||||
private String m_password = "";
|
||||
|
||||
try
|
||||
{
|
||||
// Read and parse the AuthReqMsg sent from the client
|
||||
InputStream inStream = request.getInputStream();
|
||||
AuthReqMsg authReqMsg = new AuthReqMsg(inStream);
|
||||
/*
|
||||
* The format of the Pw token is as follows:
|
||||
*
|
||||
* Base64.encode(new String("username\r\n" + "password\r\n"));
|
||||
*/
|
||||
public PwToken(String encodedToken) throws IOException
|
||||
{
|
||||
// Decode the token
|
||||
String token = Base64Coder.decode(encodedToken);
|
||||
|
||||
// Now parse the PW Token
|
||||
PwToken pwToken = new PwToken(authReqMsg.getAuthMechToken());
|
||||
BufferedReader tokenReader = new BufferedReader(new StringReader(token));
|
||||
|
||||
// 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");
|
||||
// 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
|
||||
{
|
||||
// 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, "");
|
||||
|
||||
DirContext ctx = new InitialDirContext(env);
|
||||
DirContext ctx = new InitialDirContext(env);
|
||||
|
||||
// Now search for a user with a matching surname
|
||||
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
|
||||
matchAttrs.put(new BasicAttribute("cn", pwToken.getUsername()));
|
||||
// Now search for a user with a matching surname
|
||||
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
|
||||
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
|
||||
String identId = null;
|
||||
while (answer.hasMore())
|
||||
{
|
||||
SearchResult sr = (SearchResult)answer.next();
|
||||
|
||||
System.err.println(sr.getName());
|
||||
// Enumerate through the users returned checking the password
|
||||
String identId = null;
|
||||
while (answer.hasMore())
|
||||
{
|
||||
SearchResult sr = (SearchResult)answer.next();
|
||||
|
||||
// Open a directory context for the user as a way of verifying its password
|
||||
try
|
||||
{
|
||||
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");
|
||||
System.err.println(sr.getName());
|
||||
|
||||
// Open a directory context for the user as a way of verifying its password
|
||||
try
|
||||
{
|
||||
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(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_CREDENTIALS, pwToken.getPassword());
|
||||
|
||||
if ((new InitialDirContext(env2)) != null)
|
||||
{
|
||||
// The password must be valid, set the identity Id.
|
||||
identId = sr.getName() + ",o=novell";
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
System.err.println("PwdAuthenticate.doPost()- Naming Exception: " + e.getExplanation());
|
||||
}
|
||||
}
|
||||
|
||||
// Create response based on the identity resolution results
|
||||
if (identId != null)
|
||||
{
|
||||
// An identity was resolved, get a SessionToken for it.
|
||||
SessionToken sessionToken = new SessionToken(identId, authReqMsg.getRealm(), sessionTokenLifetime);
|
||||
|
||||
// Write out the response
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpOkStatusMsg,
|
||||
ProtoDefs.httpOkStatusCode,
|
||||
sessionToken.toString(),
|
||||
sessionTokenLifetime);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write out the response
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpUnauthorizedStatusMsg,
|
||||
ProtoDefs.httpUnauthorizedStatusCode);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
// tbd
|
||||
// Log the error
|
||||
System.err.println("PwdAuthenticate.doPost()- Naming Exception on Proxy User: " + e.getExplanation());
|
||||
|
||||
// Write out the response
|
||||
try
|
||||
{
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||
ProtoDefs.httpServerErrorStatusCode);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
System.err.println("PwdAuthenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// tbd
|
||||
System.err.println("PwdAuthenticate.doPost()- Naming Exception on Proxy User: " + e.toString());
|
||||
|
||||
// Write out the response
|
||||
try
|
||||
{
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||
ProtoDefs.httpServerErrorStatusCode);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
System.err.println("PwdAuthenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Done sending out the reply
|
||||
out.close();
|
||||
}
|
||||
if ((new InitialDirContext(env2)) != null)
|
||||
{
|
||||
// The password must be valid, set the identity Id.
|
||||
identId = sr.getName() + ",o=novell";
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
System.err.println("PwdAuthenticate.doPost()- Naming Exception: " + e.getExplanation());
|
||||
}
|
||||
}
|
||||
|
||||
// Create response based on the identity resolution results
|
||||
if (identId != null)
|
||||
{
|
||||
// An identity was resolved, get a SessionToken for it.
|
||||
SessionToken sessionToken = new SessionToken(identId, authReqMsg.getRealm(), sessionTokenLifetime);
|
||||
|
||||
// Write out the response
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpOkStatusMsg,
|
||||
ProtoDefs.httpOkStatusCode,
|
||||
sessionToken.toString(),
|
||||
sessionTokenLifetime);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write out the response
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpUnauthorizedStatusMsg,
|
||||
ProtoDefs.httpUnauthorizedStatusCode);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
// tbd
|
||||
// Log the error
|
||||
System.err.println("PwdAuthenticate.doPost()- Naming Exception on Proxy User: " + e.getExplanation());
|
||||
|
||||
// Write out the response
|
||||
try
|
||||
{
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||
ProtoDefs.httpServerErrorStatusCode);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
System.err.println("PwdAuthenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// tbd
|
||||
System.err.println("PwdAuthenticate.doPost()- Naming Exception on Proxy User: " + e.toString());
|
||||
|
||||
// Write out the response
|
||||
try
|
||||
{
|
||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||
ProtoDefs.httpServerErrorStatusCode);
|
||||
out.println(authRespMsg.toString());
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
System.err.println("PwdAuthenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Done sending out the reply
|
||||
out.close();
|
||||
}
|
||||
}
|
@ -48,365 +48,369 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
* </session_token>
|
||||
*
|
||||
*/
|
||||
public class SessionToken {
|
||||
|
||||
private String m_id;
|
||||
private String m_realm;
|
||||
private String m_lifetime;
|
||||
private String m_signature;
|
||||
private String m_token;
|
||||
public class SessionToken
|
||||
{
|
||||
|
||||
/*
|
||||
* 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_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;
|
||||
private String m_id;
|
||||
private String m_realm;
|
||||
private String m_lifetime;
|
||||
private String m_signature;
|
||||
private String m_token;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
public SAXHandler (SessionToken SessionToken)
|
||||
{
|
||||
super();
|
||||
|
||||
// Initialize our members
|
||||
m_SessionToken = SessionToken;
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
/*
|
||||
* 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_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;
|
||||
|
||||
/*
|
||||
* endDocument() implementation.
|
||||
*/
|
||||
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");
|
||||
}
|
||||
private SessionToken m_SessionToken;
|
||||
private int m_state;
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
public SAXHandler (SessionToken SessionToken)
|
||||
{
|
||||
super();
|
||||
|
||||
/*
|
||||
* 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";
|
||||
// Initialize our members
|
||||
m_SessionToken = SessionToken;
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
/*
|
||||
* endDocument() implementation.
|
||||
*/
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user