Mostly formatting changes.
This commit is contained in:
parent
79e2f829f4
commit
0983950115
@ -46,233 +46,237 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
|||||||
* </auth_req>
|
* </auth_req>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AuthReqMsg {
|
public class AuthReqMsg
|
||||||
|
{
|
||||||
|
|
||||||
protected String m_realm = null;
|
protected String m_realm = null;
|
||||||
protected String m_authMechToken = null;
|
protected String m_authMechToken = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class for handling Authentication Request parsing events.
|
* Class for handling Authentication Request parsing events.
|
||||||
*/
|
*/
|
||||||
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
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_START = 0;
|
||||||
private final static int AWAITING_ROOT_ELEMENT_END = 1;
|
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_START = 2;
|
||||||
private final static int AWAITING_REALM_ELEMENT_END = 3;
|
private final static int AWAITING_REALM_ELEMENT_END = 3;
|
||||||
private final static int AWAITING_REALM_DATA = 4;
|
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_START = 5;
|
||||||
private final static int AWAITING_AUTH_MECH_TOKEN_ELEMENT_END = 6;
|
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 AWAITING_AUTH_MECH_TOKEN_DATA = 7;
|
||||||
private final static int DONE_PARSING = 8;
|
private final static int DONE_PARSING = 8;
|
||||||
|
|
||||||
private AuthReqMsg m_authReqMsg;
|
private AuthReqMsg m_authReqMsg;
|
||||||
private int m_state;
|
private int m_state;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public SAXHandler (AuthReqMsg authReqMsg)
|
public SAXHandler (AuthReqMsg authReqMsg)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
// Initialize our members
|
// Initialize our members
|
||||||
m_authReqMsg = authReqMsg;
|
m_authReqMsg = authReqMsg;
|
||||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* endDocument() implementation.
|
* endDocument() implementation.
|
||||||
*/
|
*/
|
||||||
public void endDocument () throws SAXException
|
public void endDocument () throws SAXException
|
||||||
{
|
{
|
||||||
// Verify that we obtained all of the required elements
|
// Verify that we obtained all of the required elements
|
||||||
if (m_state != DONE_PARSING)
|
if (m_state != DONE_PARSING)
|
||||||
{
|
{
|
||||||
System.err.println("AuthReqMsg SAXHandler.endDocument()- Missing element");
|
System.err.println("AuthReqMsg SAXHandler.endDocument()- Missing element");
|
||||||
throw new SAXException("Missing element");
|
throw new SAXException("Missing element");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* startElement() implementation.
|
* startElement() implementation.
|
||||||
*/
|
*/
|
||||||
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_ROOT_ELEMENT_START:
|
case AWAITING_ROOT_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.authRequestElementName.equals(qName))
|
if (ProtoDefs.authRequestElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_REALM_ELEMENT_START;
|
m_state = AWAITING_REALM_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthReqMsg SAXHandler.startElement()- Un-expected element");
|
System.err.println("AuthReqMsg SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_REALM_ELEMENT_START:
|
case AWAITING_REALM_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.realmElementName.equals(qName))
|
if (ProtoDefs.realmElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_REALM_DATA;
|
m_state = AWAITING_REALM_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthReqMsg SAXHandler.startElement()- Un-expected element");
|
System.err.println("AuthReqMsg SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_AUTH_MECH_TOKEN_ELEMENT_START:
|
case AWAITING_AUTH_MECH_TOKEN_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.authMechTokenElementName.equals(qName))
|
if (ProtoDefs.authMechTokenElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_AUTH_MECH_TOKEN_DATA;
|
m_state = AWAITING_AUTH_MECH_TOKEN_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthReqMsg SAXHandler.startElement()- Un-expected element");
|
System.err.println("AuthReqMsg SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
System.err.println("AuthReqMsg SAXHandler.startElement()- State error");
|
System.err.println("AuthReqMsg SAXHandler.startElement()- State error");
|
||||||
throw new SAXException("State error");
|
throw new SAXException("State error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* endElement() immplementation.
|
* endElement() immplementation.
|
||||||
*/
|
*/
|
||||||
public void endElement (String uri, String name, String qName) throws SAXException
|
public void endElement (String uri, String name, String qName) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_ROOT_ELEMENT_END:
|
case AWAITING_ROOT_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.authRequestElementName.equals(qName))
|
if (ProtoDefs.authRequestElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = DONE_PARSING;
|
m_state = DONE_PARSING;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthReqMsg SAXHandler.endElement()- Un-expected element");
|
System.err.println("AuthReqMsg SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_REALM_ELEMENT_END:
|
case AWAITING_REALM_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.realmElementName.equals(qName))
|
if (ProtoDefs.realmElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_AUTH_MECH_TOKEN_ELEMENT_START;
|
m_state = AWAITING_AUTH_MECH_TOKEN_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthReqMsg SAXHandler.endElement()- Un-expected element");
|
System.err.println("AuthReqMsg SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_AUTH_MECH_TOKEN_ELEMENT_END:
|
case AWAITING_AUTH_MECH_TOKEN_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.authMechTokenElementName.equals(qName))
|
if (ProtoDefs.authMechTokenElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_ROOT_ELEMENT_END;
|
m_state = AWAITING_ROOT_ELEMENT_END;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthReqMsg SAXHandler.endElement()- Un-expected element");
|
System.err.println("AuthReqMsg SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
System.err.println("AuthReqMsg SAXHandler.startElement()- State error");
|
System.err.println("AuthReqMsg SAXHandler.startElement()- State error");
|
||||||
throw new SAXException("State error");
|
throw new SAXException("State error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* character() implementation.
|
* character() implementation.
|
||||||
*/
|
*/
|
||||||
public void characters (char ch[], int start, int length) throws SAXException
|
public void characters (char ch[], int start, int length) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_REALM_DATA:
|
case AWAITING_REALM_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_authReqMsg.m_realm = new String(ch, start, length);
|
m_authReqMsg.m_realm = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_REALM_ELEMENT_END;
|
m_state = AWAITING_REALM_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_AUTH_MECH_TOKEN_DATA:
|
case AWAITING_AUTH_MECH_TOKEN_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_authReqMsg.m_authMechToken = new String(ch, start, length);
|
m_authReqMsg.m_authMechToken = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_AUTH_MECH_TOKEN_ELEMENT_END;
|
m_state = AWAITING_AUTH_MECH_TOKEN_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Do nothing
|
// Do nothing
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public AuthReqMsg (InputStream inStream) throws Exception
|
public AuthReqMsg (InputStream inStream) throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Parse the AuthReqMsg
|
// Parse the AuthReqMsg
|
||||||
XMLReader xr = XMLReaderFactory.createXMLReader();
|
XMLReader xr = XMLReaderFactory.createXMLReader();
|
||||||
SAXHandler handler = new SAXHandler(this);
|
SAXHandler handler = new SAXHandler(this);
|
||||||
xr.setContentHandler(handler);
|
xr.setContentHandler(handler);
|
||||||
xr.setErrorHandler(handler);
|
xr.setErrorHandler(handler);
|
||||||
|
|
||||||
InputSource source = new InputSource(inStream);
|
InputSource source = new InputSource(inStream);
|
||||||
xr.parse(source);
|
xr.parse(source);
|
||||||
}
|
}
|
||||||
catch (SAXException e)
|
catch (SAXException e)
|
||||||
{
|
{
|
||||||
System.err.println("AuthReqMsg()- Parse exception: " + e.toString());
|
System.err.println("AuthReqMsg()- Parse exception: " + e.toString());
|
||||||
throw new Exception("Protocol error");
|
throw new Exception("Protocol error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method to get the authentication realm.
|
* Method to get the authentication realm.
|
||||||
*/
|
*/
|
||||||
public String getRealm() throws Exception
|
public String getRealm() throws Exception
|
||||||
{
|
{
|
||||||
return m_realm;
|
return m_realm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method to get the authentication mechanism token.
|
* Method to get the authentication mechanism token.
|
||||||
*/
|
*/
|
||||||
public String getAuthMechToken() throws Exception
|
public String getAuthMechToken() throws Exception
|
||||||
{
|
{
|
||||||
return m_authMechToken;
|
return m_authMechToken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,64 +49,65 @@ package com.novell.casa.authtoksvc;
|
|||||||
* in the HTTP 1.1 Specification.
|
* in the HTTP 1.1 Specification.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AuthRespMsg {
|
public class AuthRespMsg
|
||||||
|
{
|
||||||
|
|
||||||
String m_msg;
|
String m_msg;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor for a msg that does not include the session token.
|
* Constructor for a msg that does not include the session token.
|
||||||
*/
|
*/
|
||||||
public AuthRespMsg (
|
public AuthRespMsg (
|
||||||
String statusDescription,
|
String statusDescription,
|
||||||
String statusCode) throws Exception
|
String statusCode) throws Exception
|
||||||
{
|
{
|
||||||
// Get a StringBuffer to help us with the construction of the message
|
// Get a StringBuffer to help us with the construction of the message
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
// Start building the message
|
// Start building the message
|
||||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.authResponseElementName + ">" + "\r\n");
|
sb.append("<" + ProtoDefs.authResponseElementName + ">" + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.statusElementName + ">"
|
sb.append("<" + ProtoDefs.statusElementName + ">"
|
||||||
+ "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
|
+ "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
|
||||||
+ statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
+ statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
||||||
sb.append("</" + ProtoDefs.authResponseElementName + ">" + "\r\n");
|
sb.append("</" + ProtoDefs.authResponseElementName + ">" + "\r\n");
|
||||||
|
|
||||||
// The message has now been built, save it.
|
// The message has now been built, save it.
|
||||||
m_msg = sb.toString();
|
m_msg = sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor for a msg that includes the session token.
|
* Constructor for a msg that includes the session token.
|
||||||
*/
|
*/
|
||||||
public AuthRespMsg (
|
public AuthRespMsg (
|
||||||
String statusDescription,
|
String statusDescription,
|
||||||
String statusCode,
|
String statusCode,
|
||||||
String sessionToken,
|
String sessionToken,
|
||||||
String sessionTokenLifetime) throws Exception
|
String sessionTokenLifetime) throws Exception
|
||||||
{
|
{
|
||||||
// Get a StringBuffer to help us with the construction of the message
|
// Get a StringBuffer to help us with the construction of the message
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
// Start building the message
|
// Start building the message
|
||||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.authResponseElementName + ">" + "\r\n");
|
sb.append("<" + ProtoDefs.authResponseElementName + ">" + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.statusElementName + ">"
|
sb.append("<" + ProtoDefs.statusElementName + ">"
|
||||||
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">"
|
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">"
|
||||||
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.sessionTokenElementName + ">"
|
sb.append("<" + ProtoDefs.sessionTokenElementName + ">"
|
||||||
+ "<" + ProtoDefs.lifetimeElementName + ">" + sessionTokenLifetime + "</" + ProtoDefs.lifetimeElementName + ">"
|
+ "<" + ProtoDefs.lifetimeElementName + ">" + sessionTokenLifetime + "</" + ProtoDefs.lifetimeElementName + ">"
|
||||||
+ sessionToken + "</" + ProtoDefs.sessionTokenElementName + ">" + "\r\n");
|
+ sessionToken + "</" + ProtoDefs.sessionTokenElementName + ">" + "\r\n");
|
||||||
sb.append("</" + ProtoDefs.authResponseElementName + ">" + "\r\n");
|
sb.append("</" + ProtoDefs.authResponseElementName + ">" + "\r\n");
|
||||||
|
|
||||||
// The message has now been built, save it.
|
// The message has now been built, save it.
|
||||||
m_msg = sb.toString();
|
m_msg = sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a string containing the AuthRespMsg.
|
* Returns a string containing the AuthRespMsg.
|
||||||
*/
|
*/
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return m_msg;
|
return m_msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,406 +47,410 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
|||||||
* </auth_token>
|
* </auth_token>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AuthToken {
|
public class AuthToken
|
||||||
|
{
|
||||||
|
|
||||||
private String m_token;
|
private String m_token;
|
||||||
private String m_lifetime;
|
private String m_lifetime;
|
||||||
private String m_identityTokenType;
|
private String m_identityTokenType;
|
||||||
private StringBuffer m_identityToken;
|
private StringBuffer m_identityToken;
|
||||||
private String m_signature;
|
private String m_signature;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class for handling parsing events.
|
* Class for handling parsing events.
|
||||||
*/
|
*/
|
||||||
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
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_START = 0;
|
||||||
private final static int AWAITING_ROOT_ELEMENT_END = 1;
|
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_START = 2;
|
||||||
private final static int AWAITING_SIGNATURE_ELEMENT_END = 3;
|
private final static int AWAITING_SIGNATURE_ELEMENT_END = 3;
|
||||||
private final static int AWAITING_SIGNATURE_DATA = 4;
|
private final static int AWAITING_SIGNATURE_DATA = 4;
|
||||||
private final static int AWAITING_LIFETIME_ELEMENT_START = 5;
|
private final static int AWAITING_LIFETIME_ELEMENT_START = 5;
|
||||||
private final static int AWAITING_LIFETIME_ELEMENT_END = 6;
|
private final static int AWAITING_LIFETIME_ELEMENT_END = 6;
|
||||||
private final static int AWAITING_LIFETIME_DATA = 7;
|
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_START = 8;
|
||||||
private final static int AWAITING_IDENT_TOKEN_ELEMENT_END = 9;
|
private final static int AWAITING_IDENT_TOKEN_ELEMENT_END = 9;
|
||||||
private final static int AWAITING_IDENT_TOKEN_DATA = 10;
|
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_START = 11;
|
||||||
private final static int AWAITING_TYPE_ELEMENT_END = 12;
|
private final static int AWAITING_TYPE_ELEMENT_END = 12;
|
||||||
private final static int AWAITING_TYPE_DATA = 13;
|
private final static int AWAITING_TYPE_DATA = 13;
|
||||||
private final static int DONE_PARSING = 14;
|
private final static int DONE_PARSING = 14;
|
||||||
|
|
||||||
private AuthToken m_AuthToken;
|
private AuthToken m_AuthToken;
|
||||||
private int m_state;
|
private int m_state;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public SAXHandler (AuthToken AuthToken)
|
public SAXHandler (AuthToken AuthToken)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
// Initialize our members
|
// Initialize our members
|
||||||
m_AuthToken = AuthToken;
|
m_AuthToken = AuthToken;
|
||||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* endDocument() implementation.
|
* endDocument() implementation.
|
||||||
*/
|
*/
|
||||||
public void endDocument () throws SAXException
|
public void endDocument () throws SAXException
|
||||||
{
|
{
|
||||||
// Verify that we obtained all of the required elements
|
// Verify that we obtained all of the required elements
|
||||||
if (m_state != DONE_PARSING)
|
if (m_state != DONE_PARSING)
|
||||||
{
|
{
|
||||||
System.err.println("AuthToken SAXHandler.endDocument()- Missing element");
|
System.err.println("AuthToken SAXHandler.endDocument()- Missing element");
|
||||||
throw new SAXException("Missing element");
|
throw new SAXException("Missing element");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* startElement() implementation.
|
* startElement() implementation.
|
||||||
*/
|
*/
|
||||||
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_ROOT_ELEMENT_START:
|
case AWAITING_ROOT_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.authTokenElementName.equals(qName))
|
if (ProtoDefs.authTokenElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SIGNATURE_ELEMENT_START;
|
m_state = AWAITING_SIGNATURE_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
|
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_SIGNATURE_ELEMENT_START:
|
case AWAITING_SIGNATURE_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.signatureElementName.equals(qName))
|
if (ProtoDefs.signatureElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SIGNATURE_DATA;
|
m_state = AWAITING_SIGNATURE_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
|
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_LIFETIME_ELEMENT_START:
|
case AWAITING_LIFETIME_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.lifetimeElementName.equals(qName))
|
if (ProtoDefs.lifetimeElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_LIFETIME_DATA;
|
m_state = AWAITING_LIFETIME_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
|
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_IDENT_TOKEN_ELEMENT_START:
|
case AWAITING_IDENT_TOKEN_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.identTokenElementName.equals(qName))
|
if (ProtoDefs.identTokenElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_TYPE_ELEMENT_START;
|
m_state = AWAITING_TYPE_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
|
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_TYPE_ELEMENT_START:
|
case AWAITING_TYPE_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.typeElementName.equals(qName))
|
if (ProtoDefs.typeElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_TYPE_DATA;
|
m_state = AWAITING_TYPE_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
|
System.err.println("AuthToken SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
System.err.println("AuthToken SAXHandler.startElement()- State error");
|
System.err.println("AuthToken SAXHandler.startElement()- State error");
|
||||||
throw new SAXException("State error");
|
throw new SAXException("State error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* endElement() immplementation.
|
* endElement() immplementation.
|
||||||
*/
|
*/
|
||||||
public void endElement (String uri, String name, String qName) throws SAXException
|
public void endElement (String uri, String name, String qName) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_ROOT_ELEMENT_END:
|
case AWAITING_ROOT_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.authTokenElementName.equals(qName))
|
if (ProtoDefs.authTokenElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = DONE_PARSING;
|
m_state = DONE_PARSING;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
|
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_SIGNATURE_ELEMENT_END:
|
case AWAITING_SIGNATURE_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.signatureElementName.equals(qName))
|
if (ProtoDefs.signatureElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_LIFETIME_ELEMENT_START;
|
m_state = AWAITING_LIFETIME_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
|
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_LIFETIME_ELEMENT_END:
|
case AWAITING_LIFETIME_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.lifetimeElementName.equals(qName))
|
if (ProtoDefs.lifetimeElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_IDENT_TOKEN_ELEMENT_START;
|
m_state = AWAITING_IDENT_TOKEN_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
|
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_TYPE_ELEMENT_END:
|
case AWAITING_TYPE_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.typeElementName.equals(qName))
|
if (ProtoDefs.typeElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_IDENT_TOKEN_DATA;
|
m_state = AWAITING_IDENT_TOKEN_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
|
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_IDENT_TOKEN_ELEMENT_END:
|
case AWAITING_IDENT_TOKEN_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.identTokenElementName.equals(qName))
|
if (ProtoDefs.identTokenElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_ROOT_ELEMENT_END;
|
m_state = AWAITING_ROOT_ELEMENT_END;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
|
System.err.println("AuthToken SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
System.err.println("AuthToken SAXHandler.startElement()- State error");
|
System.err.println("AuthToken SAXHandler.startElement()- State error");
|
||||||
throw new SAXException("State error");
|
throw new SAXException("State error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* character() implementation.
|
* character() implementation.
|
||||||
*/
|
*/
|
||||||
public void characters (char ch[], int start, int length) throws SAXException
|
public void characters (char ch[], int start, int length) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_SIGNATURE_DATA:
|
case AWAITING_SIGNATURE_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_AuthToken.m_signature = new String(ch, start, length);
|
m_AuthToken.m_signature = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SIGNATURE_ELEMENT_END;
|
m_state = AWAITING_SIGNATURE_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_LIFETIME_DATA:
|
case AWAITING_LIFETIME_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_AuthToken.m_lifetime = new String(ch, start, length);
|
m_AuthToken.m_lifetime = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_LIFETIME_ELEMENT_END;
|
m_state = AWAITING_LIFETIME_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_TYPE_DATA:
|
case AWAITING_TYPE_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_AuthToken.m_identityTokenType = new String(ch, start, length);
|
m_AuthToken.m_identityTokenType = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_TYPE_ELEMENT_END;
|
m_state = AWAITING_TYPE_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_IDENT_TOKEN_DATA:
|
case AWAITING_IDENT_TOKEN_DATA:
|
||||||
case AWAITING_IDENT_TOKEN_ELEMENT_END:
|
case AWAITING_IDENT_TOKEN_ELEMENT_END:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_AuthToken.m_identityToken.append(ch, start, length);
|
m_AuthToken.m_identityToken.append(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_IDENT_TOKEN_ELEMENT_END;
|
m_state = AWAITING_IDENT_TOKEN_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Do nothing
|
// Do nothing
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public AuthToken (
|
public AuthToken (
|
||||||
String identityId,
|
String identityId,
|
||||||
String realm,
|
String realm,
|
||||||
String targetService,
|
String targetService,
|
||||||
String targetHost) throws Exception
|
String targetHost) throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Verify that we have support for the specified service.
|
// Verify that we have support for the specified service.
|
||||||
// tbd
|
// tbd
|
||||||
|
|
||||||
// For now lets use the services of the only IdentityToken provider
|
// For now lets use the services of the only IdentityToken provider
|
||||||
// that we have.
|
// that we have.
|
||||||
//
|
//
|
||||||
// tbd - Add code to allow for the consumption of tokens
|
// tbd - Add code to allow for the consumption of tokens
|
||||||
// from different providers.
|
// from different providers.
|
||||||
CasaIdentityToken identityToken = new CasaIdentityToken();
|
CasaIdentityToken identityToken = new CasaIdentityToken();
|
||||||
identityToken.initialize(identityId,
|
identityToken.initialize(identityId,
|
||||||
realm,
|
realm,
|
||||||
targetService,
|
targetService,
|
||||||
targetHost);
|
targetHost);
|
||||||
|
|
||||||
m_identityToken = new StringBuffer();
|
m_identityToken = new StringBuffer();
|
||||||
m_identityToken.append(identityToken.getEncodedToken());
|
m_identityToken.append(identityToken.getEncodedToken());
|
||||||
m_identityTokenType = identityToken.getProviderType();
|
m_identityTokenType = identityToken.getProviderType();
|
||||||
|
|
||||||
m_lifetime = "56"; // tbd
|
m_lifetime = "56"; // tbd
|
||||||
|
|
||||||
// Generate a signature
|
// Generate a signature
|
||||||
// tbd - Over identToken, identToken type, and lifetime data.
|
// tbd - Over identToken, identToken type, and lifetime data.
|
||||||
m_signature = "tbd";
|
m_signature = "tbd";
|
||||||
|
|
||||||
// Get a StringBuffer to help us with the construction of the token
|
// Get a StringBuffer to help us with the construction of the token
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
// Start building the message
|
// Start building the message
|
||||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.authTokenElementName + ">" + "\r\n");
|
sb.append("<" + ProtoDefs.authTokenElementName + ">" + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.signatureElementName + ">" + m_signature + "</" + ProtoDefs.signatureElementName + ">" + "\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.lifetimeElementName + ">" + m_lifetime + "</" + ProtoDefs.lifetimeElementName + ">" + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.identTokenElementName + ">"
|
sb.append("<" + ProtoDefs.identTokenElementName + ">"
|
||||||
+ "<" + ProtoDefs.typeElementName + ">" + m_identityTokenType + "</" + ProtoDefs.typeElementName + ">"
|
+ "<" + ProtoDefs.typeElementName + ">" + m_identityTokenType + "</" + ProtoDefs.typeElementName + ">"
|
||||||
+ m_identityToken + "</" + ProtoDefs.identTokenElementName + ">" + "\r\n");
|
+ m_identityToken + "</" + ProtoDefs.identTokenElementName + ">" + "\r\n");
|
||||||
sb.append("</" + ProtoDefs.authTokenElementName + ">" + "\r\n");
|
sb.append("</" + ProtoDefs.authTokenElementName + ">" + "\r\n");
|
||||||
|
|
||||||
// Save the token
|
// Save the token
|
||||||
m_token = sb.toString();
|
m_token = sb.toString();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// tbd
|
// tbd
|
||||||
System.err.println("AuthToken()- Exception: " + e.toString());
|
System.err.println("AuthToken()- Exception: " + e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor given an authentication token string. The constructor
|
* Constructor given an authentication token string. The constructor
|
||||||
* validates the token as part of its processing.
|
* validates the token as part of its processing.
|
||||||
*/
|
*/
|
||||||
public AuthToken(String token) throws Exception
|
public AuthToken(String token) throws Exception
|
||||||
{
|
{
|
||||||
// Decode the token string
|
// Decode the token string
|
||||||
m_token = Base64Coder.decode(token);
|
m_token = Base64Coder.decode(token);
|
||||||
|
|
||||||
// Instantiate string buffer for the identity token
|
// Instantiate string buffer for the identity token
|
||||||
m_identityToken = new StringBuffer();
|
m_identityToken = new StringBuffer();
|
||||||
|
|
||||||
// Now parse the token into its elements
|
// Now parse the token into its elements
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Parse the AuthToken
|
// Parse the AuthToken
|
||||||
XMLReader xr = XMLReaderFactory.createXMLReader();
|
XMLReader xr = XMLReaderFactory.createXMLReader();
|
||||||
SAXHandler handler = new SAXHandler(this);
|
SAXHandler handler = new SAXHandler(this);
|
||||||
xr.setContentHandler(handler);
|
xr.setContentHandler(handler);
|
||||||
xr.setErrorHandler(handler);
|
xr.setErrorHandler(handler);
|
||||||
|
|
||||||
ByteArrayInputStream inStream = new ByteArrayInputStream(m_token.getBytes());
|
ByteArrayInputStream inStream = new ByteArrayInputStream(m_token.getBytes());
|
||||||
InputSource source = new InputSource(inStream);
|
InputSource source = new InputSource(inStream);
|
||||||
xr.parse(source);
|
xr.parse(source);
|
||||||
|
|
||||||
// Verify the signature
|
// Verify the signature
|
||||||
// tbd
|
// tbd
|
||||||
|
|
||||||
// Verify that the token has not expired
|
// Verify that the token has not expired
|
||||||
// tbd
|
// tbd
|
||||||
}
|
}
|
||||||
catch (SAXException e)
|
catch (SAXException e)
|
||||||
{
|
{
|
||||||
System.err.println("AuthToken()- Parse exception: " + e.toString());
|
System.err.println("AuthToken()- Parse exception: " + e.toString());
|
||||||
throw new Exception("Protocol error");
|
throw new Exception("Protocol error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a string containing the Base64 encode token.
|
* Returns a string containing the Base64 encode token.
|
||||||
*/
|
*/
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return Base64Coder.encode(m_token);
|
return Base64Coder.encode(m_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the lifetime of the token.
|
* Returns the lifetime of the token.
|
||||||
*/
|
*/
|
||||||
public String getLifetime()
|
public String getLifetime()
|
||||||
{
|
{
|
||||||
// tbd
|
// tbd
|
||||||
return "60";
|
return "60";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the identity token.
|
* Returns the identity token.
|
||||||
*/
|
*/
|
||||||
public String getIdentityToken()
|
public String getIdentityToken()
|
||||||
{
|
{
|
||||||
return m_identityToken.toString();
|
return m_identityToken.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the identity token type.
|
* Returns the identity token type.
|
||||||
*/
|
*/
|
||||||
public String getIdentityTokenType()
|
public String getIdentityTokenType()
|
||||||
{
|
{
|
||||||
return m_identityTokenType;
|
return m_identityTokenType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -39,99 +39,98 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
* service.
|
* service.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GetAuthPolicy extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
public class GetAuthPolicy extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = -8264027868130334613L;
|
private static final long serialVersionUID = -8264027868130334613L;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public GetAuthPolicy()
|
public GetAuthPolicy()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* doGet() implementation.
|
* doGet() implementation.
|
||||||
*/
|
*/
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
{
|
{
|
||||||
|
|
||||||
doPost(request, response);
|
doPost(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* doPost() implementation.
|
* doPost() implementation.
|
||||||
*/
|
*/
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
{
|
{
|
||||||
// Get ready to send back a reply
|
// Get ready to send back a reply
|
||||||
response.setContentType("text/html");
|
response.setContentType("text/html");
|
||||||
PrintWriter out = response.getWriter();
|
PrintWriter out = response.getWriter();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Read and parse the GetAuthPolicyReqMsg sent from the client
|
// Read and parse the GetAuthPolicyReqMsg sent from the client
|
||||||
InputStream inStream = request.getInputStream();
|
InputStream inStream = request.getInputStream();
|
||||||
GetAuthPolicyReqMsg getAuthPolicyReqMsg = new GetAuthPolicyReqMsg(inStream);
|
GetAuthPolicyReqMsg getAuthPolicyReqMsg = new GetAuthPolicyReqMsg(inStream);
|
||||||
|
|
||||||
// Get the auth policy for the service
|
// Get the auth policy for the service
|
||||||
byte[] authPolicy = getAuthPolicyFileData(getAuthPolicyReqMsg.getServiceName(),
|
byte[] authPolicy = getAuthPolicyFileData(getAuthPolicyReqMsg.getServiceName(),
|
||||||
getAuthPolicyReqMsg.getHostName());
|
getAuthPolicyReqMsg.getHostName());
|
||||||
|
|
||||||
// Write out the response
|
// Write out the response
|
||||||
GetAuthPolicyRespMsg getAuthPolicyRespMsg = new GetAuthPolicyRespMsg(ProtoDefs.httpOkStatusMsg,
|
GetAuthPolicyRespMsg getAuthPolicyRespMsg = new GetAuthPolicyRespMsg(ProtoDefs.httpOkStatusMsg,
|
||||||
ProtoDefs.httpOkStatusCode,
|
ProtoDefs.httpOkStatusCode,
|
||||||
new String(Base64Coder.encode(authPolicy)));
|
new String(Base64Coder.encode(authPolicy)));
|
||||||
out.println(getAuthPolicyRespMsg.toString());
|
out.println(getAuthPolicyRespMsg.toString());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// tbd
|
// tbd
|
||||||
System.err.println("GetAuthPolicy.doPost()- Exception caught: " + e.toString());
|
System.err.println("GetAuthPolicy.doPost()- Exception caught: " + e.toString());
|
||||||
|
|
||||||
// Write out the response
|
// Write out the response
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GetAuthPolicyRespMsg getAuthPolicyRespMsg = new GetAuthPolicyRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
GetAuthPolicyRespMsg getAuthPolicyRespMsg = new GetAuthPolicyRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||||
ProtoDefs.httpServerErrorStatusCode);
|
ProtoDefs.httpServerErrorStatusCode);
|
||||||
out.println(getAuthPolicyRespMsg.toString());
|
out.println(getAuthPolicyRespMsg.toString());
|
||||||
}
|
}
|
||||||
catch (Exception e2)
|
catch (Exception e2)
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthPolicy.doPost()- Exception trying to construct response msg: " + e2.toString());
|
System.err.println("GetAuthPolicy.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done sending out the reply
|
// Done sending out the reply
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the data associated with the authentication policy file
|
* Returns the data associated with the authentication policy file
|
||||||
* associated with the specified service.
|
* associated with the specified service.
|
||||||
*/
|
*/
|
||||||
private byte[] getAuthPolicyFileData(String serviceName, String hostName)
|
private byte[] getAuthPolicyFileData(String serviceName, String hostName)
|
||||||
{
|
{
|
||||||
// tdb - Read the file associated with the specified service
|
// tdb - Read the file associated with the specified service
|
||||||
StringBuffer sb = new StringBuffer();
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 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>
|
* </get_auth_policy_req>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GetAuthPolicyReqMsg {
|
public class GetAuthPolicyReqMsg
|
||||||
|
{
|
||||||
|
|
||||||
protected String m_serviceName = null;
|
protected String m_serviceName = null;
|
||||||
protected String m_hostName = null;
|
protected String m_hostName = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class for handling GetAuthPolicyReq msg parsing events.
|
* Class for handling GetAuthPolicyReq msg parsing events.
|
||||||
*/
|
*/
|
||||||
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
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_START = 0;
|
||||||
private final static int AWAITING_ROOT_ELEMENT_END = 1;
|
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_START = 2;
|
||||||
private final static int AWAITING_SERVICE_ELEMENT_END = 3;
|
private final static int AWAITING_SERVICE_ELEMENT_END = 3;
|
||||||
private final static int AWAITING_SERVICE_DATA = 4;
|
private final static int AWAITING_SERVICE_DATA = 4;
|
||||||
private final static int AWAITING_HOST_ELEMENT_START = 5;
|
private final static int AWAITING_HOST_ELEMENT_START = 5;
|
||||||
private final static int AWAITING_HOST_ELEMENT_END = 6;
|
private final static int AWAITING_HOST_ELEMENT_END = 6;
|
||||||
private final static int AWAITING_HOST_DATA = 7;
|
private final static int AWAITING_HOST_DATA = 7;
|
||||||
private final static int DONE_PARSING = 8;
|
private final static int DONE_PARSING = 8;
|
||||||
|
|
||||||
private GetAuthPolicyReqMsg m_GetAuthPolicyReqMsg;
|
private GetAuthPolicyReqMsg m_GetAuthPolicyReqMsg;
|
||||||
private int m_state;
|
private int m_state;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public SAXHandler (GetAuthPolicyReqMsg GetAuthPolicyReqMsg)
|
public SAXHandler (GetAuthPolicyReqMsg GetAuthPolicyReqMsg)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
// Initialize our members
|
// Initialize our members
|
||||||
m_GetAuthPolicyReqMsg = GetAuthPolicyReqMsg;
|
m_GetAuthPolicyReqMsg = GetAuthPolicyReqMsg;
|
||||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* endDocument() implementation.
|
* endDocument() implementation.
|
||||||
*/
|
*/
|
||||||
public void endDocument () throws SAXException
|
public void endDocument () throws SAXException
|
||||||
{
|
{
|
||||||
// Verify that we obtained all of the required elements
|
// Verify that we obtained all of the required elements
|
||||||
if (m_state != DONE_PARSING)
|
if (m_state != DONE_PARSING)
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthPolicyReqMsg SAXHandler.endDocument()- Missing element");
|
System.err.println("GetAuthPolicyReqMsg SAXHandler.endDocument()- Missing element");
|
||||||
throw new SAXException("Missing element");
|
throw new SAXException("Missing element");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* startElement() implementation.
|
* startElement() implementation.
|
||||||
*/
|
*/
|
||||||
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_ROOT_ELEMENT_START:
|
case AWAITING_ROOT_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.getAuthPolicyRequestElementName.equals(qName))
|
if (ProtoDefs.getAuthPolicyRequestElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SERVICE_ELEMENT_START;
|
m_state = AWAITING_SERVICE_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- Un-expected element");
|
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_SERVICE_ELEMENT_START:
|
case AWAITING_SERVICE_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.serviceElementName.equals(qName))
|
if (ProtoDefs.serviceElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SERVICE_DATA;
|
m_state = AWAITING_SERVICE_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- Un-expected element");
|
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_HOST_ELEMENT_START:
|
case AWAITING_HOST_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.hostElementName.equals(qName))
|
if (ProtoDefs.hostElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_HOST_DATA;
|
m_state = AWAITING_HOST_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- Un-expected element");
|
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- State error");
|
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- State error");
|
||||||
throw new SAXException("State error");
|
throw new SAXException("State error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* endElement() immplementation.
|
* endElement() immplementation.
|
||||||
*/
|
*/
|
||||||
public void endElement (String uri, String name, String qName) throws SAXException
|
public void endElement (String uri, String name, String qName) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_ROOT_ELEMENT_END:
|
case AWAITING_ROOT_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.getAuthPolicyRequestElementName.equals(qName))
|
if (ProtoDefs.getAuthPolicyRequestElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = DONE_PARSING;
|
m_state = DONE_PARSING;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthPolicyReqMsg SAXHandler.endElement()- Un-expected element");
|
System.err.println("GetAuthPolicyReqMsg SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_SERVICE_ELEMENT_END:
|
case AWAITING_SERVICE_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.serviceElementName.equals(qName))
|
if (ProtoDefs.serviceElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_HOST_ELEMENT_START;
|
m_state = AWAITING_HOST_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthPolicyReqMsg SAXHandler.endElement()- Un-expected element");
|
System.err.println("GetAuthPolicyReqMsg SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_HOST_ELEMENT_END:
|
case AWAITING_HOST_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.hostElementName.equals(qName))
|
if (ProtoDefs.hostElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_ROOT_ELEMENT_END;
|
m_state = AWAITING_ROOT_ELEMENT_END;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthPolicyReqMsg SAXHandler.endElement()- Un-expected element");
|
System.err.println("GetAuthPolicyReqMsg SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- State error");
|
System.err.println("GetAuthPolicyReqMsg SAXHandler.startElement()- State error");
|
||||||
throw new SAXException("State error");
|
throw new SAXException("State error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* character() implementation.
|
* character() implementation.
|
||||||
*/
|
*/
|
||||||
public void characters (char ch[], int start, int length) throws SAXException
|
public void characters (char ch[], int start, int length) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_SERVICE_DATA:
|
case AWAITING_SERVICE_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_GetAuthPolicyReqMsg.m_serviceName = new String(ch, start, length);
|
m_GetAuthPolicyReqMsg.m_serviceName = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SERVICE_ELEMENT_END;
|
m_state = AWAITING_SERVICE_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_HOST_DATA:
|
case AWAITING_HOST_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_GetAuthPolicyReqMsg.m_hostName = new String(ch, start, length);
|
m_GetAuthPolicyReqMsg.m_hostName = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_HOST_ELEMENT_END;
|
m_state = AWAITING_HOST_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Do nothing
|
// Do nothing
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public GetAuthPolicyReqMsg (InputStream inStream) throws Exception
|
public GetAuthPolicyReqMsg (InputStream inStream) throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Parse the GetAuthPolicyReqMsg
|
// Parse the GetAuthPolicyReqMsg
|
||||||
XMLReader xr = XMLReaderFactory.createXMLReader();
|
XMLReader xr = XMLReaderFactory.createXMLReader();
|
||||||
SAXHandler handler = new SAXHandler(this);
|
SAXHandler handler = new SAXHandler(this);
|
||||||
xr.setContentHandler(handler);
|
xr.setContentHandler(handler);
|
||||||
xr.setErrorHandler(handler);
|
xr.setErrorHandler(handler);
|
||||||
|
|
||||||
InputSource source = new InputSource(inStream);
|
InputSource source = new InputSource(inStream);
|
||||||
xr.parse(source);
|
xr.parse(source);
|
||||||
}
|
}
|
||||||
catch (SAXException e)
|
catch (SAXException e)
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthPolicyReqMsg()- Parse exception: " + e.toString());
|
System.err.println("GetAuthPolicyReqMsg()- Parse exception: " + e.toString());
|
||||||
throw new Exception("Protocol error");
|
throw new Exception("Protocol error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method to get the service name.
|
* Method to get the service name.
|
||||||
*/
|
*/
|
||||||
public String getServiceName() throws Exception
|
public String getServiceName() throws Exception
|
||||||
{
|
{
|
||||||
return m_serviceName;
|
return m_serviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method to get the host name.
|
* Method to get the host name.
|
||||||
*/
|
*/
|
||||||
public String getHostName() throws Exception
|
public String getHostName() throws Exception
|
||||||
{
|
{
|
||||||
return m_hostName;
|
return m_hostName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,61 +50,62 @@ package com.novell.casa.authtoksvc;
|
|||||||
* in the HTTP 1.1 Specification.
|
* in the HTTP 1.1 Specification.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GetAuthPolicyRespMsg {
|
public class GetAuthPolicyRespMsg
|
||||||
|
{
|
||||||
|
|
||||||
String m_msg;
|
String m_msg;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor for a msg that does not include the authentication policy.
|
* Constructor for a msg that does not include the authentication policy.
|
||||||
*/
|
*/
|
||||||
public GetAuthPolicyRespMsg (
|
public GetAuthPolicyRespMsg (
|
||||||
String statusDescription,
|
String statusDescription,
|
||||||
String statusCode) throws Exception
|
String statusCode) throws Exception
|
||||||
{
|
{
|
||||||
// Get a StringBuffer to help us with the construction of the message
|
// Get a StringBuffer to help us with the construction of the message
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
// Start building the message
|
// Start building the message
|
||||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
|
sb.append("<" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.statusElementName + ">"
|
sb.append("<" + ProtoDefs.statusElementName + ">"
|
||||||
+ "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
|
+ "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
|
||||||
+ statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
+ statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
||||||
sb.append("</" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
|
sb.append("</" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
|
||||||
|
|
||||||
// The message has now been built, save it.
|
// The message has now been built, save it.
|
||||||
m_msg = sb.toString();
|
m_msg = sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor for a msg that includes the authentication policy.
|
* Constructor for a msg that includes the authentication policy.
|
||||||
*/
|
*/
|
||||||
public GetAuthPolicyRespMsg (
|
public GetAuthPolicyRespMsg (
|
||||||
String statusDescription,
|
String statusDescription,
|
||||||
String statusCode,
|
String statusCode,
|
||||||
String authPolicy) throws Exception
|
String authPolicy) throws Exception
|
||||||
{
|
{
|
||||||
// Get a StringBuffer to help us with the construction of the message
|
// Get a StringBuffer to help us with the construction of the message
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
// Start building the message
|
// Start building the message
|
||||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
|
sb.append("<" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.statusElementName + ">"
|
sb.append("<" + ProtoDefs.statusElementName + ">"
|
||||||
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">"
|
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">"
|
||||||
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.authPolicyElementName + ">" + authPolicy + "</" + ProtoDefs.authPolicyElementName + ">" + "\r\n");
|
sb.append("<" + ProtoDefs.authPolicyElementName + ">" + authPolicy + "</" + ProtoDefs.authPolicyElementName + ">" + "\r\n");
|
||||||
sb.append("</" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
|
sb.append("</" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
|
||||||
|
|
||||||
// The message has now been built, save it.
|
// The message has now been built, save it.
|
||||||
m_msg = sb.toString();
|
m_msg = sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a string containing the GetAuthPolicyRespMsg.
|
* Returns a string containing the GetAuthPolicyRespMsg.
|
||||||
*/
|
*/
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return m_msg;
|
return m_msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,282 +46,286 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
|||||||
* </get_auth_token_req>
|
* </get_auth_token_req>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GetAuthTokReqMsg {
|
public class GetAuthTokReqMsg
|
||||||
|
{
|
||||||
|
|
||||||
protected String m_serviceName = null;
|
protected String m_serviceName = null;
|
||||||
protected String m_hostName = null;
|
protected String m_hostName = null;
|
||||||
protected String m_sessionToken = null;
|
protected String m_sessionToken = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class for handling GetAuthTokReq msg parsing events.
|
* Class for handling GetAuthTokReq msg parsing events.
|
||||||
*/
|
*/
|
||||||
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
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_START = 0;
|
||||||
private final static int AWAITING_ROOT_ELEMENT_END = 1;
|
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_START = 2;
|
||||||
private final static int AWAITING_SERVICE_ELEMENT_END = 3;
|
private final static int AWAITING_SERVICE_ELEMENT_END = 3;
|
||||||
private final static int AWAITING_SERVICE_DATA = 4;
|
private final static int AWAITING_SERVICE_DATA = 4;
|
||||||
private final static int AWAITING_HOST_ELEMENT_START = 5;
|
private final static int AWAITING_HOST_ELEMENT_START = 5;
|
||||||
private final static int AWAITING_HOST_ELEMENT_END = 6;
|
private final static int AWAITING_HOST_ELEMENT_END = 6;
|
||||||
private final static int AWAITING_HOST_DATA = 7;
|
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_START = 8;
|
||||||
private final static int AWAITING_SESSION_TOKEN_ELEMENT_END = 9;
|
private final static int AWAITING_SESSION_TOKEN_ELEMENT_END = 9;
|
||||||
private final static int AWAITING_SESSION_TOKEN_DATA = 10;
|
private final static int AWAITING_SESSION_TOKEN_DATA = 10;
|
||||||
private final static int DONE_PARSING = 11;
|
private final static int DONE_PARSING = 11;
|
||||||
|
|
||||||
private GetAuthTokReqMsg m_GetAuthTokReqMsg;
|
private GetAuthTokReqMsg m_GetAuthTokReqMsg;
|
||||||
private int m_state;
|
private int m_state;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public SAXHandler (GetAuthTokReqMsg GetAuthTokReqMsg)
|
public SAXHandler (GetAuthTokReqMsg GetAuthTokReqMsg)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
// Initialize our members
|
// Initialize our members
|
||||||
m_GetAuthTokReqMsg = GetAuthTokReqMsg;
|
m_GetAuthTokReqMsg = GetAuthTokReqMsg;
|
||||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* endDocument() implementation.
|
* endDocument() implementation.
|
||||||
*/
|
*/
|
||||||
public void endDocument () throws SAXException
|
public void endDocument () throws SAXException
|
||||||
{
|
{
|
||||||
// Verify that we obtained all of the required elements
|
// Verify that we obtained all of the required elements
|
||||||
if (m_state != DONE_PARSING)
|
if (m_state != DONE_PARSING)
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthTokReqMsg SAXHandler.endDocument()- Missing element");
|
System.err.println("GetAuthTokReqMsg SAXHandler.endDocument()- Missing element");
|
||||||
throw new SAXException("Missing element");
|
throw new SAXException("Missing element");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* startElement() implementation.
|
* startElement() implementation.
|
||||||
*/
|
*/
|
||||||
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_ROOT_ELEMENT_START:
|
case AWAITING_ROOT_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.getAuthTokRequestElementName.equals(qName))
|
if (ProtoDefs.getAuthTokRequestElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SERVICE_ELEMENT_START;
|
m_state = AWAITING_SERVICE_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
|
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_SERVICE_ELEMENT_START:
|
case AWAITING_SERVICE_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.serviceElementName.equals(qName))
|
if (ProtoDefs.serviceElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SERVICE_DATA;
|
m_state = AWAITING_SERVICE_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
|
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_HOST_ELEMENT_START:
|
case AWAITING_HOST_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.hostElementName.equals(qName))
|
if (ProtoDefs.hostElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_HOST_DATA;
|
m_state = AWAITING_HOST_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
|
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_SESSION_TOKEN_ELEMENT_START:
|
case AWAITING_SESSION_TOKEN_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.sessionTokenElementName.equals(qName))
|
if (ProtoDefs.sessionTokenElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SESSION_TOKEN_DATA;
|
m_state = AWAITING_SESSION_TOKEN_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
|
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- State error");
|
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- State error");
|
||||||
throw new SAXException("State error");
|
throw new SAXException("State error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* endElement() immplementation.
|
* endElement() immplementation.
|
||||||
*/
|
*/
|
||||||
public void endElement (String uri, String name, String qName) throws SAXException
|
public void endElement (String uri, String name, String qName) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_ROOT_ELEMENT_END:
|
case AWAITING_ROOT_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.getAuthTokRequestElementName.equals(qName))
|
if (ProtoDefs.getAuthTokRequestElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = DONE_PARSING;
|
m_state = DONE_PARSING;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
|
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_SERVICE_ELEMENT_END:
|
case AWAITING_SERVICE_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.serviceElementName.equals(qName))
|
if (ProtoDefs.serviceElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_HOST_ELEMENT_START;
|
m_state = AWAITING_HOST_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
|
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_HOST_ELEMENT_END:
|
case AWAITING_HOST_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.hostElementName.equals(qName))
|
if (ProtoDefs.hostElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SESSION_TOKEN_ELEMENT_START;
|
m_state = AWAITING_SESSION_TOKEN_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
|
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_SESSION_TOKEN_ELEMENT_END:
|
case AWAITING_SESSION_TOKEN_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.sessionTokenElementName.equals(qName))
|
if (ProtoDefs.sessionTokenElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_ROOT_ELEMENT_END;
|
m_state = AWAITING_ROOT_ELEMENT_END;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
|
System.err.println("GetAuthTokReqMsg SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- State error");
|
System.err.println("GetAuthTokReqMsg SAXHandler.startElement()- State error");
|
||||||
throw new SAXException("State error");
|
throw new SAXException("State error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* character() implementation.
|
* character() implementation.
|
||||||
*/
|
*/
|
||||||
public void characters (char ch[], int start, int length) throws SAXException
|
public void characters (char ch[], int start, int length) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_SERVICE_DATA:
|
case AWAITING_SERVICE_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_GetAuthTokReqMsg.m_serviceName = new String(ch, start, length);
|
m_GetAuthTokReqMsg.m_serviceName = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SERVICE_ELEMENT_END;
|
m_state = AWAITING_SERVICE_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_HOST_DATA:
|
case AWAITING_HOST_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_GetAuthTokReqMsg.m_hostName = new String(ch, start, length);
|
m_GetAuthTokReqMsg.m_hostName = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_HOST_ELEMENT_END;
|
m_state = AWAITING_HOST_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_SESSION_TOKEN_DATA:
|
case AWAITING_SESSION_TOKEN_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_GetAuthTokReqMsg.m_sessionToken = new String(ch, start, length);
|
m_GetAuthTokReqMsg.m_sessionToken = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SESSION_TOKEN_ELEMENT_END;
|
m_state = AWAITING_SESSION_TOKEN_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Do nothing
|
// Do nothing
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public GetAuthTokReqMsg (InputStream inStream) throws Exception
|
public GetAuthTokReqMsg (InputStream inStream) throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Parse the GetAuthTokReqMsg
|
// Parse the GetAuthTokReqMsg
|
||||||
XMLReader xr = XMLReaderFactory.createXMLReader();
|
XMLReader xr = XMLReaderFactory.createXMLReader();
|
||||||
SAXHandler handler = new SAXHandler(this);
|
SAXHandler handler = new SAXHandler(this);
|
||||||
xr.setContentHandler(handler);
|
xr.setContentHandler(handler);
|
||||||
xr.setErrorHandler(handler);
|
xr.setErrorHandler(handler);
|
||||||
|
|
||||||
InputSource source = new InputSource(inStream);
|
InputSource source = new InputSource(inStream);
|
||||||
xr.parse(source);
|
xr.parse(source);
|
||||||
}
|
}
|
||||||
catch (SAXException e)
|
catch (SAXException e)
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthTokReqMsg()- Parse exception: " + e.toString());
|
System.err.println("GetAuthTokReqMsg()- Parse exception: " + e.toString());
|
||||||
throw new Exception("Protocol error");
|
throw new Exception("Protocol error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method to get the service name.
|
* Method to get the service name.
|
||||||
*/
|
*/
|
||||||
public String getServiceName() throws Exception
|
public String getServiceName() throws Exception
|
||||||
{
|
{
|
||||||
return m_serviceName;
|
return m_serviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method to get the host name.
|
* Method to get the host name.
|
||||||
*/
|
*/
|
||||||
public String getHostName() throws Exception
|
public String getHostName() throws Exception
|
||||||
{
|
{
|
||||||
return m_hostName;
|
return m_hostName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method to get the session token.
|
* Method to get the session token.
|
||||||
*/
|
*/
|
||||||
public String getSessionToken() throws Exception
|
public String getSessionToken() throws Exception
|
||||||
{
|
{
|
||||||
return m_sessionToken;
|
return m_sessionToken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,65 +50,66 @@ package com.novell.casa.authtoksvc;
|
|||||||
* in the HTTP 1.1 Specification.
|
* in the HTTP 1.1 Specification.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GetAuthTokRespMsg {
|
public class GetAuthTokRespMsg
|
||||||
|
{
|
||||||
|
|
||||||
String m_msg;
|
String m_msg;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor for a msg that does not include the authentication token.
|
* Constructor for a msg that does not include the authentication token.
|
||||||
*/
|
*/
|
||||||
public GetAuthTokRespMsg (
|
public GetAuthTokRespMsg (
|
||||||
String statusDescription,
|
String statusDescription,
|
||||||
String statusCode) throws Exception
|
String statusCode) throws Exception
|
||||||
{
|
{
|
||||||
// Get a StringBuffer to help us with the construction of the message
|
// Get a StringBuffer to help us with the construction of the message
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
// Start building the message
|
// Start building the message
|
||||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
|
sb.append("<" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.statusElementName + ">"
|
sb.append("<" + ProtoDefs.statusElementName + ">"
|
||||||
+ "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
|
+ "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
|
||||||
+ statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
+ statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
||||||
sb.append("</" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
|
sb.append("</" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
|
||||||
|
|
||||||
// The message has now been built, save it.
|
// The message has now been built, save it.
|
||||||
m_msg = sb.toString();
|
m_msg = sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor for a msg that includes the authentication token.
|
* Constructor for a msg that includes the authentication token.
|
||||||
*/
|
*/
|
||||||
public GetAuthTokRespMsg (
|
public GetAuthTokRespMsg (
|
||||||
String statusDescription,
|
String statusDescription,
|
||||||
String statusCode,
|
String statusCode,
|
||||||
String authToken,
|
String authToken,
|
||||||
String authTokenLifetime) throws Exception
|
String authTokenLifetime) throws Exception
|
||||||
{
|
{
|
||||||
// Get a StringBuffer to help us with the construction of the message
|
// Get a StringBuffer to help us with the construction of the message
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
// Start building the message
|
// Start building the message
|
||||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
|
sb.append("<" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.statusElementName + ">"
|
sb.append("<" + ProtoDefs.statusElementName + ">"
|
||||||
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">"
|
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">"
|
||||||
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.authTokenElementName + ">"
|
sb.append("<" + ProtoDefs.authTokenElementName + ">"
|
||||||
+ "<" + ProtoDefs.lifetimeElementName + ">" + authTokenLifetime + "</" + ProtoDefs.lifetimeElementName + ">"
|
+ "<" + ProtoDefs.lifetimeElementName + ">" + authTokenLifetime + "</" + ProtoDefs.lifetimeElementName + ">"
|
||||||
+ authToken + "</" + ProtoDefs.authTokenElementName + ">" + "\r\n");
|
+ authToken + "</" + ProtoDefs.authTokenElementName + ">" + "\r\n");
|
||||||
sb.append("</" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
|
sb.append("</" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
|
||||||
|
|
||||||
// The message has now been built, save it.
|
// The message has now been built, save it.
|
||||||
m_msg = sb.toString();
|
m_msg = sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a string containing the GetAuthTokRespMsg.
|
* Returns a string containing the GetAuthTokRespMsg.
|
||||||
*/
|
*/
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return m_msg;
|
return m_msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,97 +39,97 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
* to a particular service.
|
* to a particular service.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GetAuthToken extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
public class GetAuthToken extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = -5792862615065914894L;
|
private static final long serialVersionUID = -5792862615065914894L;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public GetAuthToken()
|
public GetAuthToken()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* doGet() implementation.
|
* doGet() implementation.
|
||||||
*/
|
*/
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
{
|
{
|
||||||
// Just let doPost() handle it.
|
// Just let doPost() handle it.
|
||||||
doPost(request, response);
|
doPost(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* doPost() implementation.
|
* doPost() implementation.
|
||||||
*/
|
*/
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
{
|
{
|
||||||
// Get ready to send back a reply
|
// Get ready to send back a reply
|
||||||
response.setContentType("text/html");
|
response.setContentType("text/html");
|
||||||
PrintWriter out = response.getWriter();
|
PrintWriter out = response.getWriter();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Read and parse the GetAuthTokReqMsg sent from the client
|
// Read and parse the GetAuthTokReqMsg sent from the client
|
||||||
InputStream inStream = request.getInputStream();
|
InputStream inStream = request.getInputStream();
|
||||||
GetAuthTokReqMsg getAuthTokReqMsg = new GetAuthTokReqMsg(inStream);
|
GetAuthTokReqMsg getAuthTokReqMsg = new GetAuthTokReqMsg(inStream);
|
||||||
|
|
||||||
// Now create a session token (This validates the session token provided).
|
// Now create a session token (This validates the session token provided).
|
||||||
SessionToken sessionToken = new SessionToken(getAuthTokReqMsg.getSessionToken());
|
SessionToken sessionToken = new SessionToken(getAuthTokReqMsg.getSessionToken());
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Create the Authentication Token
|
// Create the Authentication Token
|
||||||
AuthToken authToken = new AuthToken(sessionToken.getIdentId(),
|
AuthToken authToken = new AuthToken(sessionToken.getIdentId(),
|
||||||
sessionToken.getRealm(),
|
sessionToken.getRealm(),
|
||||||
getAuthTokReqMsg.getServiceName(),
|
getAuthTokReqMsg.getServiceName(),
|
||||||
getAuthTokReqMsg.getHostName());
|
getAuthTokReqMsg.getHostName());
|
||||||
|
|
||||||
// Write out the response
|
// Write out the response
|
||||||
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpOkStatusMsg,
|
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpOkStatusMsg,
|
||||||
ProtoDefs.httpOkStatusCode,
|
ProtoDefs.httpOkStatusCode,
|
||||||
authToken.toString(),
|
authToken.toString(),
|
||||||
authToken.getLifetime());
|
authToken.getLifetime());
|
||||||
out.println(getAuthTokRespMsg.toString());
|
out.println(getAuthTokRespMsg.toString());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// tbd, use a custom exception and then set the status based
|
// tbd, use a custom exception and then set the status based
|
||||||
// on the type of exeption cached.
|
// on the type of exeption cached.
|
||||||
|
|
||||||
// Write out the response
|
// Write out the response
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||||
ProtoDefs.httpUnauthorizedStatusCode);
|
ProtoDefs.httpUnauthorizedStatusCode);
|
||||||
out.println(getAuthTokRespMsg.toString());
|
out.println(getAuthTokRespMsg.toString());
|
||||||
}
|
}
|
||||||
catch (Exception e2)
|
catch (Exception e2)
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthToken.doPost()- Exception trying to construct response msg: " + e2.toString());
|
System.err.println("GetAuthToken.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// tbd
|
// tbd
|
||||||
System.err.println("GetAuthToken.doPost()- Exception caught: " + e.toString());
|
System.err.println("GetAuthToken.doPost()- Exception caught: " + e.toString());
|
||||||
|
|
||||||
// Write out the response
|
// Write out the response
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
GetAuthTokRespMsg getAuthTokRespMsg = new GetAuthTokRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||||
ProtoDefs.httpServerErrorStatusCode);
|
ProtoDefs.httpServerErrorStatusCode);
|
||||||
out.println(getAuthTokRespMsg.toString());
|
out.println(getAuthTokRespMsg.toString());
|
||||||
}
|
}
|
||||||
catch (Exception e2)
|
catch (Exception e2)
|
||||||
{
|
{
|
||||||
System.err.println("GetAuthToken.doPost()- Exception trying to construct response msg: " + e2.toString());
|
System.err.println("GetAuthToken.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done sending out the reply
|
// Done sending out the reply
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -29,65 +29,66 @@ package com.novell.casa.authtoksvc;
|
|||||||
*
|
*
|
||||||
* This is the interface to Identity Token Providers.
|
* This is the interface to Identity Token Providers.
|
||||||
*/
|
*/
|
||||||
public interface IdentityToken {
|
public interface IdentityToken
|
||||||
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the token with parameters.
|
* Initialize the token with parameters.
|
||||||
*/
|
*/
|
||||||
void initialize (
|
void initialize (
|
||||||
String identityId,
|
String identityId,
|
||||||
String sourceName,
|
String sourceName,
|
||||||
String targetService,
|
String targetService,
|
||||||
String targetHost) throws Exception;
|
String targetHost) throws Exception;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the token object with encoded token string.
|
* Initialize the token object with encoded token string.
|
||||||
*/
|
*/
|
||||||
void initialize (String encodedToken) throws Exception;
|
void initialize (String encodedToken) throws Exception;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns encoded token string.
|
* Returns encoded token string.
|
||||||
*
|
*
|
||||||
* IMPORTANT: The token string can not contain the substring "]]>"
|
* IMPORTANT: The token string can not contain the substring "]]>"
|
||||||
* within it.
|
* within it.
|
||||||
*/
|
*/
|
||||||
String getEncodedToken() throws Exception;
|
String getEncodedToken() throws Exception;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a string containing the identity token provider type.
|
* Returns a string containing the identity token provider type.
|
||||||
*/
|
*/
|
||||||
String getProviderType() throws Exception;
|
String getProviderType() throws Exception;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a string containing the identity id.
|
* Returns a string containing the identity id.
|
||||||
*/
|
*/
|
||||||
String getIdentityId() throws Exception;
|
String getIdentityId() throws Exception;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a string containing the name associated with the
|
* Returns a string containing the name associated with the
|
||||||
* identity source.
|
* identity source.
|
||||||
*/
|
*/
|
||||||
String getSourceName() throws Exception;
|
String getSourceName() throws Exception;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a string containing the url associated with the
|
* Returns a string containing the url associated with the
|
||||||
* identity source.
|
* identity source.
|
||||||
*/
|
*/
|
||||||
String getSourceUrl() throws Exception;
|
String getSourceUrl() throws Exception;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a string containing the name of the targeted service.
|
* Returns a string containing the name of the targeted service.
|
||||||
*/
|
*/
|
||||||
String getTargetService() throws Exception;
|
String getTargetService() throws Exception;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a string containig the name of the host where the
|
* Returns a string containig the name of the host where the
|
||||||
* targeted service resides.
|
* targeted service resides.
|
||||||
*/
|
*/
|
||||||
String getTargetHost() throws Exception;
|
String getTargetHost() throws Exception;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the attributes of the identity.
|
* Returns the attributes of the identity.
|
||||||
*/
|
*/
|
||||||
javax.naming.directory.Attributes getAttributes() throws Exception;
|
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.
|
* This class processes authentication requests utilizing a kerberos-V token.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Krb5Authenticate extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
public class Krb5Authenticate extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 7247746330553668339L;
|
private static final long serialVersionUID = 7247746330553668339L;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* tbd - This needs to be somewhere else so that the same parameter
|
* tbd - This needs to be somewhere else so that the same parameter
|
||||||
* can be accessed by other authentication mechanisms.
|
* can be accessed by other authentication mechanisms.
|
||||||
*
|
*
|
||||||
* Configurable operating parameters
|
* Configurable operating parameters
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public String sessionTokenLifetime = "360";
|
public String sessionTokenLifetime = "360";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GSS Long Lived variables
|
* GSS Long Lived variables
|
||||||
*/
|
*/
|
||||||
protected GSSManager m_manager;
|
protected GSSManager m_manager;
|
||||||
protected Oid m_krb5;
|
protected Oid m_krb5;
|
||||||
protected GSSName m_svcName;
|
protected GSSName m_svcName;
|
||||||
protected GSSCredential m_credential;
|
protected GSSCredential m_credential;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Krb5 Token Class.
|
* Krb5 Token Class.
|
||||||
*/
|
*/
|
||||||
private class Krb5Token
|
private class Krb5Token
|
||||||
{
|
{
|
||||||
private String m_principalName = "";
|
private String m_principalName = "";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The format of the Krb5 token is as follows:
|
* The format of the Krb5 token is as follows:
|
||||||
*
|
*
|
||||||
* Base64.encode(GSS-API Token data));
|
* Base64.encode(GSS-API Token data));
|
||||||
*/
|
*/
|
||||||
public Krb5Token(String encodedToken, Krb5Authenticate parent) throws Exception
|
public Krb5Token(String encodedToken, Krb5Authenticate parent) throws Exception
|
||||||
{
|
{
|
||||||
// Decode the token
|
// Decode the token
|
||||||
char[] tokenChars = new char[encodedToken.length()];
|
char[] tokenChars = new char[encodedToken.length()];
|
||||||
encodedToken.getChars(0, tokenChars.length, tokenChars, 0);
|
encodedToken.getChars(0, tokenChars.length, tokenChars, 0);
|
||||||
byte[] tokenBytes = Base64Coder.decode(tokenChars);
|
byte[] tokenBytes = Base64Coder.decode(tokenChars);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Create a context and validate the token
|
// Create a context and validate the token
|
||||||
GSSContext context = parent.m_manager.createContext(parent.m_credential);
|
GSSContext context = parent.m_manager.createContext(parent.m_credential);
|
||||||
System.err.println("tokenLength = " + tokenBytes.length);
|
System.err.println("tokenLength = " + tokenBytes.length);
|
||||||
context.acceptSecContext(tokenBytes, 0, tokenBytes.length);
|
context.acceptSecContext(tokenBytes, 0, tokenBytes.length);
|
||||||
|
|
||||||
// Save the principal name of the authenticated entity
|
// Save the principal name of the authenticated entity
|
||||||
GSSName principalName = context.getSrcName();
|
GSSName principalName = context.getSrcName();
|
||||||
m_principalName = principalName.toString();
|
m_principalName = principalName.toString();
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
context.dispose();
|
context.dispose();
|
||||||
}
|
}
|
||||||
catch(GSSException e)
|
catch (GSSException e)
|
||||||
{
|
{
|
||||||
System.err.println("Krb5Authenticate Krb5Token()- GSS Exception caught: " + e.getLocalizedMessage());
|
System.err.println("Krb5Authenticate Krb5Token()- GSS Exception caught: " + e.getLocalizedMessage());
|
||||||
throw new Exception("Authentication Failure");
|
throw new Exception("Authentication Failure");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the name of the authenticated principal
|
* Returns the name of the authenticated principal
|
||||||
*/
|
*/
|
||||||
public String getPrincipalName()
|
public String getPrincipalName()
|
||||||
{
|
{
|
||||||
return m_principalName;
|
return m_principalName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public Krb5Authenticate() throws Exception
|
public Krb5Authenticate() throws Exception
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Initalize our GSS variables
|
// Initalize our GSS variables
|
||||||
//
|
//
|
||||||
// Get an instance of the default GSSManager
|
// Get an instance of the default GSSManager
|
||||||
m_manager = GSSManager.getInstance();
|
m_manager = GSSManager.getInstance();
|
||||||
|
|
||||||
// Create an OID specifying the Krb5 mechanism
|
// Create an OID specifying the Krb5 mechanism
|
||||||
m_krb5 = new Oid("1.2.840.113554.1.2.2");
|
m_krb5 = new Oid("1.2.840.113554.1.2.2");
|
||||||
|
|
||||||
// Create our host based service name
|
// Create our host based service name
|
||||||
// tbd - obtain the service name from configuration
|
// tbd - obtain the service name from configuration
|
||||||
//GSSName svcName = manager.createName(ourServiceName, GSSName.NT_HOSTBASED_SERVICE, krb5);
|
//GSSName svcName = manager.createName(ourServiceName, GSSName.NT_HOSTBASED_SERVICE, krb5);
|
||||||
m_svcName = m_manager.createName("host@jcstation.dnsdhcp.provo.novell.com",
|
m_svcName = m_manager.createName("host@jcstation.dnsdhcp.provo.novell.com",
|
||||||
GSSName.NT_HOSTBASED_SERVICE,
|
GSSName.NT_HOSTBASED_SERVICE,
|
||||||
m_krb5);
|
m_krb5);
|
||||||
|
|
||||||
// Now acquire our credentials
|
// Now acquire our credentials
|
||||||
m_credential = m_manager.createCredential(m_svcName,
|
m_credential = m_manager.createCredential(m_svcName,
|
||||||
GSSCredential.INDEFINITE_LIFETIME,
|
GSSCredential.INDEFINITE_LIFETIME,
|
||||||
m_krb5,
|
m_krb5,
|
||||||
GSSCredential.ACCEPT_ONLY);
|
GSSCredential.ACCEPT_ONLY);
|
||||||
}
|
}
|
||||||
catch(GSSException e)
|
catch (GSSException e)
|
||||||
{
|
{
|
||||||
System.err.println("Krb5Authenticate()- GSS Exception caught: " + e.getLocalizedMessage());
|
System.err.println("Krb5Authenticate()- GSS Exception caught: " + e.getLocalizedMessage());
|
||||||
throw new Exception("Failed to instantiate needed GSS objects");
|
throw new Exception("Failed to instantiate needed GSS objects");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* doGet() implementation.
|
* doGet() implementation.
|
||||||
*/
|
*/
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
{
|
{
|
||||||
doPost(request, response);
|
doPost(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* doPost() implementation.
|
* doPost() implementation.
|
||||||
*/
|
*/
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
{
|
{
|
||||||
// Get ready to send back a reply
|
// Get ready to send back a reply
|
||||||
response.setContentType("text/html");
|
response.setContentType("text/html");
|
||||||
PrintWriter out = response.getWriter();
|
PrintWriter out = response.getWriter();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Read and parse the AuthReqMsg sent from the client
|
// Read and parse the AuthReqMsg sent from the client
|
||||||
InputStream inStream = request.getInputStream();
|
InputStream inStream = request.getInputStream();
|
||||||
AuthReqMsg authReqMsg = new AuthReqMsg(inStream);
|
AuthReqMsg authReqMsg = new AuthReqMsg(inStream);
|
||||||
|
|
||||||
// Now parse the PW Token
|
// Now parse the PW Token
|
||||||
Krb5Token krb5Token = new Krb5Token(authReqMsg.getAuthMechToken(), this);
|
Krb5Token krb5Token = new Krb5Token(authReqMsg.getAuthMechToken(), this);
|
||||||
|
|
||||||
// Open a directory context and use it to identify the users
|
// Open a directory context and use it to identify the users
|
||||||
// associated with the specified surname.
|
// associated with the specified surname.
|
||||||
Hashtable env = new Hashtable();
|
Hashtable env = new Hashtable();
|
||||||
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.bandit.ia.IAInitialCtxFactory");
|
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_CONFIG_LOCATION, "/home/jluciani/workspace/IdentityAbstraction/realms.xml");
|
||||||
// env.put(IAContext.IA_REALM_SELECTOR, "");
|
// env.put(IAContext.IA_REALM_SELECTOR, "");
|
||||||
|
|
||||||
DirContext ctx = new InitialDirContext(env);
|
DirContext ctx = new InitialDirContext(env);
|
||||||
|
|
||||||
// Now search for a user with a matching kerberos principal name
|
// Now search for a user with a matching kerberos principal name
|
||||||
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
|
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
|
||||||
matchAttrs.put(new BasicAttribute("krbPrincipalName", krb5Token.getPrincipalName()));
|
matchAttrs.put(new BasicAttribute("krbPrincipalName", krb5Token.getPrincipalName()));
|
||||||
|
|
||||||
NamingEnumeration answer = ctx.search("o=novell", matchAttrs);
|
NamingEnumeration answer = ctx.search("o=novell", matchAttrs);
|
||||||
|
|
||||||
// Proceed based on the result of the search
|
// Proceed based on the result of the search
|
||||||
String identId = null;
|
String identId = null;
|
||||||
if (answer.hasMore())
|
if (answer.hasMore())
|
||||||
{
|
{
|
||||||
// The search succeeded, set the identity id.
|
// The search succeeded, set the identity id.
|
||||||
SearchResult sr = (SearchResult)answer.next();
|
SearchResult sr = (SearchResult)answer.next();
|
||||||
identId = sr.getName() + ",o=novell";
|
identId = sr.getName() + ",o=novell";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create response based on the identity resolution results
|
// Create response based on the identity resolution results
|
||||||
if (identId != null)
|
if (identId != null)
|
||||||
{
|
{
|
||||||
// An identity was resolved, get a SessionToken for it.
|
// An identity was resolved, get a SessionToken for it.
|
||||||
SessionToken sessionToken = new SessionToken(identId, authReqMsg.getRealm(), sessionTokenLifetime);
|
SessionToken sessionToken = new SessionToken(identId, authReqMsg.getRealm(), sessionTokenLifetime);
|
||||||
|
|
||||||
// Write out the response
|
// Write out the response
|
||||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpOkStatusMsg,
|
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpOkStatusMsg,
|
||||||
ProtoDefs.httpOkStatusCode,
|
ProtoDefs.httpOkStatusCode,
|
||||||
sessionToken.toString(),
|
sessionToken.toString(),
|
||||||
sessionTokenLifetime);
|
sessionTokenLifetime);
|
||||||
out.println(authRespMsg.toString());
|
out.println(authRespMsg.toString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Write out the response
|
// Write out the response
|
||||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpUnauthorizedStatusMsg,
|
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpUnauthorizedStatusMsg,
|
||||||
ProtoDefs.httpUnauthorizedStatusCode);
|
ProtoDefs.httpUnauthorizedStatusCode);
|
||||||
out.println(authRespMsg.toString());
|
out.println(authRespMsg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (NamingException e)
|
catch (NamingException e)
|
||||||
{
|
{
|
||||||
// tbd
|
// tbd
|
||||||
// Log the error
|
// Log the error
|
||||||
System.err.println("Krb5Authenticate.doPost()- Exception caught: " + e.getExplanation());
|
System.err.println("Krb5Authenticate.doPost()- Exception caught: " + e.getExplanation());
|
||||||
|
|
||||||
// Write out the response
|
// Write out the response
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||||
ProtoDefs.httpServerErrorStatusCode);
|
ProtoDefs.httpServerErrorStatusCode);
|
||||||
out.println(authRespMsg.toString());
|
out.println(authRespMsg.toString());
|
||||||
}
|
}
|
||||||
catch (Exception e2)
|
catch (Exception e2)
|
||||||
{
|
{
|
||||||
System.err.println("Krb5Authenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
System.err.println("Krb5Authenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// tbd
|
// tbd
|
||||||
System.err.println("Krb5Authenticate.doPost()- Exception: " + e.toString());
|
System.err.println("Krb5Authenticate.doPost()- Exception: " + e.toString());
|
||||||
|
|
||||||
// Write out the response
|
// Write out the response
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||||
ProtoDefs.httpServerErrorStatusCode);
|
ProtoDefs.httpServerErrorStatusCode);
|
||||||
out.println(authRespMsg.toString());
|
out.println(authRespMsg.toString());
|
||||||
}
|
}
|
||||||
catch (Exception e2)
|
catch (Exception e2)
|
||||||
{
|
{
|
||||||
System.err.println("Krb5Authenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
System.err.println("Krb5Authenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done sending out the reply
|
// Done sending out the reply
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,53 +31,54 @@ package com.novell.casa.authtoksvc;
|
|||||||
* protocol.
|
* protocol.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ProtoDefs {
|
public class ProtoDefs
|
||||||
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XML Declaration used in the Casa Client/Server protocol
|
* XML Declaration used in the Casa Client/Server protocol
|
||||||
*/
|
*/
|
||||||
public final static String xmlDeclaration = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
|
public final static String xmlDeclaration = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XML Element Name Constants for the documents exchanged between the
|
* XML Element Name Constants for the documents exchanged between the
|
||||||
* Casa Client and the Casa Server.
|
* Casa Client and the Casa Server.
|
||||||
*/
|
*/
|
||||||
public final static String authRequestElementName = "auth_req";
|
public final static String authRequestElementName = "auth_req";
|
||||||
public final static String authResponseElementName = "auth_resp";
|
public final static String authResponseElementName = "auth_resp";
|
||||||
public final static String getAuthPolicyRequestElementName = "get_auth_policy_req";
|
public final static String getAuthPolicyRequestElementName = "get_auth_policy_req";
|
||||||
public final static String getAuthPolicyResponseElementName = "get_auth_policy_resp";
|
public final static String getAuthPolicyResponseElementName = "get_auth_policy_resp";
|
||||||
public final static String getAuthTokRequestElementName = "get_auth_tok_req";
|
public final static String getAuthTokRequestElementName = "get_auth_tok_req";
|
||||||
public final static String getAuthTokResponseElementName = "get_auth_tok_resp";
|
public final static String getAuthTokResponseElementName = "get_auth_tok_resp";
|
||||||
public final static String authMechTokenElementName = "auth_mech_token";
|
public final static String authMechTokenElementName = "auth_mech_token";
|
||||||
public final static String statusElementName = "status";
|
public final static String statusElementName = "status";
|
||||||
public final static String sessionTokenElementName = "session_token";
|
public final static String sessionTokenElementName = "session_token";
|
||||||
public final static String authTokenElementName = "auth_token";
|
public final static String authTokenElementName = "auth_token";
|
||||||
public final static String authPolicyElementName = "auth_policy";
|
public final static String authPolicyElementName = "auth_policy";
|
||||||
public final static String identTokenElementName = "ident_token";
|
public final static String identTokenElementName = "ident_token";
|
||||||
public final static String lifetimeElementName = "lifetime";
|
public final static String lifetimeElementName = "lifetime";
|
||||||
public final static String signatureElementName = "signature";
|
public final static String signatureElementName = "signature";
|
||||||
public final static String typeElementName = "type";
|
public final static String typeElementName = "type";
|
||||||
public final static String descriptionElementName = "description";
|
public final static String descriptionElementName = "description";
|
||||||
public final static String serviceElementName = "service";
|
public final static String serviceElementName = "service";
|
||||||
public final static String hostElementName = "host";
|
public final static String hostElementName = "host";
|
||||||
public final static String identIdElementName = "ident_id";
|
public final static String identIdElementName = "ident_id";
|
||||||
public final static String realmElementName = "realm";
|
public final static String realmElementName = "realm";
|
||||||
public final static String authSourceElementName = "auth_source";
|
public final static String authSourceElementName = "auth_source";
|
||||||
public final static String mechanismElementName = "mechanism";
|
public final static String mechanismElementName = "mechanism";
|
||||||
public final static String mechanismInfoElementName = "mechanism_info";
|
public final static String mechanismInfoElementName = "mechanism_info";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Configurable operating parameters
|
* Configurable operating parameters
|
||||||
*/
|
*/
|
||||||
public String sessionTokenLifetime = "360";
|
public String sessionTokenLifetime = "360";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* HTTP Status Codes and Messages
|
* HTTP Status Codes and Messages
|
||||||
*/
|
*/
|
||||||
public final static String httpOkStatusCode = "200";
|
public final static String httpOkStatusCode = "200";
|
||||||
public final static String httpOkStatusMsg = "OK";
|
public final static String httpOkStatusMsg = "OK";
|
||||||
public final static String httpUnauthorizedStatusCode = "401";
|
public final static String httpUnauthorizedStatusCode = "401";
|
||||||
public final static String httpUnauthorizedStatusMsg = "Unauthorized";
|
public final static String httpUnauthorizedStatusMsg = "Unauthorized";
|
||||||
public final static String httpServerErrorStatusCode = "500";
|
public final static String httpServerErrorStatusCode = "500";
|
||||||
public final static String httpServerErrorStatusMsg = "Internal Server Error";
|
public final static String httpServerErrorStatusMsg = "Internal Server Error";
|
||||||
}
|
}
|
||||||
|
@ -55,128 +55,128 @@ import org.bandit.ia.IAContext;
|
|||||||
* password materials.
|
* password materials.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class PwdAuthenticate extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
public class PwdAuthenticate extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final long serialVersionUID = 3710685782114934264L;
|
private static final long serialVersionUID = 3710685782114934264L;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* tbd - This needs to be somewhere else so that the same parameter
|
* tbd - This needs to be somewhere else so that the same parameter
|
||||||
* can be accessed by other authentication mechanisms.
|
* can be accessed by other authentication mechanisms.
|
||||||
*
|
*
|
||||||
* Configurable operating parameters
|
* Configurable operating parameters
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public String sessionTokenLifetime = "360";
|
public String sessionTokenLifetime = "360";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Password Token Class.
|
* Password Token Class.
|
||||||
*/
|
*/
|
||||||
private class PwToken
|
private class PwToken
|
||||||
{
|
{
|
||||||
private String m_username = "";
|
private String m_username = "";
|
||||||
private String m_password = "";
|
private String m_password = "";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The format of the Pw token is as follows:
|
* The format of the Pw token is as follows:
|
||||||
*
|
*
|
||||||
* Base64.encode(new String("username\r\n" + "password\r\n"));
|
* Base64.encode(new String("username\r\n" + "password\r\n"));
|
||||||
*/
|
*/
|
||||||
public PwToken(String encodedToken) throws IOException
|
public PwToken(String encodedToken) throws IOException
|
||||||
{
|
{
|
||||||
// Decode the token
|
// Decode the token
|
||||||
String token = Base64Coder.decode(encodedToken);
|
String token = Base64Coder.decode(encodedToken);
|
||||||
|
|
||||||
BufferedReader tokenReader = new BufferedReader(new StringReader(token));
|
BufferedReader tokenReader = new BufferedReader(new StringReader(token));
|
||||||
|
|
||||||
// The second line contains the "username"
|
// The second line contains the "username"
|
||||||
m_username = tokenReader.readLine();
|
m_username = tokenReader.readLine();
|
||||||
|
|
||||||
// The third line contains the "password"
|
// The third line contains the "password"
|
||||||
m_password = tokenReader.readLine();
|
m_password = tokenReader.readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the username
|
* Returns the username
|
||||||
*/
|
*/
|
||||||
public String getUsername()
|
public String getUsername()
|
||||||
{
|
{
|
||||||
return m_username;
|
return m_username;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the password
|
* Returns the password
|
||||||
*/
|
*/
|
||||||
public String getPassword()
|
public String getPassword()
|
||||||
{
|
{
|
||||||
return m_password;
|
return m_password;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public PwdAuthenticate()
|
public PwdAuthenticate()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* doGet() implementation.
|
* doGet() implementation.
|
||||||
*/
|
*/
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
{
|
{
|
||||||
// Just let doPost() handle it.
|
// Just let doPost() handle it.
|
||||||
doPost(request, response);
|
doPost(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* doPost() implementation.
|
* doPost() implementation.
|
||||||
*/
|
*/
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
{
|
{
|
||||||
// Get ready to send back a reply
|
// Get ready to send back a reply
|
||||||
response.setContentType("text/html");
|
response.setContentType("text/html");
|
||||||
PrintWriter out = response.getWriter();
|
PrintWriter out = response.getWriter();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Read and parse the AuthReqMsg sent from the client
|
// Read and parse the AuthReqMsg sent from the client
|
||||||
InputStream inStream = request.getInputStream();
|
InputStream inStream = request.getInputStream();
|
||||||
AuthReqMsg authReqMsg = new AuthReqMsg(inStream);
|
AuthReqMsg authReqMsg = new AuthReqMsg(inStream);
|
||||||
|
|
||||||
// Now parse the PW Token
|
// Now parse the PW Token
|
||||||
PwToken pwToken = new PwToken(authReqMsg.getAuthMechToken());
|
PwToken pwToken = new PwToken(authReqMsg.getAuthMechToken());
|
||||||
|
|
||||||
// Open a directory context and use it to identify the users
|
// Open a directory context and use it to identify the users
|
||||||
// associated with the specified surname.
|
// associated with the specified surname.
|
||||||
Hashtable env = new Hashtable();
|
Hashtable env = new Hashtable();
|
||||||
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.bandit.ia.IAInitialCtxFactory");
|
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_CONFIG_LOCATION, "/home/jluciani/workspace/IdentityAbstraction/realms.xml");
|
||||||
// env.put(IAContext.IA_REALM_SELECTOR, "");
|
// env.put(IAContext.IA_REALM_SELECTOR, "");
|
||||||
|
|
||||||
DirContext ctx = new InitialDirContext(env);
|
DirContext ctx = new InitialDirContext(env);
|
||||||
|
|
||||||
// Now search for a user with a matching surname
|
// Now search for a user with a matching surname
|
||||||
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
|
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
|
||||||
matchAttrs.put(new BasicAttribute("cn", pwToken.getUsername()));
|
matchAttrs.put(new BasicAttribute("cn", pwToken.getUsername()));
|
||||||
|
|
||||||
NamingEnumeration answer = ctx.search("o=novell", matchAttrs);
|
NamingEnumeration answer = ctx.search("o=novell", matchAttrs);
|
||||||
|
|
||||||
// Enumerate through the users returned checking the password
|
// Enumerate through the users returned checking the password
|
||||||
String identId = null;
|
String identId = null;
|
||||||
while (answer.hasMore())
|
while (answer.hasMore())
|
||||||
{
|
{
|
||||||
SearchResult sr = (SearchResult)answer.next();
|
SearchResult sr = (SearchResult)answer.next();
|
||||||
|
|
||||||
System.err.println(sr.getName());
|
System.err.println(sr.getName());
|
||||||
|
|
||||||
// Open a directory context for the user as a way of verifying its password
|
// Open a directory context for the user as a way of verifying its password
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Hashtable env2 = new Hashtable();
|
Hashtable env2 = new Hashtable();
|
||||||
env2.put(Context.INITIAL_CONTEXT_FACTORY, "org.bandit.ia.IAInitialCtxFactory");
|
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_CONFIG_LOCATION, "/home/jluciani/workspace/IdentityAbstraction/realms.xml");
|
||||||
// env2.put(IAContext.IA_REALM_SELECTOR, "");
|
// env2.put(IAContext.IA_REALM_SELECTOR, "");
|
||||||
|
|
||||||
// env2.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
|
// env2.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
|
||||||
@ -185,78 +185,78 @@ import org.bandit.ia.IAContext;
|
|||||||
// env2.put(Context.SECURITY_PRINCIPAL, sr.getName() + ",o=novell");
|
// env2.put(Context.SECURITY_PRINCIPAL, sr.getName() + ",o=novell");
|
||||||
// env2.put(Context.SECURITY_CREDENTIALS, pwToken.getPassword());
|
// env2.put(Context.SECURITY_CREDENTIALS, pwToken.getPassword());
|
||||||
|
|
||||||
if ((new InitialDirContext(env2)) != null)
|
if ((new InitialDirContext(env2)) != null)
|
||||||
{
|
{
|
||||||
// The password must be valid, set the identity Id.
|
// The password must be valid, set the identity Id.
|
||||||
identId = sr.getName() + ",o=novell";
|
identId = sr.getName() + ",o=novell";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (NamingException e)
|
catch (NamingException e)
|
||||||
{
|
{
|
||||||
System.err.println("PwdAuthenticate.doPost()- Naming Exception: " + e.getExplanation());
|
System.err.println("PwdAuthenticate.doPost()- Naming Exception: " + e.getExplanation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create response based on the identity resolution results
|
// Create response based on the identity resolution results
|
||||||
if (identId != null)
|
if (identId != null)
|
||||||
{
|
{
|
||||||
// An identity was resolved, get a SessionToken for it.
|
// An identity was resolved, get a SessionToken for it.
|
||||||
SessionToken sessionToken = new SessionToken(identId, authReqMsg.getRealm(), sessionTokenLifetime);
|
SessionToken sessionToken = new SessionToken(identId, authReqMsg.getRealm(), sessionTokenLifetime);
|
||||||
|
|
||||||
// Write out the response
|
// Write out the response
|
||||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpOkStatusMsg,
|
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpOkStatusMsg,
|
||||||
ProtoDefs.httpOkStatusCode,
|
ProtoDefs.httpOkStatusCode,
|
||||||
sessionToken.toString(),
|
sessionToken.toString(),
|
||||||
sessionTokenLifetime);
|
sessionTokenLifetime);
|
||||||
out.println(authRespMsg.toString());
|
out.println(authRespMsg.toString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Write out the response
|
// Write out the response
|
||||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpUnauthorizedStatusMsg,
|
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpUnauthorizedStatusMsg,
|
||||||
ProtoDefs.httpUnauthorizedStatusCode);
|
ProtoDefs.httpUnauthorizedStatusCode);
|
||||||
out.println(authRespMsg.toString());
|
out.println(authRespMsg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (NamingException e)
|
catch (NamingException e)
|
||||||
{
|
{
|
||||||
// tbd
|
// tbd
|
||||||
// Log the error
|
// Log the error
|
||||||
System.err.println("PwdAuthenticate.doPost()- Naming Exception on Proxy User: " + e.getExplanation());
|
System.err.println("PwdAuthenticate.doPost()- Naming Exception on Proxy User: " + e.getExplanation());
|
||||||
|
|
||||||
// Write out the response
|
// Write out the response
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||||
ProtoDefs.httpServerErrorStatusCode);
|
ProtoDefs.httpServerErrorStatusCode);
|
||||||
out.println(authRespMsg.toString());
|
out.println(authRespMsg.toString());
|
||||||
}
|
}
|
||||||
catch (Exception e2)
|
catch (Exception e2)
|
||||||
{
|
{
|
||||||
System.err.println("PwdAuthenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
System.err.println("PwdAuthenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// tbd
|
// tbd
|
||||||
System.err.println("PwdAuthenticate.doPost()- Naming Exception on Proxy User: " + e.toString());
|
System.err.println("PwdAuthenticate.doPost()- Naming Exception on Proxy User: " + e.toString());
|
||||||
|
|
||||||
// Write out the response
|
// Write out the response
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
AuthRespMsg authRespMsg = new AuthRespMsg(ProtoDefs.httpServerErrorStatusMsg,
|
||||||
ProtoDefs.httpServerErrorStatusCode);
|
ProtoDefs.httpServerErrorStatusCode);
|
||||||
out.println(authRespMsg.toString());
|
out.println(authRespMsg.toString());
|
||||||
}
|
}
|
||||||
catch (Exception e2)
|
catch (Exception e2)
|
||||||
{
|
{
|
||||||
System.err.println("PwdAuthenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
System.err.println("PwdAuthenticate.doPost()- Exception trying to construct response msg: " + e2.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done sending out the reply
|
// Done sending out the reply
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -48,365 +48,369 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
|||||||
* </session_token>
|
* </session_token>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SessionToken {
|
public class SessionToken
|
||||||
|
{
|
||||||
|
|
||||||
private String m_id;
|
private String m_id;
|
||||||
private String m_realm;
|
private String m_realm;
|
||||||
private String m_lifetime;
|
private String m_lifetime;
|
||||||
private String m_signature;
|
private String m_signature;
|
||||||
private String m_token;
|
private String m_token;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class for handling parsing events.
|
* Class for handling parsing events.
|
||||||
*/
|
*/
|
||||||
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
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_START = 0;
|
||||||
private final static int AWAITING_ROOT_ELEMENT_END = 1;
|
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_START = 2;
|
||||||
private final static int AWAITING_SIGNATURE_ELEMENT_END = 3;
|
private final static int AWAITING_SIGNATURE_ELEMENT_END = 3;
|
||||||
private final static int AWAITING_SIGNATURE_DATA = 4;
|
private final static int AWAITING_SIGNATURE_DATA = 4;
|
||||||
private final static int AWAITING_LIFETIME_ELEMENT_START = 5;
|
private final static int AWAITING_LIFETIME_ELEMENT_START = 5;
|
||||||
private final static int AWAITING_LIFETIME_ELEMENT_END = 6;
|
private final static int AWAITING_LIFETIME_ELEMENT_END = 6;
|
||||||
private final static int AWAITING_LIFETIME_DATA = 7;
|
private final static int AWAITING_LIFETIME_DATA = 7;
|
||||||
private final static int AWAITING_REALM_ELEMENT_START = 8;
|
private final static int AWAITING_REALM_ELEMENT_START = 8;
|
||||||
private final static int AWAITING_REALM_ELEMENT_END = 9;
|
private final static int AWAITING_REALM_ELEMENT_END = 9;
|
||||||
private final static int AWAITING_REALM_DATA = 10;
|
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_START = 11;
|
||||||
private final static int AWAITING_IDENT_ID_ELEMENT_END = 12;
|
private final static int AWAITING_IDENT_ID_ELEMENT_END = 12;
|
||||||
private final static int AWAITING_IDENT_ID_DATA = 13;
|
private final static int AWAITING_IDENT_ID_DATA = 13;
|
||||||
private final static int DONE_PARSING = 14;
|
private final static int DONE_PARSING = 14;
|
||||||
|
|
||||||
private SessionToken m_SessionToken;
|
private SessionToken m_SessionToken;
|
||||||
private int m_state;
|
private int m_state;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public SAXHandler (SessionToken SessionToken)
|
public SAXHandler (SessionToken SessionToken)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
// Initialize our members
|
// Initialize our members
|
||||||
m_SessionToken = SessionToken;
|
m_SessionToken = SessionToken;
|
||||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* endDocument() implementation.
|
* endDocument() implementation.
|
||||||
*/
|
*/
|
||||||
public void endDocument () throws SAXException
|
public void endDocument () throws SAXException
|
||||||
{
|
{
|
||||||
// Verify that we obtained all of the required elements
|
// Verify that we obtained all of the required elements
|
||||||
if (m_state != DONE_PARSING)
|
if (m_state != DONE_PARSING)
|
||||||
{
|
{
|
||||||
System.err.println("SessionToken SAXHandler.endDocument()- Missing element");
|
System.err.println("SessionToken SAXHandler.endDocument()- Missing element");
|
||||||
throw new SAXException("Missing element");
|
throw new SAXException("Missing element");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* startElement() implementation.
|
* startElement() implementation.
|
||||||
*/
|
*/
|
||||||
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_ROOT_ELEMENT_START:
|
case AWAITING_ROOT_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.sessionTokenElementName.equals(qName))
|
if (ProtoDefs.sessionTokenElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SIGNATURE_ELEMENT_START;
|
m_state = AWAITING_SIGNATURE_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
|
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_SIGNATURE_ELEMENT_START:
|
case AWAITING_SIGNATURE_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.signatureElementName.equals(qName))
|
if (ProtoDefs.signatureElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SIGNATURE_DATA;
|
m_state = AWAITING_SIGNATURE_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
|
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_LIFETIME_ELEMENT_START:
|
case AWAITING_LIFETIME_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.lifetimeElementName.equals(qName))
|
if (ProtoDefs.lifetimeElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_LIFETIME_DATA;
|
m_state = AWAITING_LIFETIME_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
|
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_REALM_ELEMENT_START:
|
case AWAITING_REALM_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.realmElementName.equals(qName))
|
if (ProtoDefs.realmElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_REALM_DATA;
|
m_state = AWAITING_REALM_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
|
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_IDENT_ID_ELEMENT_START:
|
case AWAITING_IDENT_ID_ELEMENT_START:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.identIdElementName.equals(qName))
|
if (ProtoDefs.identIdElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_IDENT_ID_DATA;
|
m_state = AWAITING_IDENT_ID_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
|
System.err.println("SessionToken SAXHandler.startElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
System.err.println("SessionToken SAXHandler.startElement()- State error");
|
System.err.println("SessionToken SAXHandler.startElement()- State error");
|
||||||
throw new SAXException("State error");
|
throw new SAXException("State error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* endElement() immplementation.
|
* endElement() immplementation.
|
||||||
*/
|
*/
|
||||||
public void endElement (String uri, String name, String qName) throws SAXException
|
public void endElement (String uri, String name, String qName) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_ROOT_ELEMENT_END:
|
case AWAITING_ROOT_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.sessionTokenElementName.equals(qName))
|
if (ProtoDefs.sessionTokenElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = DONE_PARSING;
|
m_state = DONE_PARSING;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
|
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_SIGNATURE_ELEMENT_END:
|
case AWAITING_SIGNATURE_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.signatureElementName.equals(qName))
|
if (ProtoDefs.signatureElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_LIFETIME_ELEMENT_START;
|
m_state = AWAITING_LIFETIME_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
|
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_LIFETIME_ELEMENT_END:
|
case AWAITING_LIFETIME_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.lifetimeElementName.equals(qName))
|
if (ProtoDefs.lifetimeElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_REALM_ELEMENT_START;
|
m_state = AWAITING_REALM_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
|
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_REALM_ELEMENT_END:
|
case AWAITING_REALM_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.realmElementName.equals(qName))
|
if (ProtoDefs.realmElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_IDENT_ID_ELEMENT_START;
|
m_state = AWAITING_IDENT_ID_ELEMENT_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
|
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_IDENT_ID_ELEMENT_END:
|
case AWAITING_IDENT_ID_ELEMENT_END:
|
||||||
// Verify that we are processing the expected tag
|
// Verify that we are processing the expected tag
|
||||||
if (ProtoDefs.identIdElementName.equals(qName))
|
if (ProtoDefs.identIdElementName.equals(qName))
|
||||||
{
|
{
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_ROOT_ELEMENT_END;
|
m_state = AWAITING_ROOT_ELEMENT_END;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
|
System.err.println("SessionToken SAXHandler.endElement()- Un-expected element");
|
||||||
throw new SAXException("Un-expected element");
|
throw new SAXException("Un-expected element");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
System.err.println("SessionToken SAXHandler.startElement()- State error");
|
System.err.println("SessionToken SAXHandler.startElement()- State error");
|
||||||
throw new SAXException("State error");
|
throw new SAXException("State error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* character() implementation.
|
* character() implementation.
|
||||||
*/
|
*/
|
||||||
public void characters (char ch[], int start, int length) throws SAXException
|
public void characters (char ch[], int start, int length) throws SAXException
|
||||||
{
|
{
|
||||||
// Proceed based on our state
|
// Proceed based on our state
|
||||||
switch (m_state) {
|
switch (m_state)
|
||||||
|
{
|
||||||
|
|
||||||
case AWAITING_SIGNATURE_DATA:
|
case AWAITING_SIGNATURE_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_SessionToken.m_signature = new String(ch, start, length);
|
m_SessionToken.m_signature = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_SIGNATURE_ELEMENT_END;
|
m_state = AWAITING_SIGNATURE_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_LIFETIME_DATA:
|
case AWAITING_LIFETIME_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_SessionToken.m_lifetime = new String(ch, start, length);
|
m_SessionToken.m_lifetime = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_LIFETIME_ELEMENT_END;
|
m_state = AWAITING_LIFETIME_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_REALM_DATA:
|
case AWAITING_REALM_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_SessionToken.m_realm = new String(ch, start, length);
|
m_SessionToken.m_realm = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_REALM_ELEMENT_END;
|
m_state = AWAITING_REALM_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_IDENT_ID_DATA:
|
case AWAITING_IDENT_ID_DATA:
|
||||||
// Consume the data
|
// Consume the data
|
||||||
m_SessionToken.m_id = new String(ch, start, length);
|
m_SessionToken.m_id = new String(ch, start, length);
|
||||||
|
|
||||||
// Advance to the next state
|
// Advance to the next state
|
||||||
m_state = AWAITING_IDENT_ID_ELEMENT_END;
|
m_state = AWAITING_IDENT_ID_ELEMENT_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Do nothing
|
// Do nothing
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public SessionToken(String id, String realm, String lifetime) throws Exception
|
public SessionToken(String id, String realm, String lifetime) throws Exception
|
||||||
{
|
{
|
||||||
// Save copies of the input parameters
|
// Save copies of the input parameters
|
||||||
m_id = id;
|
m_id = id;
|
||||||
m_realm = realm;
|
m_realm = realm;
|
||||||
m_lifetime = lifetime;
|
m_lifetime = lifetime;
|
||||||
|
|
||||||
// Generate a signature
|
// Generate a signature
|
||||||
// tbd - Over id, realm, and lifetime data.
|
// tbd - Over id, realm, and lifetime data.
|
||||||
m_signature = "tbd";
|
m_signature = "tbd";
|
||||||
|
|
||||||
// Get a StringBuffer to help us with the construction of the token
|
// Get a StringBuffer to help us with the construction of the token
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
// Start building the message
|
// Start building the message
|
||||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.sessionTokenElementName + ">" + "\r\n");
|
sb.append("<" + ProtoDefs.sessionTokenElementName + ">" + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.signatureElementName + ">" + m_signature + "</" + ProtoDefs.signatureElementName + ">" + "\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.lifetimeElementName + ">" + m_lifetime + "</" + ProtoDefs.lifetimeElementName + ">" + "\r\n");
|
||||||
sb.append("<" + ProtoDefs.realmElementName + ">" + m_realm + "</" + ProtoDefs.realmElementName + ">" + "\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.identIdElementName + ">" + m_id + "</" + ProtoDefs.identIdElementName + ">" + "\r\n");
|
||||||
sb.append("</" + ProtoDefs.sessionTokenElementName + ">" + "\r\n");
|
sb.append("</" + ProtoDefs.sessionTokenElementName + ">" + "\r\n");
|
||||||
|
|
||||||
// Save the token
|
// Save the token
|
||||||
m_token = sb.toString();
|
m_token = sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor given a session token string. The constructor
|
* Constructor given a session token string. The constructor
|
||||||
* validates the token as part of its processing.
|
* validates the token as part of its processing.
|
||||||
*/
|
*/
|
||||||
public SessionToken(String token) throws Exception
|
public SessionToken(String token) throws Exception
|
||||||
{
|
{
|
||||||
// Decode the token string
|
// Decode the token string
|
||||||
m_token = Base64Coder.decode(token);
|
m_token = Base64Coder.decode(token);
|
||||||
|
|
||||||
// Now parse the token into its elements
|
// Now parse the token into its elements
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Parse the SessionToken
|
// Parse the SessionToken
|
||||||
XMLReader xr = XMLReaderFactory.createXMLReader();
|
XMLReader xr = XMLReaderFactory.createXMLReader();
|
||||||
SAXHandler handler = new SAXHandler(this);
|
SAXHandler handler = new SAXHandler(this);
|
||||||
xr.setContentHandler(handler);
|
xr.setContentHandler(handler);
|
||||||
xr.setErrorHandler(handler);
|
xr.setErrorHandler(handler);
|
||||||
|
|
||||||
ByteArrayInputStream inStream = new ByteArrayInputStream(m_token.getBytes());
|
ByteArrayInputStream inStream = new ByteArrayInputStream(m_token.getBytes());
|
||||||
InputSource source = new InputSource(inStream);
|
InputSource source = new InputSource(inStream);
|
||||||
xr.parse(source);
|
xr.parse(source);
|
||||||
|
|
||||||
// Verify the signature
|
// Verify the signature
|
||||||
// tbd
|
// tbd
|
||||||
|
|
||||||
// Verify that the token has not expired
|
// Verify that the token has not expired
|
||||||
// tbd
|
// tbd
|
||||||
}
|
}
|
||||||
catch (SAXException e)
|
catch (SAXException e)
|
||||||
{
|
{
|
||||||
System.err.println("SessionToken()- Parse exception: " + e.toString());
|
System.err.println("SessionToken()- Parse exception: " + e.toString());
|
||||||
throw new Exception("Protocol error");
|
throw new Exception("Protocol error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a string containing the session token.
|
* Returns a string containing the session token.
|
||||||
*/
|
*/
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return Base64Coder.encode(m_token);
|
return Base64Coder.encode(m_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method to get the Identity Id
|
* Method to get the Identity Id
|
||||||
*/
|
*/
|
||||||
public String getIdentId() throws Exception
|
public String getIdentId() throws Exception
|
||||||
{
|
{
|
||||||
return m_id;
|
return m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method to get the Identity Repository Reference (Realm).
|
* Method to get the Identity Repository Reference (Realm).
|
||||||
*/
|
*/
|
||||||
public String getRealm() throws Exception
|
public String getRealm() throws Exception
|
||||||
{
|
{
|
||||||
return m_realm;
|
return m_realm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user