Added missing javadoc comments and made minor changes for issues found
during code inspection.
This commit is contained in:
parent
43009ada4f
commit
919bb85125
@ -92,7 +92,7 @@ The ATS base settings are configured in the svc.settings file under the conf fol
|
||||
|
||||
The following is an example svc.settings file:
|
||||
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<SessionTokenLifetime>43200</SessionTokenLifetime>
|
||||
<LifetimeShorter>10</LifetimeShorter>
|
||||
@ -179,7 +179,7 @@ realms.
|
||||
|
||||
The following is an example auth.policy file:
|
||||
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<auth_policy>
|
||||
<auth_source>
|
||||
<realm>CorpTree</realm>
|
||||
@ -222,7 +222,7 @@ tokens issued to authenticate to the service.
|
||||
|
||||
The following is an example authtoken.settings file:
|
||||
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<TokenLifetime>3600</TokenLifetime>
|
||||
<LifetimeShorter>10</LifetimeShorter>
|
||||
@ -253,7 +253,7 @@ embedded in authentication tokens.
|
||||
|
||||
The following is an example identoken.settings file:
|
||||
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<Attributes>sn,groupMembership,guid</Attributes>
|
||||
<EncryptAttributes>false</EncryptAttributes>
|
||||
@ -303,7 +303,7 @@ implementing the mechanism.
|
||||
The following is an example mechanism.settings file for the Krb5Authentication
|
||||
mechanism:
|
||||
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<ClassName>com.novell.casa.authtoksvc.Krb5Authenticate</ClassName>
|
||||
<RelativeClassPath>WEB-INF/classes</RelativeClassPath>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<auth_policy>
|
||||
<auth_source>
|
||||
<realm>CorpTree</realm>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<ClassName>com.novell.casa.authtoksvc.Krb5Authenticate</ClassName>
|
||||
<RelativeClassPath>WEB-INF/classes</RelativeClassPath>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<ClassName>com.novell.casa.authtoksvc.PwdAuthenticate</ClassName>
|
||||
<RelativeClassPath>WEB-INF/classes</RelativeClassPath>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<TokenLifetime>3600</TokenLifetime>
|
||||
</settings>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<auth_policy>
|
||||
<auth_source>
|
||||
<realm>CorpTree</realm>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<TokenLifetime>3600</TokenLifetime>
|
||||
</settings>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<EncryptAttributes>false</EncryptAttributes>
|
||||
<Attributes>sn,groupMembership</Attributes>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<EncryptAttributes>false</EncryptAttributes>
|
||||
<Attributes>sn</Attributes>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<IAConfigFile>/home/jluciani/jakarta-tomcat-5.0.28/webapps/CasaAuthTokenSvc/WEB-INF/conf/iaRealms.xml</IAConfigFile>
|
||||
<SessionTokenLifetime>43200</SessionTokenLifetime>
|
||||
|
@ -34,11 +34,11 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
/**
|
||||
* AuthMechConfig Class.
|
||||
*
|
||||
* <p>
|
||||
* This class obtains and maintains authentication token configuration.
|
||||
*
|
||||
*/
|
||||
public class AuthMechConfig
|
||||
public final class AuthMechConfig
|
||||
{
|
||||
// Well known authentication token configuration settings
|
||||
public final static String ClassName = "ClassName";
|
||||
@ -47,14 +47,14 @@ public class AuthMechConfig
|
||||
public final static String Krb5ServicePrincipalName = "ServicePrincipalName";
|
||||
|
||||
// Default configuration values
|
||||
private String m_defaultKrb5ServicePrincipalNameValue = "host";
|
||||
private final String m_defaultKrb5ServicePrincipalNameValue = "host";
|
||||
|
||||
private Map m_mechSettingsMap;
|
||||
private final Map<String,String> m_mechSettingsMap;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Class for handling parsing events.
|
||||
*/
|
||||
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
private static final class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
{
|
||||
private final static int AWAITING_ROOT_ELEMENT_START = 0;
|
||||
private final static int AWAITING_SETTING_ELEMENT_START = 1;
|
||||
@ -64,14 +64,16 @@ public class AuthMechConfig
|
||||
|
||||
private final static String m_rootElementName = "settings";
|
||||
|
||||
private Map m_keyMap;
|
||||
private final Map<String,String> m_keyMap;
|
||||
private int m_state;
|
||||
private String m_currentKey;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param keyMap Key/Value map.
|
||||
*/
|
||||
public SAXHandler(Map keyMap)
|
||||
public SAXHandler(Map<String,String> keyMap)
|
||||
{
|
||||
super();
|
||||
|
||||
@ -80,8 +82,10 @@ public class AuthMechConfig
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* endDocument() implementation.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endDocument () throws SAXException
|
||||
{
|
||||
@ -93,8 +97,14 @@ public class AuthMechConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* startElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @param atts Attributes.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
{
|
||||
@ -129,8 +139,13 @@ public class AuthMechConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* endElement() immplementation.
|
||||
/**
|
||||
* endElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endElement (String uri, String name, String qName) throws SAXException
|
||||
{
|
||||
@ -163,8 +178,13 @@ public class AuthMechConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* character() implementation.
|
||||
*
|
||||
* @param ch Characters with element data.
|
||||
* @param start Start position in the character array.
|
||||
* @param length Number of characters to use in the array.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void characters (char ch[], int start, int length) throws SAXException
|
||||
{
|
||||
@ -180,26 +200,29 @@ public class AuthMechConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor which sets default configuration values.
|
||||
*/
|
||||
public AuthMechConfig() throws Exception
|
||||
public AuthMechConfig()
|
||||
{
|
||||
System.err.println("AuthMechConfig()- Default");
|
||||
|
||||
// Create a map to keep track of the token settings
|
||||
m_mechSettingsMap = new HashMap();
|
||||
m_mechSettingsMap = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param mechSettingsFileName Name of mechanism's settings file.
|
||||
* @throws Exception
|
||||
*/
|
||||
public AuthMechConfig(String mechSettingsFileName) throws Exception
|
||||
{
|
||||
System.err.println("AuthMechConfig()-");
|
||||
|
||||
// Create a map to keep track of the token settings
|
||||
m_mechSettingsMap = new HashMap();
|
||||
m_mechSettingsMap = new HashMap<String, String>();
|
||||
|
||||
try
|
||||
{
|
||||
@ -240,13 +263,16 @@ public class AuthMechConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the value associated with the specified setting.
|
||||
*
|
||||
* @param settingName Name of the setting.
|
||||
* @return Value of the specified setting.
|
||||
*/
|
||||
public String getSetting(String settingName) throws Exception
|
||||
public final String getSetting(String settingName)
|
||||
{
|
||||
// Try to find the setting in our map
|
||||
String value = (String) m_mechSettingsMap.get(settingName);
|
||||
String value = m_mechSettingsMap.get(settingName);
|
||||
if (value == null)
|
||||
{
|
||||
|
||||
|
@ -24,30 +24,40 @@
|
||||
|
||||
package com.novell.casa.authtoksvc;
|
||||
|
||||
/*
|
||||
/**
|
||||
* AuthMechanism Interface.
|
||||
*
|
||||
* <p>
|
||||
* This is the interface implemented by Authentication Mechanisms.
|
||||
*
|
||||
* <p>
|
||||
* Please note that Authentication Machanisms must also implement the
|
||||
* Serializable interface.
|
||||
*
|
||||
*/
|
||||
public interface AuthMechanism
|
||||
{
|
||||
/*
|
||||
/**
|
||||
* Initialize the authentication mechanism.
|
||||
*
|
||||
* @param svcConfig Service configuration object.
|
||||
* @param mechConfig Mechanism configuration object.
|
||||
* @throws Exception
|
||||
*/
|
||||
void init(SvcConfig svcConfig, AuthMechConfig mechConfig) throws Exception;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Process authenticate request. If successful, return the Id of the
|
||||
* authenticated identity.
|
||||
*
|
||||
* @param authReqMsg Authentication request message.
|
||||
* @return Id of the authenticated entity.
|
||||
* @throws Exception
|
||||
*/
|
||||
String invoke(AuthReqMsg authReqMsg) throws Exception;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Return the mechanism id.
|
||||
*
|
||||
* @return Mechanism id.
|
||||
*/
|
||||
String getId();
|
||||
}
|
||||
|
@ -34,14 +34,13 @@ import org.apache.xml.serialize.OutputFormat;
|
||||
import org.apache.xml.serialize.XMLSerializer;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Formatter;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class for the creation and editing of auth.policy files.
|
||||
*
|
||||
**/
|
||||
public class AuthPolicyEditor
|
||||
*/
|
||||
public final class AuthPolicyEditor
|
||||
{
|
||||
private static final String usage =
|
||||
"usage: AuthPolicyEditor -op [-entry realm:mechanismName[:mechanismInfo]] [-refentry realm:mechanismName] -file policyFilePath\n\n" +
|
||||
@ -75,10 +74,10 @@ public class AuthPolicyEditor
|
||||
|
||||
|
||||
/**
|
||||
* Returns the formal mechanism name if well known
|
||||
* Returns the formal mechanism name if well known.
|
||||
*
|
||||
* @param mechName Name of mechanism.
|
||||
* @return Mechanism formal name.
|
||||
* @return Mechanism formal name.
|
||||
*/
|
||||
private static String mechFormalName(String mechName)
|
||||
{
|
||||
@ -113,7 +112,7 @@ public class AuthPolicyEditor
|
||||
// Remove text nodes
|
||||
Element root = doc.getDocumentElement();
|
||||
Node child;
|
||||
Node next = (Node) root.getFirstChild();
|
||||
Node next = root.getFirstChild();
|
||||
while ((child = next) != null)
|
||||
{
|
||||
next = child.getNextSibling();
|
||||
@ -190,7 +189,7 @@ public class AuthPolicyEditor
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a starting policy document
|
||||
* Gets a starting policy document.
|
||||
*
|
||||
* @return Starting policy document.
|
||||
*/
|
||||
@ -361,7 +360,7 @@ public class AuthPolicyEditor
|
||||
|
||||
Element firstEntry = null;
|
||||
Node child;
|
||||
Node next = (Node) root.getFirstChild();
|
||||
Node next = root.getFirstChild();
|
||||
while ((child = next) != null)
|
||||
{
|
||||
next = child.getNextSibling();
|
||||
@ -525,7 +524,7 @@ public class AuthPolicyEditor
|
||||
}
|
||||
curr_auth_source_node.getNextSibling();
|
||||
Element nextEntry = null;
|
||||
next = (Node) curr_auth_source_node.getNextSibling();;
|
||||
next = curr_auth_source_node.getNextSibling();
|
||||
while ((child = next) != null)
|
||||
{
|
||||
next = child.getNextSibling();
|
||||
@ -639,9 +638,9 @@ public class AuthPolicyEditor
|
||||
}
|
||||
|
||||
/**
|
||||
* Applications Entry Point
|
||||
* Applications Entry Point.
|
||||
*
|
||||
* @param args
|
||||
* @param args Arguments.
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
|
@ -34,30 +34,30 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
/**
|
||||
* AuthReqMsg Class.
|
||||
*
|
||||
* <p>
|
||||
* This class deals with the message sent by Casa Client when requesting
|
||||
* that an entity be authenticated. The format of the message is as
|
||||
* follows:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <auth_req>
|
||||
* <realm>realm value</realm>
|
||||
* <mechanism>mechanism id</mechanism>
|
||||
* <auth_mech_token>mechanism token data</auth_mech_token>
|
||||
* </auth_req>
|
||||
* <p>
|
||||
* <?xml version="1.0" encoding="UTF-8"?>
|
||||
* <auth_req>
|
||||
* <realm>realm value</realm>
|
||||
* <mechanism>mechanism id</mechanism>
|
||||
* <auth_mech_token>mechanism token data</auth_mech_token>
|
||||
* </auth_req>
|
||||
*
|
||||
*/
|
||||
public class AuthReqMsg
|
||||
public final class AuthReqMsg
|
||||
{
|
||||
|
||||
protected String m_realm = null;
|
||||
protected String m_authMechToken = null;
|
||||
protected String m_authMechanism = null;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Class for handling Authentication Request parsing events.
|
||||
*/
|
||||
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
private final class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
{
|
||||
private final static int AWAITING_ROOT_ELEMENT_START = 0;
|
||||
private final static int AWAITING_ROOT_ELEMENT_END = 1;
|
||||
@ -72,11 +72,13 @@ public class AuthReqMsg
|
||||
private final static int AWAITING_AUTH_MECH_TOKEN_DATA = 10;
|
||||
private final static int DONE_PARSING = 11;
|
||||
|
||||
private AuthReqMsg m_authReqMsg;
|
||||
private final AuthReqMsg m_authReqMsg;
|
||||
private int m_state;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param authReqMsg Authentication request message object.
|
||||
*/
|
||||
public SAXHandler (AuthReqMsg authReqMsg)
|
||||
{
|
||||
@ -87,10 +89,12 @@ public class AuthReqMsg
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* endDocument() implementation.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endDocument () throws SAXException
|
||||
public final void endDocument () throws SAXException
|
||||
{
|
||||
// Verify that we obtained all of the required elements
|
||||
if (m_state != DONE_PARSING)
|
||||
@ -100,10 +104,16 @@ public class AuthReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* startElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @param atts Attributes.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
public final void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -170,10 +180,15 @@ public class AuthReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* endElement() immplementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endElement (String uri, String name, String qName) throws SAXException
|
||||
public final void endElement (String uri, String name, String qName) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -240,10 +255,15 @@ public class AuthReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* character() implementation.
|
||||
*
|
||||
* @param ch Characters with element data.
|
||||
* @param start Start position in the character array.
|
||||
* @param length Number of characters to use in the array.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void characters (char ch[], int start, int length) throws SAXException
|
||||
public final void characters (char ch[], int start, int length) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -294,8 +314,11 @@ public class AuthReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param inStream Input stream with authentication request data.
|
||||
* @throws Exception
|
||||
*/
|
||||
public AuthReqMsg (InputStream inStream) throws Exception
|
||||
{
|
||||
@ -317,26 +340,32 @@ public class AuthReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Method to get the authentication realm.
|
||||
/**
|
||||
* Method to get the authentication realm.
|
||||
*
|
||||
* @return Authentication realm name.
|
||||
*/
|
||||
public String getRealm() throws Exception
|
||||
public String getRealm()
|
||||
{
|
||||
return m_realm;
|
||||
}
|
||||
|
||||
/*
|
||||
* Method to get the authentication mechanism token.
|
||||
/**
|
||||
* Method to get the authentication mechanism token.
|
||||
*
|
||||
* @return Authentication mechanism token.
|
||||
*/
|
||||
public String getAuthMechToken() throws Exception
|
||||
public String getAuthMechToken()
|
||||
{
|
||||
return m_authMechToken;
|
||||
}
|
||||
|
||||
/*
|
||||
* Method to get the authentication mechanism id.
|
||||
/**
|
||||
* Method to get the authentication mechanism id.
|
||||
*
|
||||
* @return Id of authentication mechanism targeted.
|
||||
*/
|
||||
public String getMechanismId() throws Exception
|
||||
public String getMechanismId()
|
||||
{
|
||||
return m_authMechanism;
|
||||
}
|
||||
|
@ -30,83 +30,90 @@ package com.novell.casa.authtoksvc;
|
||||
* This class deals with the message sent to the CASA Client as a
|
||||
* response to an authentication request. The format of the message is
|
||||
* as follows when the response includes a session token:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <auth_resp>
|
||||
* <status><description>OK</description>200</status>
|
||||
* <session_token><lifetime>lifetime value</lifetime>session token data</session_token>
|
||||
* </auth_resp>
|
||||
*
|
||||
* <p>
|
||||
* <?xml version="1.0" encoding="UTF-8"?>
|
||||
* <auth_resp>
|
||||
* <status><description>OK</description>200</status>
|
||||
* <session_token><lifetime>lifetime value</lifetime>session token data</session_token>
|
||||
* </auth_resp>
|
||||
* <p>
|
||||
* The format of the message is as follows when the response does not
|
||||
* include a session token.
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <auth_resp>
|
||||
* <status><description>status description</description>status code</status>
|
||||
* </auth_resp>
|
||||
*
|
||||
* <p>
|
||||
* <?xml version="1.0" encoding="UTF-8"?>
|
||||
* <auth_resp>
|
||||
* <status><description>status description</description>status code</status>
|
||||
* </auth_resp>
|
||||
* <p>
|
||||
* Plase note that the protocol utilizes the status codes defined
|
||||
* in the HTTP 1.1 Specification.
|
||||
*
|
||||
*/
|
||||
public class AuthRespMsg
|
||||
public final class AuthRespMsg
|
||||
{
|
||||
|
||||
String m_msg;
|
||||
final String m_msg;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor for a msg that does not include the session token.
|
||||
*
|
||||
* @param statusDescription Description of the status code.
|
||||
* @param statusCode Status code.
|
||||
*/
|
||||
public AuthRespMsg (
|
||||
String statusDescription,
|
||||
String statusCode) throws Exception
|
||||
public AuthRespMsg (String statusDescription, String statusCode)
|
||||
{
|
||||
// Get a StringBuffer to help us with the construction of the message
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
// Start building the message
|
||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||
sb.append("<" + ProtoDefs.authResponseElementName + ">" + "\r\n");
|
||||
sb.append("<" + ProtoDefs.statusElementName + ">"
|
||||
+ "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
|
||||
+ statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
||||
sb.append("</" + ProtoDefs.authResponseElementName + ">" + "\r\n");
|
||||
sb.append(ProtoDefs.xmlDeclaration); sb.append("\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.authResponseElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.statusElementName); sb.append(">");
|
||||
sb.append("<"); sb.append(ProtoDefs.descriptionElementName); sb.append(">"); sb.append(statusDescription); sb.append("</"); sb.append(ProtoDefs.descriptionElementName); sb.append(">");
|
||||
sb.append(statusCode); sb.append("</"); sb.append(ProtoDefs.statusElementName); sb.append(">\r\n");
|
||||
sb.append("</"); sb.append(ProtoDefs.authResponseElementName); sb.append(">\r\n");
|
||||
|
||||
// The message has now been built, save it.
|
||||
m_msg = sb.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor for a msg that includes the session token.
|
||||
*
|
||||
* @param statusDescription Status code description.
|
||||
* @param statusCode Status code.
|
||||
* @param sessionToken Session token string.
|
||||
* @param sessionTokenLifetime Lifetime of the session token.
|
||||
*/
|
||||
public AuthRespMsg (
|
||||
String statusDescription,
|
||||
String statusCode,
|
||||
String sessionToken,
|
||||
String sessionTokenLifetime) throws Exception
|
||||
public AuthRespMsg (String statusDescription,
|
||||
String statusCode,
|
||||
String sessionToken,
|
||||
String sessionTokenLifetime)
|
||||
{
|
||||
// Get a StringBuffer to help us with the construction of the message
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
// Start building the message
|
||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||
sb.append("<" + ProtoDefs.authResponseElementName + ">" + "\r\n");
|
||||
sb.append("<" + ProtoDefs.statusElementName + ">"
|
||||
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">"
|
||||
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
||||
sb.append("<" + ProtoDefs.sessionTokenElementName + ">"
|
||||
+ "<" + ProtoDefs.lifetimeElementName + ">" + sessionTokenLifetime + "</" + ProtoDefs.lifetimeElementName + ">"
|
||||
+ sessionToken + "</" + ProtoDefs.sessionTokenElementName + ">" + "\r\n");
|
||||
sb.append("</" + ProtoDefs.authResponseElementName + ">" + "\r\n");
|
||||
sb.append(ProtoDefs.xmlDeclaration); sb.append("\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.authResponseElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.statusElementName); sb.append(">");
|
||||
sb.append("<"); sb.append(ProtoDefs.descriptionElementName); sb.append(">"); sb.append(ProtoDefs.httpOkStatusMsg); sb.append("</"); sb.append(ProtoDefs.descriptionElementName); sb.append(">");
|
||||
sb.append(ProtoDefs.httpOkStatusCode); sb.append("</"); sb.append(ProtoDefs.statusElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.sessionTokenElementName); sb.append(">");
|
||||
sb.append("<"); sb.append(ProtoDefs.lifetimeElementName); sb.append(">"); sb.append(sessionTokenLifetime); sb.append("</"); sb.append(ProtoDefs.lifetimeElementName); sb.append(">");
|
||||
sb.append(sessionToken); sb.append("</"); sb.append(ProtoDefs.sessionTokenElementName); sb.append(">\r\n");
|
||||
sb.append("</"); sb.append(ProtoDefs.authResponseElementName); sb.append(">\r\n");
|
||||
|
||||
// The message has now been built, save it.
|
||||
m_msg = sb.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the AuthRespMsg.
|
||||
*
|
||||
* @return Authentication response message string.
|
||||
*/
|
||||
public String toString()
|
||||
public final String toString()
|
||||
{
|
||||
return m_msg;
|
||||
}
|
||||
|
@ -41,20 +41,20 @@ import java.io.*;
|
||||
//import org.apache.axis.utils.XMLUtils;
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* AuthToken Class.
|
||||
*
|
||||
* <p>
|
||||
* This class constructs authentication tokens that clients can present
|
||||
* to services for authentication. The authentication token consists of
|
||||
* a SOAP message secured with WSSecurity with the appropriate elements signed
|
||||
* and with a timestamp. The body of the SOAP message is as follows:
|
||||
*
|
||||
* <auth_token>
|
||||
* <ident_token><type>Identity Token type</type>identity token data</ident_token>
|
||||
* </auth_token>
|
||||
* <p>
|
||||
* <auth_token>
|
||||
* <ident_token><type>Identity Token type</type>identity token data</ident_token>
|
||||
* </auth_token>
|
||||
*
|
||||
*/
|
||||
public class AuthToken
|
||||
public final class AuthToken
|
||||
{
|
||||
private String m_token;
|
||||
private String m_lifetime = "";
|
||||
@ -75,8 +75,16 @@ public class AuthToken
|
||||
|
||||
static final private MessageContext axisMsgContext = new MessageContext(new AxisClient(new NullProvider()));
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param identityId Id of the authenticated identity.
|
||||
* @param realm Realm where the identity id is valid.
|
||||
* @param targetService Name of the targeted service.
|
||||
* @param targetHost Host where the targeted service resides.
|
||||
* @param svcConfig Service configuration object.
|
||||
* @param enabledSvcsConfig Enabled services configuration object.
|
||||
* @throws Exception
|
||||
*/
|
||||
public AuthToken(String identityId,
|
||||
String realm,
|
||||
@ -137,9 +145,13 @@ public class AuthToken
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor given an authentication token string. The constructor
|
||||
* validates the token as part of its processing.
|
||||
*
|
||||
* @param token Authentication token string.
|
||||
* @param encodedToken Indication of whether or not the token is Base64 encoded.
|
||||
* @throws Exception
|
||||
*/
|
||||
public AuthToken(String token,
|
||||
boolean encodedToken) throws Exception
|
||||
@ -202,20 +214,20 @@ public class AuthToken
|
||||
}
|
||||
|
||||
/**
|
||||
* Get AuthToken SOAP Message
|
||||
* Get AuthToken SOAP Message.
|
||||
*
|
||||
* @param identityToken String containing the identity token that should be part of the message
|
||||
* @param identityTokenType String containing the identity token type
|
||||
* @param lifetime Lifetime that should be specified in the message timestamp (seconds)
|
||||
* @param svcConfig Service configuration object
|
||||
* @param includeCert True if the message should include the Public Certificate
|
||||
* @return <code>Message<code> AuthToken message, null if the method fails.
|
||||
* @param identityToken String containing the identity token that should be part of the message.
|
||||
* @param identityTokenType String containing the identity token type.
|
||||
* @param lifetime Lifetime that should be specified in the message timestamp (seconds).
|
||||
* @param svcConfig Service configuration object.
|
||||
* @param includeCert True if the message should include the Public Certificate.
|
||||
* @return AuthToken message, null if the method fails.
|
||||
*/
|
||||
private Message getMessage(String identityToken,
|
||||
String identityTokenType,
|
||||
int lifetime,
|
||||
SvcConfig svcConfig,
|
||||
boolean includeCert)
|
||||
private static Message getMessage(String identityToken,
|
||||
String identityTokenType,
|
||||
int lifetime,
|
||||
SvcConfig svcConfig,
|
||||
boolean includeCert)
|
||||
{
|
||||
Message secureMessage;
|
||||
|
||||
@ -260,21 +272,26 @@ public class AuthToken
|
||||
return secureMessage;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the Base64 encode token.
|
||||
*
|
||||
* @return Authentication token string.
|
||||
*/
|
||||
public String toString()
|
||||
public final String toString()
|
||||
{
|
||||
return Base64Coder.encode(m_token);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the lifetime of the token.
|
||||
*
|
||||
* <p>
|
||||
* Note: It is only valid to execute this procedure if its called on an object
|
||||
* instantiated via the constructor which takes a lifetime parameter.
|
||||
*
|
||||
* @return Authentication token lifetime.
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getLifetime() throws Exception
|
||||
public final String getLifetime() throws Exception
|
||||
{
|
||||
// Throw exeption if the lifetime parameter is not set
|
||||
if (m_lifetime.length() == 0)
|
||||
@ -286,28 +303,35 @@ public class AuthToken
|
||||
return Integer.toString(Integer.valueOf(m_lifetime).intValue() - Integer.valueOf(m_lifetimeShorter).intValue());
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the identity token.
|
||||
*
|
||||
* @return Identity token string.
|
||||
*/
|
||||
public String getIdentityToken()
|
||||
public final String getIdentityToken()
|
||||
{
|
||||
return m_identityToken;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the identity token type.
|
||||
*
|
||||
* @return Identity token type.
|
||||
*/
|
||||
public String getIdentityTokenType()
|
||||
public final String getIdentityTokenType()
|
||||
{
|
||||
return m_identityTokenType;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Validates an authentication token. If successful it
|
||||
* returns a string containing the identity token associated
|
||||
* with the authentication token; otherwise it returns NULL;
|
||||
*
|
||||
* <p>
|
||||
* Note, the routine assumes that the token is not encoded.
|
||||
*
|
||||
* @param authTokenString Authentication token string.
|
||||
* @return Identity token string.
|
||||
*/
|
||||
public static String validate(String authTokenString)
|
||||
{
|
||||
|
@ -34,11 +34,11 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
/**
|
||||
* AuthTokenConfig Class.
|
||||
*
|
||||
* <p>
|
||||
* This class obtains and maintains authentication token configuration.
|
||||
*
|
||||
*/
|
||||
public class AuthTokenConfig
|
||||
public final class AuthTokenConfig
|
||||
{
|
||||
// Well known authentication token configuration settings
|
||||
public final static String TokenLifetime = "TokenLifetime";
|
||||
@ -46,16 +46,16 @@ public class AuthTokenConfig
|
||||
public final static String IdentityTokenType = "IdentityTokenType";
|
||||
|
||||
// Default configuration values
|
||||
private String m_defaultTokenLifetimeValue = "3600"; // Seconds
|
||||
private String m_defaultLifetimeShorterValue = "5"; // Seconds
|
||||
private String m_defaultIdentityTokenTypeValue = "CasaIdentityToken";
|
||||
private final String m_defaultTokenLifetimeValue = "3600"; // Seconds
|
||||
private final String m_defaultLifetimeShorterValue = "5"; // Seconds
|
||||
private final String m_defaultIdentityTokenTypeValue = "CasaIdentityToken";
|
||||
|
||||
private Map m_tokenSettingsMap;
|
||||
private final Map<String,String> m_tokenSettingsMap;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Class for handling parsing events.
|
||||
*/
|
||||
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
private static final class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
{
|
||||
private final static int AWAITING_ROOT_ELEMENT_START = 0;
|
||||
private final static int AWAITING_SETTING_ELEMENT_START = 1;
|
||||
@ -65,14 +65,16 @@ public class AuthTokenConfig
|
||||
|
||||
private final static String m_rootElementName = "settings";
|
||||
|
||||
private Map m_keyMap;
|
||||
private final Map<String,String> m_keyMap;
|
||||
private int m_state;
|
||||
private String m_currentKey;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param keyMap Key/Value pair map.
|
||||
*/
|
||||
public SAXHandler(Map keyMap)
|
||||
public SAXHandler(Map<String,String> keyMap)
|
||||
{
|
||||
super();
|
||||
|
||||
@ -81,8 +83,10 @@ public class AuthTokenConfig
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* endDocument() implementation.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endDocument () throws SAXException
|
||||
{
|
||||
@ -94,8 +98,14 @@ public class AuthTokenConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* startElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @param atts Attributes.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
{
|
||||
@ -130,8 +140,13 @@ public class AuthTokenConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* endElement() immplementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endElement (String uri, String name, String qName) throws SAXException
|
||||
{
|
||||
@ -164,8 +179,13 @@ public class AuthTokenConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* character() implementation.
|
||||
*
|
||||
* @param ch Characters with element data.
|
||||
* @param start Start position in the character array.
|
||||
* @param length Number of characters to use in the array.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void characters (char ch[], int start, int length) throws SAXException
|
||||
{
|
||||
@ -181,15 +201,15 @@ public class AuthTokenConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor which sets default configuration values.
|
||||
*/
|
||||
public AuthTokenConfig() throws Exception
|
||||
public AuthTokenConfig()
|
||||
{
|
||||
System.err.println("AuthTokenConfig()- Default");
|
||||
|
||||
// Create a map to keep track of the token settings
|
||||
m_tokenSettingsMap = new HashMap();
|
||||
m_tokenSettingsMap = new HashMap<String, String>();
|
||||
|
||||
// Set the default settings in our map
|
||||
m_tokenSettingsMap.put(TokenLifetime, m_defaultTokenLifetimeValue);
|
||||
@ -197,15 +217,18 @@ public class AuthTokenConfig
|
||||
m_tokenSettingsMap.put(IdentityTokenType, m_defaultIdentityTokenTypeValue);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param authTokenSettingsFileName Name of the authentication token settings file.
|
||||
* @throws Exception
|
||||
*/
|
||||
public AuthTokenConfig(String authTokenSettingsFileName) throws Exception
|
||||
{
|
||||
System.err.println("AuthTokenConfig()-");
|
||||
|
||||
// Create a map to keep track of the token settings
|
||||
m_tokenSettingsMap = new HashMap();
|
||||
m_tokenSettingsMap = new HashMap<String, String>();
|
||||
|
||||
try
|
||||
{
|
||||
@ -246,13 +269,16 @@ public class AuthTokenConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the value associated with the specified setting.
|
||||
*
|
||||
* @param settingName Name of the setting.
|
||||
* @return Value of the specified setting.
|
||||
*/
|
||||
public String getSetting(String settingName) throws Exception
|
||||
public final String getSetting(String settingName)
|
||||
{
|
||||
// Try to find the setting in our map
|
||||
String value = (String) m_tokenSettingsMap.get(settingName);
|
||||
String value = m_tokenSettingsMap.get(settingName);
|
||||
if (value == null)
|
||||
{
|
||||
System.err.println("AuthTokenConfig.getSetting()- Did not find setting " + settingName);
|
||||
|
@ -28,8 +28,8 @@ package com.novell.casa.authtoksvc;
|
||||
*
|
||||
* Class for the creation and editing of authtoken.settings files.
|
||||
*
|
||||
**/
|
||||
public class AuthTokenSettingsEditor implements IVerifySetting
|
||||
*/
|
||||
public final class AuthTokenSettingsEditor implements IVerifySetting
|
||||
{
|
||||
private static final String usage =
|
||||
"usage: AuthTokenSettingsEditor -op [settingName [settingValue]] -file settingsFilePath\n\n" +
|
||||
@ -130,9 +130,9 @@ public class AuthTokenSettingsEditor implements IVerifySetting
|
||||
}
|
||||
|
||||
/**
|
||||
* Applications Entry Point
|
||||
* Applications Entry Point.
|
||||
*
|
||||
* @param args
|
||||
* @param args Arguments.
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
|
@ -39,32 +39,36 @@ import java.net.URLClassLoader;
|
||||
|
||||
/**
|
||||
* Authenticate Class.
|
||||
*
|
||||
* <p>
|
||||
* This class processes authentication requests.
|
||||
*
|
||||
*/
|
||||
public class Authenticate implements RpcMethod
|
||||
public final class Authenticate implements RpcMethod
|
||||
{
|
||||
private static final String m_mechanismSettingsFileName = "mechanism.settings";
|
||||
|
||||
private Map m_authMechanismMap;
|
||||
private final Map<String,AuthMechanism> m_authMechanismMap;
|
||||
|
||||
private SvcConfig m_svcConfig;
|
||||
private EnabledSvcsConfig m_enabledSvcsConfig;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Authenticate() throws Exception
|
||||
public Authenticate()
|
||||
{
|
||||
// Create a map to keep track of the authentication mechanisms
|
||||
m_authMechanismMap = new HashMap();
|
||||
m_authMechanismMap = new HashMap<String, AuthMechanism>();
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Initialize the Rpc method.
|
||||
*
|
||||
* @param svcConfig Service configuration object.
|
||||
* @param enabledSvcsConfig Enabled services configuration object.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void init(SvcConfig svcConfig, EnabledSvcsConfig enabledSvcsConfig) throws Exception
|
||||
public final void init(SvcConfig svcConfig, EnabledSvcsConfig enabledSvcsConfig) throws Exception
|
||||
{
|
||||
m_svcConfig = svcConfig;
|
||||
m_enabledSvcsConfig = enabledSvcsConfig;
|
||||
@ -120,7 +124,7 @@ public class Authenticate implements RpcMethod
|
||||
ClassLoader customClassLoader = new URLClassLoader(urls);
|
||||
|
||||
// Load the mech class using our custom loader
|
||||
Class mechClass = customClassLoader.loadClass(mechClassName);
|
||||
Class<?> mechClass = customClassLoader.loadClass(mechClassName);
|
||||
FileOutputStream fos = new FileOutputStream(svcConfig.getSetting(SvcConfig.AppRootPath) + "tmp");
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
oos.writeObject(mechClass);
|
||||
@ -128,7 +132,7 @@ public class Authenticate implements RpcMethod
|
||||
fos.close();
|
||||
FileInputStream fis = new FileInputStream(svcConfig.getSetting(SvcConfig.AppRootPath) + "tmp");
|
||||
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||
mechClass = (Class) ois.readObject();
|
||||
mechClass = (Class<?>) ois.readObject();
|
||||
ois.close();
|
||||
fis.close();
|
||||
|
||||
@ -174,7 +178,7 @@ public class Authenticate implements RpcMethod
|
||||
ClassLoader customClassLoader = new URLClassLoader(urls);
|
||||
|
||||
// Load the mech class using our custom loader
|
||||
Class mechClass = customClassLoader.loadClass(mechClassName);
|
||||
Class<?> mechClass = customClassLoader.loadClass(mechClassName);
|
||||
FileOutputStream fos = new FileOutputStream(svcConfig.getSetting(SvcConfig.AppRootPath) + "tmp");
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
oos.writeObject(mechClass);
|
||||
@ -182,7 +186,7 @@ public class Authenticate implements RpcMethod
|
||||
fos.close();
|
||||
FileInputStream fis = new FileInputStream(svcConfig.getSetting(SvcConfig.AppRootPath) + "tmp");
|
||||
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||
mechClass = (Class) ois.readObject();
|
||||
mechClass = (Class<?>) ois.readObject();
|
||||
ois.close();
|
||||
fis.close();
|
||||
|
||||
@ -254,10 +258,13 @@ public class Authenticate implements RpcMethod
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Process Rpc.
|
||||
*
|
||||
* @param inStream Input data stream (Request data).
|
||||
* @param out Output data print writter (Reply data).
|
||||
*/
|
||||
public void invoke(InputStream inStream, PrintWriter out) throws IOException
|
||||
public final void invoke(InputStream inStream, PrintWriter out)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -267,7 +274,7 @@ public class Authenticate implements RpcMethod
|
||||
AuthReqMsg authReqMsg = new AuthReqMsg(inStream);
|
||||
|
||||
// Get the necessary authentication mechanism
|
||||
AuthMechanism authMechanism = (AuthMechanism) m_authMechanismMap.get(authReqMsg.getMechanismId());
|
||||
AuthMechanism authMechanism = m_authMechanismMap.get(authReqMsg.getMechanismId());
|
||||
if (authMechanism != null)
|
||||
{
|
||||
// Invoke the mechanism to authenticate the entity
|
||||
@ -331,10 +338,12 @@ public class Authenticate implements RpcMethod
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Return the method id.
|
||||
*
|
||||
* @return Method id.
|
||||
*/
|
||||
public String getId()
|
||||
public final String getId()
|
||||
{
|
||||
return "Authenticate";
|
||||
}
|
||||
|
@ -20,19 +20,22 @@
|
||||
|
||||
package com.novell.casa.authtoksvc;
|
||||
|
||||
public class Base64Coder {
|
||||
/**
|
||||
* Base64Coder class.
|
||||
*/
|
||||
public final class Base64Coder {
|
||||
|
||||
// Mapping table from 6-bit nibbles to Base64 characters.
|
||||
private static char[] map1 = new char[64];
|
||||
private static final char[] map1 = new char[64];
|
||||
static {
|
||||
int i=0;
|
||||
for (char c='A'; c<='Z'; c++) map1[i++] = c;
|
||||
for (char c='a'; c<='z'; c++) map1[i++] = c;
|
||||
for (char c='0'; c<='9'; c++) map1[i++] = c;
|
||||
map1[i++] = '+'; map1[i++] = '/'; }
|
||||
map1[i++] = '+'; map1[i] = '/'; }
|
||||
|
||||
// Mapping table from Base64 characters to 6-bit nibbles.
|
||||
private static byte[] map2 = new byte[128];
|
||||
private static final byte[] map2 = new byte[128];
|
||||
static {
|
||||
for (int i=0; i<map2.length; i++) map2[i] = -1;
|
||||
for (int i=0; i<64; i++) map2[map1[i]] = (byte)i; }
|
||||
@ -40,8 +43,8 @@ private static byte[] map2 = new byte[128];
|
||||
/**
|
||||
* Encodes a string into Base64 format.
|
||||
* No blanks or line breaks are inserted.
|
||||
* @param s a String to be encoded.
|
||||
* @return A String with the Base64 encoded data.
|
||||
* @param s String to be encoded.
|
||||
* @return String with the Base64 encoded data.
|
||||
*/
|
||||
public static String encode (String s) {
|
||||
return new String(encode(s.getBytes())); }
|
||||
@ -49,8 +52,8 @@ public static String encode (String s) {
|
||||
/**
|
||||
* Encodes a byte array into Base64 format.
|
||||
* No blanks or line breaks are inserted.
|
||||
* @param in an array containing the data bytes to be encoded.
|
||||
* @return A character array with the Base64 encoded data.
|
||||
* @param in Array containing the data bytes to be encoded.
|
||||
* @return A character array with the Base64 encoded data.
|
||||
*/
|
||||
public static char[] encode (byte[] in) {
|
||||
int iLen = in.length;
|
||||
|
@ -25,9 +25,7 @@
|
||||
package com.novell.casa.authtoksvc;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingEnumeration;
|
||||
@ -44,35 +42,34 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
import org.bandit.ia.IAContext;
|
||||
import org.bandit.util.config.Realm;
|
||||
|
||||
/*
|
||||
/**
|
||||
* CasaIdentityToken Class.
|
||||
*
|
||||
* <p>
|
||||
* This class constructs Casa Identity tokens.
|
||||
*
|
||||
* <p>
|
||||
* A Casa Identity Token is a simple XML Document
|
||||
* with information about an identity in the form
|
||||
* of:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <casa_ident_tok>
|
||||
* <id>identity id</id>
|
||||
* <source_name>identity data source name</source_name>
|
||||
* <source_url>identity data source url</source_url>
|
||||
* <target_service>target service name</target_service>
|
||||
* <target_host>target host name</target_host>
|
||||
* <attributes>
|
||||
* <attribute name>attribute value</attribute name>
|
||||
* <attribute2 name>attribute2 value</attribute name>
|
||||
* ...
|
||||
* </attributes>
|
||||
* </casa_ident_tok>
|
||||
*
|
||||
*
|
||||
* attribute/values pairs. The attribute names
|
||||
* <p>
|
||||
* <?xml version="1.0" encoding="UTF-8"?>
|
||||
* <casa_ident_tok>
|
||||
* <id>identity id</id>
|
||||
* <source_name>identity data source name</source_name>
|
||||
* <source_url>identity data source url</source_url>
|
||||
* <target_service>target service name</target_service>
|
||||
* <target_host>target host name</target_host>
|
||||
* <attributes>
|
||||
* <attribute name>attribute value</attribute name>
|
||||
* <attribute2 name>attribute2 value</attribute name>
|
||||
* ...
|
||||
* </attributes>
|
||||
* </casa_ident_tok>
|
||||
* <p>
|
||||
* Attribute/values pairs. The attribute names
|
||||
* being the XML elements of the documents.
|
||||
*
|
||||
*/
|
||||
public class CasaIdentityToken implements IdentityToken
|
||||
public final class CasaIdentityToken implements IdentityToken
|
||||
{
|
||||
/*
|
||||
* XML Element Name Constants for the documents exchanged between the
|
||||
@ -86,7 +83,7 @@ public class CasaIdentityToken implements IdentityToken
|
||||
private final static String targetHostElementName = "target_host";
|
||||
private final static String attributesElementName = "attributes";
|
||||
|
||||
private IdenTokenConfig m_idenTokenConfig;
|
||||
private final IdenTokenConfig m_idenTokenConfig;
|
||||
|
||||
private String m_identityId = null;
|
||||
private String m_sourceName = null;
|
||||
@ -96,10 +93,10 @@ public class CasaIdentityToken implements IdentityToken
|
||||
private String m_token = null;
|
||||
private javax.naming.directory.Attributes m_attributes = null;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Class for handling Authentication Request parsing events.
|
||||
*/
|
||||
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
private final class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
{
|
||||
private final static int AWAITING_ROOT_ELEMENT_START = 0;
|
||||
private final static int AWAITING_ROOT_ELEMENT_END = 1;
|
||||
@ -125,13 +122,15 @@ public class CasaIdentityToken implements IdentityToken
|
||||
private final static int AWAITING_BINARY_ATTRIBUTE_DATA = 21;
|
||||
private final static int DONE_PARSING = 22;
|
||||
|
||||
private CasaIdentityToken m_casaIdentToken;
|
||||
private final CasaIdentityToken m_casaIdentToken;
|
||||
private int m_state;
|
||||
private String m_currAttribute;
|
||||
private boolean m_encryptedAttrs;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param casaIdentityToken Casa Identity Token object.
|
||||
*/
|
||||
public SAXHandler (CasaIdentityToken casaIdentityToken)
|
||||
{
|
||||
@ -142,10 +141,12 @@ public class CasaIdentityToken implements IdentityToken
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* endDocument() implementation.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endDocument () throws SAXException
|
||||
public final void endDocument () throws SAXException
|
||||
{
|
||||
// Verify that we obtained all of the required elements
|
||||
if (m_state != DONE_PARSING)
|
||||
@ -155,11 +156,16 @@ public class CasaIdentityToken implements IdentityToken
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
/**
|
||||
* startElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @param atts Attributes.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
public final void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -289,10 +295,15 @@ public class CasaIdentityToken implements IdentityToken
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* endElement() immplementation.
|
||||
/**
|
||||
* endElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endElement (String uri, String name, String qName) throws SAXException
|
||||
public final void endElement (String uri, String name, String qName) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -407,10 +418,15 @@ public class CasaIdentityToken implements IdentityToken
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* character() implementation.
|
||||
*
|
||||
* @param ch Characters with element data.
|
||||
* @param start Start position in the character array.
|
||||
* @param length Number of characters to use in the array.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void characters (char ch[], int start, int length) throws SAXException
|
||||
public final void characters (char ch[], int start, int length) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -510,8 +526,10 @@ public class CasaIdentityToken implements IdentityToken
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param idenTokenConfig Identity token configuration object.
|
||||
*/
|
||||
public CasaIdentityToken (IdenTokenConfig idenTokenConfig)
|
||||
{
|
||||
@ -521,7 +539,7 @@ public class CasaIdentityToken implements IdentityToken
|
||||
m_idenTokenConfig = idenTokenConfig;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public CasaIdentityToken ()
|
||||
@ -532,14 +550,21 @@ public class CasaIdentityToken implements IdentityToken
|
||||
m_idenTokenConfig = null;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Initialize with parameters.
|
||||
*
|
||||
* @param identityId Identity identifier.
|
||||
* @param sourceName Name of the realm where the identityId is valid.
|
||||
* @param targetService Name of service being targeted.
|
||||
* @param targetHost Host where the targeted service resides.
|
||||
* @param svcConfig Service configuration object.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void initialize (String identityId,
|
||||
String sourceName,
|
||||
String targetService,
|
||||
String targetHost,
|
||||
SvcConfig svcConfig) throws Exception
|
||||
public final void initialize (String identityId,
|
||||
String sourceName,
|
||||
String targetService,
|
||||
String targetHost,
|
||||
SvcConfig svcConfig) throws Exception
|
||||
{
|
||||
// Save input parameters
|
||||
m_identityId = identityId;
|
||||
@ -561,14 +586,14 @@ public class CasaIdentityToken implements IdentityToken
|
||||
// Setup a string buffer for building the IdentityToken, notice for now
|
||||
// we are not going to wrap the identity token.
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||
sb.append("<" + casaIdentTokElementName + ">" + "\r\n");
|
||||
sb.append("<" + idElementName + ">" + identityId + "</" + idElementName + ">\r\n");
|
||||
sb.append("<" + sourceNameElementName + ">" + sourceName + "</" + sourceNameElementName + ">\r\n");
|
||||
sb.append("<" + sourceUrlElementName + ">" + m_sourceUrl + "</" + sourceUrlElementName + ">\r\n");
|
||||
sb.append("<" + targetServiceElementName + ">" + m_service + "</" + targetServiceElementName + ">\r\n");
|
||||
sb.append("<" + targetHostElementName + ">" + m_host + "</" + targetHostElementName + ">\r\n");
|
||||
sb.append("<" + attributesElementName + ">" + "\r\n");
|
||||
sb.append(ProtoDefs.xmlDeclaration); sb.append("\r\n");
|
||||
sb.append("<"); sb.append(casaIdentTokElementName); sb.append(">"); sb.append("\r\n");
|
||||
sb.append("<"); sb.append(idElementName); sb.append(">"); sb.append(identityId); sb.append("</"); sb.append(idElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(sourceNameElementName); sb.append(">"); sb.append(sourceName); sb.append("</"); sb.append(sourceNameElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(sourceUrlElementName); sb.append(">"); sb.append(m_sourceUrl); sb.append("</"); sb.append(sourceUrlElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(targetServiceElementName); sb.append(">"); sb.append(m_service); sb.append("</"); sb.append(targetServiceElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(targetHostElementName); sb.append(">"); sb.append(m_host); sb.append("</"); sb.append(targetHostElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(attributesElementName); sb.append(">\r\n");
|
||||
|
||||
// Get the necessary attributes of the specified services in the identity token
|
||||
String[] attributesNeeded = m_idenTokenConfig.getAttributes();
|
||||
@ -580,7 +605,7 @@ public class CasaIdentityToken implements IdentityToken
|
||||
{
|
||||
javax.naming.directory.Attribute attr = (javax.naming.directory.Attribute) ae.next();
|
||||
|
||||
NamingEnumeration enumeration = attr.getAll();
|
||||
NamingEnumeration<?> enumeration = attr.getAll();
|
||||
while (enumeration.hasMore())
|
||||
{
|
||||
Object attrValue = enumeration.next();
|
||||
@ -600,13 +625,13 @@ public class CasaIdentityToken implements IdentityToken
|
||||
if (attrValue instanceof byte[])
|
||||
{
|
||||
// The attribute value is of type byte[], we need to encode it.
|
||||
sb.append("<" + attr.getID() + " type=\"binary\" encoding=\"base64\">" + new String(Base64Coder.encode((byte[]) attrValue)) + "</" + attr.getID() + ">" + "\r\n");
|
||||
sb.append("<"); sb.append(attr.getID()); sb.append(" type=\"binary\" encoding=\"base64\">"); sb.append(new String(Base64Coder.encode((byte[]) attrValue))); sb.append("</"); sb.append(attr.getID()); sb.append(">\r\n");
|
||||
System.err.println("Attribute " + attr.getID() + "included as " + new String(Base64Coder.encode((byte[]) attrValue)));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Assume the attribute value is of type String
|
||||
sb.append("<" + attr.getID() + ">" + (String) attrValue + "</" + attr.getID() + ">" + "\r\n");
|
||||
sb.append("<"); sb.append(attr.getID()); sb.append(">"); sb.append(attrValue); sb.append("</"); sb.append(attr.getID()); sb.append(">\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -628,10 +653,13 @@ public class CasaIdentityToken implements IdentityToken
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Initialize the token object with an ecoded token string.
|
||||
*
|
||||
* @param encodedToken Encoded identity token string.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void initialize (String encodedToken) throws Exception
|
||||
public final void initialize (String encodedToken) throws Exception
|
||||
{
|
||||
// Save copy of the token
|
||||
m_token = Base64Coder.decode(encodedToken);
|
||||
@ -658,13 +686,16 @@ public class CasaIdentityToken implements IdentityToken
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns encoded token string.
|
||||
*
|
||||
* <p>
|
||||
* IMPORTANT: The token string can not contain the substring "]]>"
|
||||
* within it.
|
||||
*
|
||||
* @return Encoded identity token string.
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getEncodedToken () throws Exception
|
||||
public final String getEncodedToken () throws Exception
|
||||
{
|
||||
if (m_token != null)
|
||||
{
|
||||
@ -677,19 +708,25 @@ public class CasaIdentityToken implements IdentityToken
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing our type of identity token provider.
|
||||
*
|
||||
* @return Identity token provider type.
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getProviderType () throws Exception
|
||||
public final String getProviderType () throws Exception
|
||||
{
|
||||
// tbd - Change to a GUID
|
||||
return "CasaIdentityToken";
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the identity id.
|
||||
*
|
||||
* @return Identity identifier.
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getIdentityId () throws Exception
|
||||
public final String getIdentityId () throws Exception
|
||||
{
|
||||
if (m_identityId != null)
|
||||
return m_identityId;
|
||||
@ -700,11 +737,14 @@ public class CasaIdentityToken implements IdentityToken
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the name associated with the
|
||||
* identity source.
|
||||
*
|
||||
* @return Name of the authentication realm.
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getSourceName () throws Exception
|
||||
public final String getSourceName () throws Exception
|
||||
{
|
||||
if (m_sourceName != null)
|
||||
return m_sourceName;
|
||||
@ -715,11 +755,14 @@ public class CasaIdentityToken implements IdentityToken
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the url associated with the
|
||||
* identity source.
|
||||
*
|
||||
* @return Url of the identity data source.
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getSourceUrl () throws Exception
|
||||
public final String getSourceUrl () throws Exception
|
||||
{
|
||||
if (m_sourceUrl != null)
|
||||
return m_sourceUrl;
|
||||
@ -730,10 +773,13 @@ public class CasaIdentityToken implements IdentityToken
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the name of the targeted service.
|
||||
*
|
||||
* @return Name of the targeted service.
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getTargetService () throws Exception
|
||||
public final String getTargetService () throws Exception
|
||||
{
|
||||
if (m_service != null)
|
||||
return m_service;
|
||||
@ -744,11 +790,14 @@ public class CasaIdentityToken implements IdentityToken
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containig the name of the host where the
|
||||
* targeted service resides.
|
||||
*
|
||||
* @return Name of the host where the targeted service resides.
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getTargetHost () throws Exception
|
||||
public final String getTargetHost () throws Exception
|
||||
{
|
||||
if (m_host != null)
|
||||
return m_host;
|
||||
@ -759,10 +808,13 @@ public class CasaIdentityToken implements IdentityToken
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the attributes of the identity.
|
||||
*
|
||||
* @return Identity attributes.
|
||||
* @throws Exception
|
||||
*/
|
||||
public javax.naming.directory.Attributes getAttributes () throws Exception
|
||||
public final javax.naming.directory.Attributes getAttributes () throws Exception
|
||||
{
|
||||
if (m_attributes != null)
|
||||
return m_attributes;
|
||||
|
@ -29,18 +29,18 @@ import java.util.*;
|
||||
|
||||
/**
|
||||
* EnabledSvcsConfig Class.
|
||||
*
|
||||
* <p>
|
||||
* This class obtains and maintains configuration and policy information about
|
||||
* the services enabled to use Authentication Tokens.
|
||||
*
|
||||
*/
|
||||
public class EnabledSvcsConfig
|
||||
public final class EnabledSvcsConfig
|
||||
{
|
||||
private static final String m_authPolicyFileName = "auth.policy";
|
||||
private static final String m_authTokenSettingsFileName = "authtoken.settings";
|
||||
private static final String m_idenTokenSettingsFileName = "identoken.settings";
|
||||
|
||||
private boolean m_enabledSvcsOnly;
|
||||
private final boolean m_enabledSvcsOnly;
|
||||
|
||||
// Default auth policy, authtoken, and identtoken configs.
|
||||
byte[] m_defaultAuthPolicyData = null;
|
||||
@ -48,23 +48,27 @@ public class EnabledSvcsConfig
|
||||
IdenTokenConfig m_defaultIdenTokenConfig = null;
|
||||
|
||||
|
||||
private Map m_hostsMap;
|
||||
private final Map<String,Map<Object, SvcConfigEntry>> m_hostsMap;
|
||||
|
||||
/**
|
||||
* SvcConfigEntry Class.
|
||||
*
|
||||
* <p>
|
||||
* This class is used to maintain the configuration and policy associated with an
|
||||
* enabled service.
|
||||
*
|
||||
*/
|
||||
private class SvcConfigEntry
|
||||
private static final class SvcConfigEntry
|
||||
{
|
||||
protected byte[] m_authPolicyFileData;
|
||||
protected AuthTokenConfig m_authTokenConfig;
|
||||
protected IdenTokenConfig m_idenTokenConfig;
|
||||
protected final byte[] m_authPolicyFileData;
|
||||
protected final AuthTokenConfig m_authTokenConfig;
|
||||
protected final IdenTokenConfig m_idenTokenConfig;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param authPolicyFileData Authentication policy file data.
|
||||
* @param authTokenConfig Authentication token configuration object.
|
||||
* @param idenTokenConfig Identity token configuration object.
|
||||
*/
|
||||
public SvcConfigEntry(byte[] authPolicyFileData,
|
||||
AuthTokenConfig authTokenConfig,
|
||||
@ -76,8 +80,13 @@ public class EnabledSvcsConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param svcConfigPath Path to the service configuration folder.
|
||||
* @param enabledSvcsOnly True if configured to only provide authentication for
|
||||
* configured services.
|
||||
* @throws Exception
|
||||
*/
|
||||
public EnabledSvcsConfig(String svcConfigPath,
|
||||
boolean enabledSvcsOnly) throws Exception
|
||||
@ -88,14 +97,9 @@ public class EnabledSvcsConfig
|
||||
// Remember the enabledSvcsOnly setting
|
||||
m_enabledSvcsOnly = enabledSvcsOnly;
|
||||
|
||||
// Initialize the default auth policy, authtoken, and identtoken configs.
|
||||
byte[] defaultAuthPolicyData = null;
|
||||
AuthTokenConfig defaultAuthTokenConfig = null;
|
||||
IdenTokenConfig defaultIdenTokenConfig = null;
|
||||
|
||||
// Create a map to keep track of the enabled services and their configuration
|
||||
// for each configured host.
|
||||
m_hostsMap = new HashMap();
|
||||
m_hostsMap = new HashMap<String, Map<Object, SvcConfigEntry>>();
|
||||
|
||||
// Get access to the configuration folder for the service
|
||||
File configFolder = new File(svcConfigPath);
|
||||
@ -176,7 +180,7 @@ public class EnabledSvcsConfig
|
||||
if (hostFolderObjs != null)
|
||||
{
|
||||
// Create a Map object to hold the service configurations for this host
|
||||
Map enabledSvcsConfigMap = new HashMap();
|
||||
Map<Object, SvcConfigEntry> enabledSvcsConfigMap = new HashMap<Object, SvcConfigEntry>();
|
||||
|
||||
for (int ii = 0; ii < hostFolderObjs.length; ii++)
|
||||
{
|
||||
@ -295,11 +299,15 @@ public class EnabledSvcsConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns true if the specified service has been enabled to use authentication
|
||||
* tokens.
|
||||
*
|
||||
* @param hostName Name of host where the service resides.
|
||||
* @param serviceName Name of the service.
|
||||
* @return True if the service is enabled.
|
||||
*/
|
||||
public boolean svcEnabled(String hostName, String serviceName)
|
||||
public final boolean svcEnabled(String hostName, String serviceName)
|
||||
{
|
||||
// Always return try if m_enabledSvcsOnly is configured "false" else
|
||||
// check the enabled svcs configuration.
|
||||
@ -311,7 +319,7 @@ public class EnabledSvcsConfig
|
||||
{
|
||||
// First try to obtain the Map of enabled services for the host
|
||||
// tbd - Should we make this case insensitive?
|
||||
Map enabledSvcsConfigMap = (Map) m_hostsMap.get(hostName);
|
||||
Map<Object, SvcConfigEntry> enabledSvcsConfigMap = m_hostsMap.get(hostName);
|
||||
if (enabledSvcsConfigMap != null)
|
||||
{
|
||||
return enabledSvcsConfigMap.containsKey(serviceName);
|
||||
@ -323,21 +331,25 @@ public class EnabledSvcsConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the data associated with the authentication policy file
|
||||
* associated with the specified service.
|
||||
*
|
||||
* @param hostName Name of host where the service resides.
|
||||
* @param serviceName Name of the service.
|
||||
* @return Authentication policy data for the service.
|
||||
*/
|
||||
public byte[] getAuthPolicyFileDataForSvc(String hostName, String serviceName)
|
||||
public final byte[] getAuthPolicyFileDataForSvc(String hostName, String serviceName)
|
||||
{
|
||||
byte[] authPolicyData = null;
|
||||
|
||||
// First try to obtain the Map of enabled services for the host
|
||||
// tbd - Should we make this case insensitive?
|
||||
Map enabledSvcsConfigMap = (Map) m_hostsMap.get(hostName);
|
||||
Map<Object, SvcConfigEntry> enabledSvcsConfigMap = m_hostsMap.get(hostName);
|
||||
if (enabledSvcsConfigMap != null)
|
||||
{
|
||||
// Retrieve SvcConfigEntry for the service from the map for the host
|
||||
SvcConfigEntry svcConfigEntry = (SvcConfigEntry) enabledSvcsConfigMap.get(serviceName);
|
||||
SvcConfigEntry svcConfigEntry = enabledSvcsConfigMap.get(serviceName);
|
||||
if (svcConfigEntry != null)
|
||||
{
|
||||
authPolicyData = svcConfigEntry.m_authPolicyFileData;
|
||||
@ -356,21 +368,25 @@ public class EnabledSvcsConfig
|
||||
return authPolicyData;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the authentication token configuration associated with the
|
||||
* specified service.
|
||||
*
|
||||
* @param hostName Name of host where the service resides.
|
||||
* @param serviceName Name of the service.
|
||||
* @return Authentication token configuration object for the service.
|
||||
*/
|
||||
public AuthTokenConfig getAuthTokenConfig(String hostName, String serviceName)
|
||||
public final AuthTokenConfig getAuthTokenConfig(String hostName, String serviceName)
|
||||
{
|
||||
AuthTokenConfig authTokenConfig = null;
|
||||
|
||||
// First try to obtain the Map of enabled services for the host
|
||||
// tbd - Should we make this case insensitive?
|
||||
Map enabledSvcsConfigMap = (Map) m_hostsMap.get(hostName);
|
||||
Map<Object, SvcConfigEntry> enabledSvcsConfigMap = m_hostsMap.get(hostName);
|
||||
if (enabledSvcsConfigMap != null)
|
||||
{
|
||||
// Retrieve SvcConfigEntry for the service from the map for the host
|
||||
SvcConfigEntry svcConfigEntry = (SvcConfigEntry) enabledSvcsConfigMap.get(serviceName);
|
||||
SvcConfigEntry svcConfigEntry = enabledSvcsConfigMap.get(serviceName);
|
||||
if (svcConfigEntry != null)
|
||||
{
|
||||
authTokenConfig = svcConfigEntry.m_authTokenConfig;
|
||||
@ -388,21 +404,25 @@ public class EnabledSvcsConfig
|
||||
return authTokenConfig;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the identity token configuration associated with the
|
||||
* specified service.
|
||||
*
|
||||
* @param hostName Name of host where the service resides.
|
||||
* @param serviceName Name of the service.
|
||||
* @return Identity token configuration object for the specified service.
|
||||
*/
|
||||
public IdenTokenConfig getIdenTokenConfig(String hostName, String serviceName)
|
||||
public final IdenTokenConfig getIdenTokenConfig(String hostName, String serviceName)
|
||||
{
|
||||
IdenTokenConfig idenTokenConfig = null;
|
||||
|
||||
// First try to obtain the Map of enabled services for the host
|
||||
// tbd - Should we make this case insensitive?
|
||||
Map enabledSvcsConfigMap = (Map) m_hostsMap.get(hostName);
|
||||
Map<Object, SvcConfigEntry> enabledSvcsConfigMap = m_hostsMap.get(hostName);
|
||||
if (enabledSvcsConfigMap != null)
|
||||
{
|
||||
// Retrieve SvcConfigEntry for the service from the map for the host
|
||||
SvcConfigEntry svcConfigEntry = (SvcConfigEntry) enabledSvcsConfigMap.get(serviceName);
|
||||
SvcConfigEntry svcConfigEntry = enabledSvcsConfigMap.get(serviceName);
|
||||
if (svcConfigEntry != null)
|
||||
{
|
||||
idenTokenConfig = svcConfigEntry.m_idenTokenConfig;
|
||||
|
@ -26,30 +26,33 @@ package com.novell.casa.authtoksvc;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* GetAuthPolicy Class.
|
||||
*
|
||||
* <p>
|
||||
* This class processes get authentication policy requests for a particular
|
||||
* service.
|
||||
*
|
||||
*/
|
||||
public class GetAuthPolicy implements RpcMethod
|
||||
public final class GetAuthPolicy implements RpcMethod
|
||||
{
|
||||
private SvcConfig m_svcConfig;
|
||||
private EnabledSvcsConfig m_enabledSvcsConfig;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public GetAuthPolicy() throws Exception
|
||||
public GetAuthPolicy()
|
||||
{
|
||||
// Nothing to do at this time
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Initialize the Rpc method.
|
||||
*
|
||||
* @param svcConfig Service configuration object.
|
||||
* @param enabledSvcsConfig Enabled services configuration object.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void init(SvcConfig svcConfig, EnabledSvcsConfig enabledSvcsConfig) throws Exception
|
||||
{
|
||||
@ -57,8 +60,12 @@ public class GetAuthPolicy implements RpcMethod
|
||||
m_enabledSvcsConfig = enabledSvcsConfig;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Process Rpc.
|
||||
*
|
||||
* @param inStream Input stream with request.
|
||||
* @param out Ouput print writer for reply.
|
||||
* @throws IOException
|
||||
*/
|
||||
public void invoke(InputStream inStream, PrintWriter out) throws IOException
|
||||
{
|
||||
@ -122,8 +129,10 @@ public class GetAuthPolicy implements RpcMethod
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Return the method id.
|
||||
*
|
||||
* @return Method id.
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
|
@ -33,19 +33,19 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
/**
|
||||
* GetAuthPolicyReqMsg Class.
|
||||
*
|
||||
* <p>
|
||||
* This class deals with the message sent by Casa Client when requesting
|
||||
* authenication policy to authenticate an entity to a particular service.
|
||||
* The format of the the message is as follows:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <get_auth_policy_req>
|
||||
* <service>service name</service>
|
||||
* <host>host name</host>
|
||||
* </get_auth_policy_req>
|
||||
* <p>
|
||||
* <?xml version="1.0" encoding="UTF-8"?>
|
||||
* <get_auth_policy_req>
|
||||
* <service>service name</service>
|
||||
* <host>host name</host>
|
||||
* </get_auth_policy_req>
|
||||
*
|
||||
*/
|
||||
public class GetAuthPolicyReqMsg
|
||||
public final class GetAuthPolicyReqMsg
|
||||
{
|
||||
|
||||
protected String m_serviceName = null;
|
||||
@ -54,7 +54,7 @@ public class GetAuthPolicyReqMsg
|
||||
/*
|
||||
* Class for handling GetAuthPolicyReq msg parsing events.
|
||||
*/
|
||||
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
private final class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
{
|
||||
private final static int AWAITING_ROOT_ELEMENT_START = 0;
|
||||
private final static int AWAITING_ROOT_ELEMENT_END = 1;
|
||||
@ -66,25 +66,29 @@ public class GetAuthPolicyReqMsg
|
||||
private final static int AWAITING_HOST_DATA = 7;
|
||||
private final static int DONE_PARSING = 8;
|
||||
|
||||
private GetAuthPolicyReqMsg m_GetAuthPolicyReqMsg;
|
||||
private final GetAuthPolicyReqMsg m_GetAuthPolicyReqMsg;
|
||||
private int m_state;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param getAuthPolicyReqMsg Get authentication policy request message object.
|
||||
*/
|
||||
public SAXHandler (GetAuthPolicyReqMsg GetAuthPolicyReqMsg)
|
||||
public SAXHandler (GetAuthPolicyReqMsg getAuthPolicyReqMsg)
|
||||
{
|
||||
super();
|
||||
|
||||
// Initialize our members
|
||||
m_GetAuthPolicyReqMsg = GetAuthPolicyReqMsg;
|
||||
m_GetAuthPolicyReqMsg = getAuthPolicyReqMsg;
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* endDocument() implementation.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endDocument () throws SAXException
|
||||
public final void endDocument () throws SAXException
|
||||
{
|
||||
// Verify that we obtained all of the required elements
|
||||
if (m_state != DONE_PARSING)
|
||||
@ -96,8 +100,14 @@ public class GetAuthPolicyReqMsg
|
||||
|
||||
/*
|
||||
* startElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @param atts Attributes.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
public final void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -151,10 +161,15 @@ public class GetAuthPolicyReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* endElement() immplementation.
|
||||
/**
|
||||
* endElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endElement (String uri, String name, String qName) throws SAXException
|
||||
public final void endElement (String uri, String name, String qName) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -207,10 +222,15 @@ public class GetAuthPolicyReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* character() implementation.
|
||||
*
|
||||
* @param ch Characters with element data.
|
||||
* @param start Start position in the character array.
|
||||
* @param length Number of characters to use in the array.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void characters (char ch[], int start, int length) throws SAXException
|
||||
public final void characters (char ch[], int start, int length) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -248,8 +268,11 @@ public class GetAuthPolicyReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param inStream Input stream with get authentication policy request message.
|
||||
* @throws Exception
|
||||
*/
|
||||
public GetAuthPolicyReqMsg (InputStream inStream) throws Exception
|
||||
{
|
||||
@ -271,18 +294,22 @@ public class GetAuthPolicyReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Method to get the service name.
|
||||
/**
|
||||
* Method to get the service name.
|
||||
*
|
||||
* @return Service name.
|
||||
*/
|
||||
public String getServiceName() throws Exception
|
||||
public String getServiceName()
|
||||
{
|
||||
return m_serviceName;
|
||||
}
|
||||
|
||||
/*
|
||||
* Method to get the host name.
|
||||
/**
|
||||
* Method to get the host name.
|
||||
*
|
||||
* @return Host name.
|
||||
*/
|
||||
public String getHostName() throws Exception
|
||||
public String getHostName()
|
||||
{
|
||||
return m_hostName;
|
||||
}
|
||||
|
@ -26,83 +26,90 @@ package com.novell.casa.authtoksvc;
|
||||
|
||||
/**
|
||||
* GetAuthPolicyRespMsg Class.
|
||||
*
|
||||
* <p>
|
||||
* This class deals with the message sent to the Casa Client as a
|
||||
* response to a get authentication token request. The format of
|
||||
* the message is as follows when the response includes an
|
||||
* authentication token:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <get_auth_policy_resp>
|
||||
* <status><description>OK</description>200</status>
|
||||
* <auth_policy>authentication policy data</auth_policy>
|
||||
* </get_auth_policy_resp>
|
||||
*
|
||||
* <p>
|
||||
* <?xml version="1.0" encoding="UTF-8"?>
|
||||
* <get_auth_policy_resp>
|
||||
* <status><description>OK</description>200</status>
|
||||
* <auth_policy>authentication policy data</auth_policy>
|
||||
* </get_auth_policy_resp>
|
||||
* <p>
|
||||
* The format of the message is as follows when the response does not
|
||||
* include an authentication token.
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <get_auth_policy_resp>
|
||||
* <status><description>status description</description>status code</status>
|
||||
* </get_auth_policy_resp>
|
||||
*
|
||||
* <p>
|
||||
* <?xml version="1.0" encoding="UTF-8"?>
|
||||
* <get_auth_policy_resp>
|
||||
* <status><description>status description</description>status code</status>
|
||||
* </get_auth_policy_resp>
|
||||
* <p>
|
||||
* Plase note that the protocol utilizes the status codes defined
|
||||
* in the HTTP 1.1 Specification.
|
||||
*
|
||||
*/
|
||||
public class GetAuthPolicyRespMsg
|
||||
public final class GetAuthPolicyRespMsg
|
||||
{
|
||||
|
||||
String m_msg;
|
||||
final String m_msg;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor for a msg that does not include the authentication policy.
|
||||
*
|
||||
* @param statusDescription Status code description.
|
||||
* @param statusCode Status code.
|
||||
*/
|
||||
public GetAuthPolicyRespMsg (
|
||||
String statusDescription,
|
||||
String statusCode) throws Exception
|
||||
public GetAuthPolicyRespMsg (String statusDescription,
|
||||
String statusCode)
|
||||
{
|
||||
// Get a StringBuffer to help us with the construction of the message
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
// Start building the message
|
||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||
sb.append("<" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
|
||||
sb.append("<" + ProtoDefs.statusElementName + ">"
|
||||
+ "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
|
||||
+ statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
||||
sb.append("</" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
|
||||
sb.append(ProtoDefs.xmlDeclaration); sb.append("\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.getAuthPolicyResponseElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.statusElementName); sb.append(">");
|
||||
sb.append("<"); sb.append(ProtoDefs.descriptionElementName); sb.append(">"); sb.append(statusDescription); sb.append("</"); sb.append(ProtoDefs.descriptionElementName); sb.append(">");
|
||||
sb.append(statusCode); sb.append("</"); sb.append(ProtoDefs.statusElementName); sb.append(">\r\n");
|
||||
sb.append("</"); sb.append(ProtoDefs.getAuthPolicyResponseElementName); sb.append(">\r\n");
|
||||
|
||||
// The message has now been built, save it.
|
||||
m_msg = sb.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor for a msg that includes the authentication policy.
|
||||
*
|
||||
* @param statusDescription Status code description.
|
||||
* @param statusCode Status code.
|
||||
* @param authPolicy Authentication policy data.
|
||||
*/
|
||||
public GetAuthPolicyRespMsg (
|
||||
String statusDescription,
|
||||
String statusCode,
|
||||
String authPolicy) throws Exception
|
||||
public GetAuthPolicyRespMsg (String statusDescription,
|
||||
String statusCode,
|
||||
String authPolicy)
|
||||
{
|
||||
// Get a StringBuffer to help us with the construction of the message
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
// Start building the message
|
||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||
sb.append("<" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
|
||||
sb.append("<" + ProtoDefs.statusElementName + ">"
|
||||
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">"
|
||||
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
||||
sb.append("<" + ProtoDefs.authPolicyElementName + ">" + authPolicy + "</" + ProtoDefs.authPolicyElementName + ">" + "\r\n");
|
||||
sb.append("</" + ProtoDefs.getAuthPolicyResponseElementName + ">" + "\r\n");
|
||||
sb.append(ProtoDefs.xmlDeclaration); sb.append("\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.getAuthPolicyResponseElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.statusElementName); sb.append(">");
|
||||
sb.append("<"); sb.append(ProtoDefs.descriptionElementName); sb.append(">"); sb.append(ProtoDefs.httpOkStatusMsg); sb.append("</"); sb.append(ProtoDefs.descriptionElementName); sb.append(">");
|
||||
sb.append(ProtoDefs.httpOkStatusCode); sb.append("</"); sb.append(ProtoDefs.statusElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.authPolicyElementName); sb.append(">"); sb.append(authPolicy); sb.append("</"); sb.append(ProtoDefs.authPolicyElementName); sb.append(">\r\n");
|
||||
sb.append("</"); sb.append(ProtoDefs.getAuthPolicyResponseElementName); sb.append(">\r\n");
|
||||
|
||||
// The message has now been built, save it.
|
||||
m_msg = sb.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the GetAuthPolicyRespMsg.
|
||||
*
|
||||
* @return Get authentication policy response message string.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
|
@ -33,30 +33,30 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
/**
|
||||
* GetAuthTokReqMsg Class.
|
||||
*
|
||||
* <p>
|
||||
* This class deals with the message sent by Casa Client when requesting
|
||||
* a token to authenticate an entity to a particular service. The format of
|
||||
* the message is as follows:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <get_auth_token_req>
|
||||
* <service>service name</service>
|
||||
* <host>host name</host>
|
||||
* <session_token>session token data</session_token>
|
||||
* </get_auth_token_req>
|
||||
*
|
||||
* <p>
|
||||
* <?xml version="1.0" encoding="UTF-8"?>
|
||||
* <get_auth_token_req>
|
||||
* <service>service name</service>
|
||||
* <host>host name</host>
|
||||
* <session_token>session token data</session_token>
|
||||
* </get_auth_token_req>
|
||||
* <p>
|
||||
*/
|
||||
public class GetAuthTokReqMsg
|
||||
public final class GetAuthTokReqMsg
|
||||
{
|
||||
|
||||
protected String m_serviceName = null;
|
||||
protected String m_hostName = null;
|
||||
protected String m_sessionToken = null;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Class for handling GetAuthTokReq msg parsing events.
|
||||
*/
|
||||
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
private final class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
{
|
||||
private final static int AWAITING_ROOT_ELEMENT_START = 0;
|
||||
private final static int AWAITING_ROOT_ELEMENT_END = 1;
|
||||
@ -71,25 +71,29 @@ public class GetAuthTokReqMsg
|
||||
private final static int AWAITING_SESSION_TOKEN_DATA = 10;
|
||||
private final static int DONE_PARSING = 11;
|
||||
|
||||
private GetAuthTokReqMsg m_GetAuthTokReqMsg;
|
||||
private final GetAuthTokReqMsg m_GetAuthTokReqMsg;
|
||||
private int m_state;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param getAuthTokReqMsg Get authentication token request message object.
|
||||
*/
|
||||
public SAXHandler (GetAuthTokReqMsg GetAuthTokReqMsg)
|
||||
public SAXHandler (GetAuthTokReqMsg getAuthTokReqMsg)
|
||||
{
|
||||
super();
|
||||
|
||||
// Initialize our members
|
||||
m_GetAuthTokReqMsg = GetAuthTokReqMsg;
|
||||
m_GetAuthTokReqMsg = getAuthTokReqMsg;
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* endDocument() implementation.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endDocument () throws SAXException
|
||||
public final void endDocument () throws SAXException
|
||||
{
|
||||
// Verify that we obtained all of the required elements
|
||||
if (m_state != DONE_PARSING)
|
||||
@ -99,10 +103,16 @@ public class GetAuthTokReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* startElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @param atts Attributes.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
public final void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -170,10 +180,15 @@ public class GetAuthTokReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* endElement() immplementation.
|
||||
/**
|
||||
* endElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endElement (String uri, String name, String qName) throws SAXException
|
||||
public final void endElement (String uri, String name, String qName) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -240,10 +255,15 @@ public class GetAuthTokReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* character() implementation.
|
||||
*
|
||||
* @param ch Characters with element data.
|
||||
* @param start Start position in the character array.
|
||||
* @param length Number of characters to use in the array.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void characters (char ch[], int start, int length) throws SAXException
|
||||
public final void characters (char ch[], int start, int length) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -294,8 +314,11 @@ public class GetAuthTokReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param inStream Input stream with get authentication token request message.
|
||||
* @throws Exception
|
||||
*/
|
||||
public GetAuthTokReqMsg (InputStream inStream) throws Exception
|
||||
{
|
||||
@ -317,26 +340,32 @@ public class GetAuthTokReqMsg
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Method to get the service name.
|
||||
/**
|
||||
* Method to get the service name.
|
||||
*
|
||||
* @return Service name.
|
||||
*/
|
||||
public String getServiceName() throws Exception
|
||||
public String getServiceName()
|
||||
{
|
||||
return m_serviceName;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Method to get the host name.
|
||||
*
|
||||
* @return Host name.
|
||||
*/
|
||||
public String getHostName() throws Exception
|
||||
public String getHostName()
|
||||
{
|
||||
return m_hostName;
|
||||
}
|
||||
|
||||
/*
|
||||
* Method to get the session token.
|
||||
/**
|
||||
* Method to get the session token.
|
||||
*
|
||||
* @return Session token string.
|
||||
*/
|
||||
public String getSessionToken() throws Exception
|
||||
public String getSessionToken()
|
||||
{
|
||||
return m_sessionToken;
|
||||
}
|
||||
|
@ -26,86 +26,94 @@ package com.novell.casa.authtoksvc;
|
||||
|
||||
/**
|
||||
* GetAuthTokRespMsg Class.
|
||||
*
|
||||
* <p>
|
||||
* This class deals with the message sent to the Casa Client as a
|
||||
* response to a get authentication token request. The format of
|
||||
* the message is as follows when the response includes an
|
||||
* authentication token:
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <get_auth_tok_resp>
|
||||
* <status><description>OK</description>200</status>
|
||||
* <auth_token><lifetime>lifetime value</lifetime>authentication token data</auth_token>
|
||||
* </get_auth_tok_resp>
|
||||
*
|
||||
* <p>
|
||||
* <?xml version="1.0" encoding="UTF-8"?>
|
||||
* <get_auth_tok_resp>
|
||||
* <status><description>OK</description>200</status>
|
||||
* <auth_token><lifetime>lifetime value</lifetime>authentication token data</auth_token>
|
||||
* </get_auth_tok_resp>
|
||||
* <p>
|
||||
* The format of the message is as follows when the response does not
|
||||
* include an authentication token.
|
||||
*
|
||||
* <?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
* <get_auth_tok_resp>
|
||||
* <status><description>status description</description>status code</status>
|
||||
* </get_auth_tok_resp>
|
||||
*
|
||||
* <p>
|
||||
* <?xml version="1.0" encoding="UTF-8"?>
|
||||
* <get_auth_tok_resp>
|
||||
* <status><description>status description</description>status code</status>
|
||||
* </get_auth_tok_resp>
|
||||
* <p>
|
||||
* Plase note that the protocol utilizes the status codes defined
|
||||
* in the HTTP 1.1 Specification.
|
||||
*
|
||||
*/
|
||||
public class GetAuthTokRespMsg
|
||||
public final class GetAuthTokRespMsg
|
||||
{
|
||||
|
||||
String m_msg;
|
||||
final String m_msg;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor for a msg that does not include the authentication token.
|
||||
*
|
||||
* @param statusDescription Status code description.
|
||||
* @param statusCode Status code.
|
||||
*/
|
||||
public GetAuthTokRespMsg (
|
||||
String statusDescription,
|
||||
String statusCode) throws Exception
|
||||
public GetAuthTokRespMsg (String statusDescription,
|
||||
String statusCode)
|
||||
{
|
||||
// Get a StringBuffer to help us with the construction of the message
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
// Start building the message
|
||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||
sb.append("<" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
|
||||
sb.append("<" + ProtoDefs.statusElementName + ">"
|
||||
+ "<" + ProtoDefs.descriptionElementName + ">" + statusDescription + "</" + ProtoDefs.descriptionElementName + ">"
|
||||
+ statusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
||||
sb.append("</" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
|
||||
sb.append(ProtoDefs.xmlDeclaration); sb.append("\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.getAuthTokResponseElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.statusElementName); sb.append(">");
|
||||
sb.append("<"); sb.append(ProtoDefs.descriptionElementName); sb.append(">"); sb.append(statusDescription); sb.append("</"); sb.append(ProtoDefs.descriptionElementName); sb.append(">");
|
||||
sb.append(statusCode); sb.append("</"); sb.append(ProtoDefs.statusElementName); sb.append(">\r\n");
|
||||
sb.append("</"); sb.append(ProtoDefs.getAuthTokResponseElementName); sb.append(">\r\n");
|
||||
|
||||
// The message has now been built, save it.
|
||||
m_msg = sb.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor for a msg that includes the authentication token.
|
||||
*
|
||||
* @param statusDescription Status code description.
|
||||
* @param statusCode Status code.
|
||||
* @param authToken Authentication token string.
|
||||
* @param authTokenLifetime Authentication token lifetime.
|
||||
*/
|
||||
public GetAuthTokRespMsg (
|
||||
String statusDescription,
|
||||
String statusCode,
|
||||
String authToken,
|
||||
String authTokenLifetime) throws Exception
|
||||
public GetAuthTokRespMsg (String statusDescription,
|
||||
String statusCode,
|
||||
String authToken,
|
||||
String authTokenLifetime)
|
||||
{
|
||||
// Get a StringBuffer to help us with the construction of the message
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
// Start building the message
|
||||
sb.append(ProtoDefs.xmlDeclaration + "\r\n");
|
||||
sb.append("<" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
|
||||
sb.append("<" + ProtoDefs.statusElementName + ">"
|
||||
+ "<" + ProtoDefs.descriptionElementName + ">" + ProtoDefs.httpOkStatusMsg + "</" + ProtoDefs.descriptionElementName + ">"
|
||||
+ ProtoDefs.httpOkStatusCode + "</" + ProtoDefs.statusElementName + ">" + "\r\n");
|
||||
sb.append("<" + ProtoDefs.authTokenElementName + ">"
|
||||
+ "<" + ProtoDefs.lifetimeElementName + ">" + authTokenLifetime + "</" + ProtoDefs.lifetimeElementName + ">"
|
||||
+ authToken + "</" + ProtoDefs.authTokenElementName + ">" + "\r\n");
|
||||
sb.append("</" + ProtoDefs.getAuthTokResponseElementName + ">" + "\r\n");
|
||||
sb.append(ProtoDefs.xmlDeclaration); sb.append("\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.getAuthTokResponseElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.statusElementName); sb.append(">");
|
||||
sb.append("<"); sb.append(ProtoDefs.descriptionElementName); sb.append(">"); sb.append(ProtoDefs.httpOkStatusMsg); sb.append("</"); sb.append(ProtoDefs.descriptionElementName); sb.append(">");
|
||||
sb.append(ProtoDefs.httpOkStatusCode); sb.append("</"); sb.append(ProtoDefs.statusElementName); sb.append(">\r\n");
|
||||
sb.append("<"); sb.append(ProtoDefs.authTokenElementName); sb.append(">");
|
||||
sb.append("<"); sb.append(ProtoDefs.lifetimeElementName); sb.append(">"); sb.append(authTokenLifetime); sb.append("</"); sb.append(ProtoDefs.lifetimeElementName); sb.append(">");
|
||||
sb.append(authToken); sb.append("</"); sb.append(ProtoDefs.authTokenElementName); sb.append(">\r\n");
|
||||
sb.append("</"); sb.append(ProtoDefs.getAuthTokResponseElementName); sb.append(">\r\n");
|
||||
|
||||
// The message has now been built, save it.
|
||||
m_msg = sb.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the GetAuthTokRespMsg.
|
||||
*
|
||||
* @return Get authentication token response message string.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
|
@ -30,37 +30,45 @@ import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* GetAuthToken Class.
|
||||
*
|
||||
* <p>
|
||||
* This class processes requests for tokens to authenticate an entity
|
||||
* to a particular service.
|
||||
*
|
||||
*/
|
||||
public class GetAuthToken implements RpcMethod
|
||||
public final class GetAuthToken implements RpcMethod
|
||||
{
|
||||
private SvcConfig m_svcConfig;
|
||||
private EnabledSvcsConfig m_enabledSvcsConfig;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public GetAuthToken() throws Exception
|
||||
public GetAuthToken()
|
||||
{
|
||||
// Nothing to do at this time
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Initialize the Rpc method.
|
||||
*
|
||||
* @param svcConfig Service configuration object.
|
||||
* @param enabledSvcsConfig Enabled services configuration object.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void init(SvcConfig svcConfig, EnabledSvcsConfig enabledSvcsConfig) throws Exception
|
||||
public final void init(SvcConfig svcConfig, EnabledSvcsConfig enabledSvcsConfig) throws Exception
|
||||
{
|
||||
m_svcConfig = svcConfig;
|
||||
m_enabledSvcsConfig = enabledSvcsConfig;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Process Rpc.
|
||||
*
|
||||
* @param inStream Input stream with request.
|
||||
* @param out Ouput print writer for reply.
|
||||
* @throws IOException
|
||||
*/
|
||||
public void invoke(InputStream inStream, PrintWriter out) throws IOException
|
||||
public final void invoke(InputStream inStream, PrintWriter out) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -136,10 +144,12 @@ public class GetAuthToken implements RpcMethod
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Return the method id.
|
||||
*
|
||||
* @return Method id.
|
||||
*/
|
||||
public String getId()
|
||||
public final String getId()
|
||||
{
|
||||
return "GetAuthToken";
|
||||
}
|
||||
|
@ -34,27 +34,27 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
/**
|
||||
* IdenTokenConfig Class.
|
||||
*
|
||||
* <p>
|
||||
* This class obtains and maintains identity token configuration.
|
||||
*
|
||||
*/
|
||||
public class IdenTokenConfig
|
||||
public final class IdenTokenConfig
|
||||
{
|
||||
// Well known identity token configuration settings
|
||||
public final static String EncryptAttributes = "EncryptAttributes";
|
||||
public final static String Attributes = "Attributes";
|
||||
|
||||
// Default configuration values
|
||||
private String m_defaultEncryptAttributesValue = "false";
|
||||
private String m_defaultAttributesValue = "sn";
|
||||
private final String m_defaultEncryptAttributesValue = "false";
|
||||
private final String m_defaultAttributesValue = "sn";
|
||||
|
||||
private Map m_tokenSettingsMap;
|
||||
private final Map<String,String> m_tokenSettingsMap;
|
||||
private String[] m_identityAttributes;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Class for handling parsing events.
|
||||
*/
|
||||
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
private static final class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
{
|
||||
private final static int AWAITING_ROOT_ELEMENT_START = 0;
|
||||
private final static int AWAITING_SETTING_ELEMENT_START = 1;
|
||||
@ -64,14 +64,16 @@ public class IdenTokenConfig
|
||||
|
||||
private final static String m_rootElementName = "settings";
|
||||
|
||||
private Map m_keyMap;
|
||||
private final Map<String,String> m_keyMap;
|
||||
private int m_state;
|
||||
private String m_currentKey;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param keyMap Key/Value map.
|
||||
*/
|
||||
public SAXHandler(Map keyMap)
|
||||
public SAXHandler(Map<String,String> keyMap)
|
||||
{
|
||||
super();
|
||||
|
||||
@ -80,10 +82,12 @@ public class IdenTokenConfig
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* endDocument() implementation.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endDocument () throws SAXException
|
||||
public final void endDocument () throws SAXException
|
||||
{
|
||||
// Verify that we are not in an invalid state
|
||||
if (m_state != DONE_PARSING)
|
||||
@ -93,10 +97,16 @@ public class IdenTokenConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* startElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @param atts Attributes.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
public final void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -129,10 +139,15 @@ public class IdenTokenConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* endElement() immplementation.
|
||||
/**
|
||||
* endElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endElement (String uri, String name, String qName) throws SAXException
|
||||
public final void endElement (String uri, String name, String qName) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -163,10 +178,15 @@ public class IdenTokenConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* character() implementation.
|
||||
*
|
||||
* @param ch Characters with element data.
|
||||
* @param start Start position in the character array.
|
||||
* @param length Number of characters to use in the array.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void characters (char ch[], int start, int length) throws SAXException
|
||||
public final void characters (char ch[], int start, int length) throws SAXException
|
||||
{
|
||||
// Consume the data if in the right state
|
||||
if (m_state == AWAITING_SETTING_ELEMENT_DATA)
|
||||
@ -181,29 +201,32 @@ public class IdenTokenConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor which sets default configuration values.
|
||||
*/
|
||||
public IdenTokenConfig() throws Exception
|
||||
public IdenTokenConfig()
|
||||
{
|
||||
System.err.println("IdenTokenConfig()- Default");
|
||||
|
||||
// Create a map to keep track of the token settings
|
||||
m_tokenSettingsMap = new HashMap();
|
||||
m_tokenSettingsMap = new HashMap<String, String>();
|
||||
|
||||
// Set the default settings in our map
|
||||
m_tokenSettingsMap.put(Attributes, m_defaultAttributesValue);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param idenTokenSettingsFileName Name of identity token settings file.
|
||||
* @throws Exception
|
||||
*/
|
||||
public IdenTokenConfig(String idenTokenSettingsFileName) throws Exception
|
||||
{
|
||||
System.err.println("IdenTokenConfig()-");
|
||||
|
||||
// Create a map to keep track of the token settings
|
||||
m_tokenSettingsMap = new HashMap();
|
||||
m_tokenSettingsMap = new HashMap<String, String>();
|
||||
|
||||
try
|
||||
{
|
||||
@ -228,7 +251,7 @@ public class IdenTokenConfig
|
||||
System.err.println("IdenTokenConfig()- Attributes not configured, defaulting them.");
|
||||
m_tokenSettingsMap.put(Attributes, m_defaultAttributesValue);
|
||||
}
|
||||
String attributes = (String) m_tokenSettingsMap.get(Attributes);
|
||||
String attributes = m_tokenSettingsMap.get(Attributes);
|
||||
m_identityAttributes = attributes.split(",");
|
||||
}
|
||||
catch (SAXException e)
|
||||
@ -253,13 +276,16 @@ public class IdenTokenConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the value associated with the specified setting.
|
||||
*
|
||||
* @param settingName Name of the setting.
|
||||
* @return Value of the specified setting.
|
||||
*/
|
||||
public String getSetting(String settingName) throws Exception
|
||||
public final String getSetting(String settingName)
|
||||
{
|
||||
// Try to find the setting in our map
|
||||
String value = (String) m_tokenSettingsMap.get(settingName);
|
||||
String value = m_tokenSettingsMap.get(settingName);
|
||||
if (value == null)
|
||||
{
|
||||
System.err.println("IdenTokenConfig.getSetting()- Did not find setting " + settingName);
|
||||
@ -284,10 +310,12 @@ public class IdenTokenConfig
|
||||
return value;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the identity attributes that must be included in the token.
|
||||
*
|
||||
* @return Identity Attributes.
|
||||
*/
|
||||
public String[] getAttributes() throws Exception
|
||||
public final String[] getAttributes()
|
||||
{
|
||||
return m_identityAttributes;
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ package com.novell.casa.authtoksvc;
|
||||
*
|
||||
* Class for the creation and editing of identtoken.settings files.
|
||||
*
|
||||
**/
|
||||
public class IdenTokenSettingsEditor implements IVerifySetting
|
||||
*/
|
||||
public final class IdenTokenSettingsEditor implements IVerifySetting
|
||||
{
|
||||
private static final String usage =
|
||||
"usage: IdenTokenSettingsEditor -op [settingName [settingValue]] -file settingsFilePath\n\n" +
|
||||
@ -103,9 +103,9 @@ public class IdenTokenSettingsEditor implements IVerifySetting
|
||||
|
||||
|
||||
/**
|
||||
* Applications Entry Point
|
||||
* Applications Entry Point.
|
||||
*
|
||||
* @param args
|
||||
* @param args Arguments.
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
|
@ -24,15 +24,22 @@
|
||||
|
||||
package com.novell.casa.authtoksvc;
|
||||
|
||||
/*
|
||||
/**
|
||||
* IdentityToken Interface.
|
||||
*
|
||||
* <p>
|
||||
* This is the interface implemented by Identity Token Providers.
|
||||
*/
|
||||
public interface IdentityToken
|
||||
{
|
||||
/*
|
||||
/**
|
||||
* Initialize the token with parameters.
|
||||
*
|
||||
* @param identityId Identity identifier.
|
||||
* @param sourceName Name of the realm where the identityId is valid.
|
||||
* @param targetService Name of service being targeted.
|
||||
* @param targetHost Host where the targeted service resides.
|
||||
* @param svcConfig Service configuration object.
|
||||
* @throws Exception
|
||||
*/
|
||||
void initialize(String identityId,
|
||||
String sourceName,
|
||||
@ -40,54 +47,81 @@ public interface IdentityToken
|
||||
String targetHost,
|
||||
SvcConfig svcConfig) throws Exception;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Initialize the token object with encoded token string.
|
||||
*
|
||||
* @param encodedToken Encoded identity token string.
|
||||
* @throws Exception
|
||||
*/
|
||||
void initialize(String encodedToken) throws Exception;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns encoded token string.
|
||||
*
|
||||
* IMPORTANT: The token string can not contain the substring "]]>"
|
||||
* within it.
|
||||
*
|
||||
* @return Encoded identity token string.
|
||||
* @throws Exception
|
||||
*/
|
||||
String getEncodedToken() throws Exception;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the identity token provider type.
|
||||
*
|
||||
* @return Identity token provider type.
|
||||
* @throws Exception
|
||||
*/
|
||||
String getProviderType() throws Exception;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the identity id.
|
||||
*
|
||||
* @return Identity identifier.
|
||||
* @throws Exception
|
||||
*/
|
||||
String getIdentityId() throws Exception;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the name associated with the
|
||||
* identity source.
|
||||
*
|
||||
* @return Name of the authentication realm.
|
||||
* @throws Exception
|
||||
*/
|
||||
String getSourceName() throws Exception;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the url associated with the
|
||||
* identity source.
|
||||
*
|
||||
* @return Url of the identity data source.
|
||||
* @throws Exception
|
||||
*/
|
||||
String getSourceUrl() throws Exception;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the name of the targeted service.
|
||||
*
|
||||
* @return Name of the targeted service.
|
||||
* @throws Exception
|
||||
*/
|
||||
String getTargetService() throws Exception;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containig the name of the host where the
|
||||
* targeted service resides.
|
||||
*
|
||||
* @return Name of the host where the targeted service resides.
|
||||
* @throws Exception
|
||||
*/
|
||||
String getTargetHost() throws Exception;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the attributes of the identity.
|
||||
*
|
||||
* @return Identity attributes.
|
||||
* @throws Exception
|
||||
*/
|
||||
javax.naming.directory.Attributes getAttributes() throws Exception;
|
||||
}
|
||||
|
@ -25,17 +25,11 @@
|
||||
package com.novell.casa.authtoksvc;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.BasicAttribute;
|
||||
import javax.naming.directory.BasicAttributes;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
import javax.naming.directory.SearchResult;
|
||||
@ -53,13 +47,13 @@ import org.bandit.util.config.Realm;
|
||||
|
||||
/**
|
||||
* Krb5Authenticate Class.
|
||||
*
|
||||
* <p>
|
||||
* This class implementes an authentication mechanism for
|
||||
* the processing of authentication requests utilizing a
|
||||
* Kerberos5 token.
|
||||
*
|
||||
*/
|
||||
public class Krb5Authenticate implements AuthMechanism, Serializable
|
||||
public final class Krb5Authenticate implements AuthMechanism, Serializable
|
||||
{
|
||||
private SvcConfig m_svcConfig;
|
||||
private AuthMechConfig m_mechConfig;
|
||||
@ -72,17 +66,23 @@ public class Krb5Authenticate implements AuthMechanism, Serializable
|
||||
protected GSSName m_svcName;
|
||||
protected GSSCredential m_credential;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Krb5 Token Class.
|
||||
*/
|
||||
private class Krb5Token
|
||||
private final class Krb5Token
|
||||
{
|
||||
private String m_principalName = "";
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* The format of the Krb5 token is as follows:
|
||||
*
|
||||
* <p>
|
||||
* Base64.encode(GSS-API Token data));
|
||||
*
|
||||
* @param encodedToken Base64 encoded GSS-API token.
|
||||
* @param parent Associated Krb5Authenticate object.
|
||||
* @throws Exception
|
||||
*/
|
||||
public Krb5Token(String encodedToken, Krb5Authenticate parent) throws Exception
|
||||
{
|
||||
@ -112,8 +112,10 @@ public class Krb5Authenticate implements AuthMechanism, Serializable
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the name of the authenticated principal
|
||||
/**
|
||||
* Returns the name of the authenticated principal.
|
||||
*
|
||||
* @return Principal name.
|
||||
*/
|
||||
public String getPrincipalName()
|
||||
{
|
||||
@ -121,18 +123,22 @@ public class Krb5Authenticate implements AuthMechanism, Serializable
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Krb5Authenticate() throws Exception
|
||||
public Krb5Authenticate()
|
||||
{
|
||||
// Nothing to do at this time
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Initialize the mechanism.
|
||||
*
|
||||
* @param svcConfig Service configuration object.
|
||||
* @param mechConfig Authentication mechanism configuration object.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void init(SvcConfig svcConfig, AuthMechConfig mechConfig) throws Exception
|
||||
public final void init(SvcConfig svcConfig, AuthMechConfig mechConfig) throws Exception
|
||||
{
|
||||
m_svcConfig = svcConfig;
|
||||
m_mechConfig = mechConfig;
|
||||
@ -178,10 +184,14 @@ public class Krb5Authenticate implements AuthMechanism, Serializable
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* invoke() implementation.
|
||||
*
|
||||
* @param authReqMsg Authentication request message.
|
||||
* @return Id of the authenticated entity.
|
||||
* @throws Exception
|
||||
*/
|
||||
public String invoke(AuthReqMsg authReqMsg) throws Exception
|
||||
public final String invoke(AuthReqMsg authReqMsg) throws Exception
|
||||
{
|
||||
String identId = null;
|
||||
|
||||
@ -216,7 +226,7 @@ public class Krb5Authenticate implements AuthMechanism, Serializable
|
||||
}
|
||||
|
||||
// Perform the search
|
||||
NamingEnumeration answer = ctx.search(searchContext,
|
||||
NamingEnumeration<SearchResult> answer = ctx.search(searchContext,
|
||||
"(krbPrincipalName={0})",
|
||||
new String[] {krb5Token.getPrincipalName()},
|
||||
controls);
|
||||
@ -225,7 +235,7 @@ public class Krb5Authenticate implements AuthMechanism, Serializable
|
||||
if (answer.hasMore())
|
||||
{
|
||||
// The search succeeded, set the identity id.
|
||||
SearchResult sr = (SearchResult)answer.next();
|
||||
SearchResult sr = answer.next();
|
||||
if (searchContext.equals(""))
|
||||
{
|
||||
identId = sr.getNameInNamespace();
|
||||
@ -254,10 +264,12 @@ public class Krb5Authenticate implements AuthMechanism, Serializable
|
||||
return identId;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Return the mechanism id.
|
||||
*
|
||||
* @return Mechanism id.
|
||||
*/
|
||||
public String getId()
|
||||
public final String getId()
|
||||
{
|
||||
return "Krb5Authenticate";
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<description>This is the authentication mechanism for the Krb5Authenticate scheme. The Krb5Authenticate scheme authenticates entities using Kerberos-V tokens.</description>
|
||||
<ClassName>com.novell.casa.authtoksvc.Krb5Authenticate</ClassName>
|
||||
|
@ -24,20 +24,20 @@
|
||||
|
||||
package com.novell.casa.authtoksvc;
|
||||
|
||||
/*
|
||||
/**
|
||||
* ProDefs Class.
|
||||
*
|
||||
* <p>
|
||||
* This class contains constants utilized in the Casa Client/Server
|
||||
* protocol.
|
||||
*
|
||||
*/
|
||||
public class ProtoDefs
|
||||
public final class ProtoDefs
|
||||
{
|
||||
|
||||
/*
|
||||
* 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=\"UTF-8\"?>";
|
||||
|
||||
/*
|
||||
* XML Element Name Constants for the documents exchanged between the
|
||||
@ -67,11 +67,6 @@ public class ProtoDefs
|
||||
public final static String mechanismElementName = "mechanism";
|
||||
public final static String mechanismInfoElementName = "mechanism_info";
|
||||
|
||||
/*
|
||||
* Configurable operating parameters
|
||||
*/
|
||||
public String sessionTokenLifetime = "360";
|
||||
|
||||
/*
|
||||
* HTTP Status Codes and Messages
|
||||
*/
|
||||
|
@ -27,18 +27,13 @@ package com.novell.casa.authtoksvc;
|
||||
import java.io.Serializable;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringReader;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.directory.BasicAttribute;
|
||||
import javax.naming.directory.BasicAttributes;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.SearchResult;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.NamingException;
|
||||
@ -49,29 +44,34 @@ import org.bandit.util.config.Realm;
|
||||
|
||||
/**
|
||||
* PwdAuthenticate Class.
|
||||
*
|
||||
* <p>
|
||||
* This class implementes an authentication mechanism for
|
||||
* the processing of authentication requests utilizing a
|
||||
* username/password token.
|
||||
*
|
||||
*/
|
||||
public class PwdAuthenticate implements AuthMechanism, Serializable
|
||||
public final class PwdAuthenticate implements AuthMechanism, Serializable
|
||||
{
|
||||
private SvcConfig m_svcConfig;
|
||||
private AuthMechConfig m_mechConfig;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Password Token Class.
|
||||
*/
|
||||
private class PwToken
|
||||
private static final class PwToken
|
||||
{
|
||||
private String m_username = "";
|
||||
private String m_password = "";
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* The format of the Pw token is as follows:
|
||||
*
|
||||
* <p>
|
||||
* Base64.encode(new String("username\r\n" + "password\r\n"));
|
||||
*
|
||||
* @param encodedToken Base64 encoded password token.
|
||||
* @throws IOException
|
||||
*/
|
||||
public PwToken(String encodedToken) throws IOException
|
||||
{
|
||||
@ -87,44 +87,56 @@ public class PwdAuthenticate implements AuthMechanism, Serializable
|
||||
m_password = tokenReader.readLine();
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the username
|
||||
/**
|
||||
* Returns the username.
|
||||
*
|
||||
* @return Username.
|
||||
*/
|
||||
public String getUsername()
|
||||
public final String getUsername()
|
||||
{
|
||||
return m_username;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the password
|
||||
/**
|
||||
* Returns the password.
|
||||
*
|
||||
* @return password.
|
||||
*/
|
||||
public String getPassword()
|
||||
public final String getPassword()
|
||||
{
|
||||
return m_password;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public PwdAuthenticate() throws Exception
|
||||
public PwdAuthenticate()
|
||||
{
|
||||
// Nothing to do at this time
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Initialize the mechanism.
|
||||
*
|
||||
* @param svcConfig Service configuration object.
|
||||
* @param mechConfig Authentication mechanism configuration object.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void init(SvcConfig svcConfig, AuthMechConfig mechConfig) throws Exception
|
||||
public final void init(SvcConfig svcConfig, AuthMechConfig mechConfig) throws Exception
|
||||
{
|
||||
m_svcConfig = svcConfig;
|
||||
m_mechConfig = mechConfig;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* invoke() implementation.
|
||||
*
|
||||
* @param authReqMsg Authentication request message.
|
||||
* @return Id of the authenticated entity.
|
||||
* @throws Exception
|
||||
*/
|
||||
public String invoke(AuthReqMsg authReqMsg) throws Exception
|
||||
public final String invoke(AuthReqMsg authReqMsg) throws Exception
|
||||
{
|
||||
String identId = null;
|
||||
|
||||
@ -159,7 +171,7 @@ public class PwdAuthenticate implements AuthMechanism, Serializable
|
||||
}
|
||||
|
||||
// Perform the search
|
||||
NamingEnumeration answer = ctx.search(searchContext,
|
||||
NamingEnumeration<SearchResult> answer = ctx.search(searchContext,
|
||||
"(cn={0})",
|
||||
new String[] {pwToken.getUsername()},
|
||||
controls);
|
||||
@ -171,7 +183,7 @@ public class PwdAuthenticate implements AuthMechanism, Serializable
|
||||
// Enumerate through the users returned checking the password
|
||||
while (answer.hasMore())
|
||||
{
|
||||
SearchResult sr = (SearchResult)answer.next();
|
||||
SearchResult sr = answer.next();
|
||||
|
||||
// Open a directory context for the user as a way of verifying its password
|
||||
try
|
||||
@ -224,10 +236,12 @@ public class PwdAuthenticate implements AuthMechanism, Serializable
|
||||
return identId;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Return the mechanism id.
|
||||
*
|
||||
* @return Mechanism id.
|
||||
*/
|
||||
public String getId()
|
||||
public final String getId()
|
||||
{
|
||||
return "PwdAuthenticate";
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<description>This is the authentication mechanism for the PwdAuthenticate scheme. The PwdAuthenticate scheme authenticates entities using username/password tokens.</description>
|
||||
<ClassName>com.novell.casa.authtoksvc.PwdAuthenticate</ClassName>
|
||||
|
@ -31,18 +31,17 @@ import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Rpc Servlet Class.
|
||||
*
|
||||
* <p>
|
||||
* This class processes Rpcs to the Authentication Token Service.
|
||||
*
|
||||
*/
|
||||
public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
||||
public final class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
|
||||
{
|
||||
private static final long serialVersionUID = -8264027868130334613L;
|
||||
|
||||
@ -54,42 +53,44 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
|
||||
protected ReconfigureThread m_reconfigureThread = null;
|
||||
protected int m_reconfigureInterval; // seconds
|
||||
|
||||
private Map m_methodsMap;
|
||||
private Map<String,RpcMethod> m_methodsMap;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Reconfigure Thread Class.
|
||||
*
|
||||
* <p>
|
||||
* This class implements a runnable thread that reconfigures an Rpc Servlet instance.
|
||||
*
|
||||
*/
|
||||
private class ReconfigureThread implements Runnable
|
||||
private final class ReconfigureThread implements Runnable
|
||||
{
|
||||
private Rpc m_rpc;
|
||||
private Thread m_thread;
|
||||
private final Rpc m_rpc;
|
||||
private boolean m_run = true;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param rpc Rpc object.
|
||||
*/
|
||||
public ReconfigureThread (Rpc rpc)
|
||||
{
|
||||
m_rpc = rpc;
|
||||
m_thread = new Thread(this);
|
||||
m_thread.start();
|
||||
Thread thread = new Thread(this);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* run() implementation.
|
||||
*/
|
||||
public void run ()
|
||||
public final void run ()
|
||||
{
|
||||
System.err.println("ReconfigureThread.run()- Running");
|
||||
|
||||
while (true)
|
||||
while (m_run)
|
||||
{
|
||||
// Sleep an ammount equal the reconfigure interval for the Rpc
|
||||
try
|
||||
{
|
||||
m_thread.sleep(m_rpc.m_reconfigureInterval * 1000);
|
||||
Thread.sleep(m_rpc.m_reconfigureInterval * 1000);
|
||||
}
|
||||
catch (InterruptedException e) { /* nothing to do */ }
|
||||
|
||||
@ -112,16 +113,16 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* stop() implementation.
|
||||
*/
|
||||
public void stop ()
|
||||
public final void stop ()
|
||||
{
|
||||
m_thread.stop();
|
||||
m_run = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Rpc ()
|
||||
@ -129,8 +130,10 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
|
||||
super();
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* configureServlet() implementation.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected void configureServlet () throws Exception
|
||||
{
|
||||
@ -152,7 +155,7 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
|
||||
EnabledSvcsConfig enabledSvcsConfig = new EnabledSvcsConfig(m_configFolderPath, m_enabledSvcsOnly);
|
||||
|
||||
// Create a map to keep track of the Rpc methods
|
||||
Map methodsMap = new HashMap();
|
||||
Map<String,RpcMethod> methodsMap = new HashMap<String, RpcMethod>();
|
||||
|
||||
// Instantiate the Rpc Methods
|
||||
RpcMethod getAuthPolicy = new GetAuthPolicy();
|
||||
@ -171,8 +174,11 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
|
||||
m_methodsMap = methodsMap;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* init() implementation.
|
||||
*
|
||||
* @param config Servlet configuration object.
|
||||
* @throws ServletException
|
||||
*/
|
||||
public void init (ServletConfig config) throws ServletException
|
||||
{
|
||||
@ -224,7 +230,7 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* destroy() implementation.
|
||||
*/
|
||||
public void destroy ()
|
||||
@ -240,16 +246,26 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* doGet() implementation.
|
||||
*
|
||||
* @param request Http servlet request object.
|
||||
* @param response Http servlet response object.
|
||||
* @throws ServletException
|
||||
* @throws IOException
|
||||
*/
|
||||
protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
doPost(request, response);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* doPost() implementation.
|
||||
*
|
||||
* @param request Http servlet request object.
|
||||
* @param response Http servlet response object.
|
||||
* @throws ServletException
|
||||
* @throws IOException
|
||||
*/
|
||||
protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
@ -266,7 +282,7 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
|
||||
if (requestedMethod != null)
|
||||
{
|
||||
// Get the necessary method
|
||||
RpcMethod method = (RpcMethod) m_methodsMap.get(requestedMethod);
|
||||
RpcMethod method = m_methodsMap.get(requestedMethod);
|
||||
if (method != null)
|
||||
{
|
||||
// Invoke the method to process the Rpc
|
||||
@ -276,21 +292,21 @@ public class Rpc extends javax.servlet.http.HttpServlet implements javax.servlet
|
||||
{
|
||||
// Unsupported method
|
||||
System.err.println("Rpc.doPost()- Unsupported method");
|
||||
response.sendError(response.SC_BAD_REQUEST);
|
||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Missing method parameter
|
||||
System.err.println("Rpc.doPost()- Missing method parameter");
|
||||
response.sendError(response.SC_BAD_REQUEST);
|
||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// tbd
|
||||
System.err.println("Rpc.doPost()- Exception caught: " + e.toString());
|
||||
response.sendError(response.SC_INTERNAL_SERVER_ERROR);
|
||||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
// Done sending out the reply
|
||||
|
@ -26,28 +26,37 @@ package com.novell.casa.authtoksvc;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* RpcMethod Interface.
|
||||
*
|
||||
* <p>
|
||||
* This is the interface implemented by Rpc Methods.
|
||||
*/
|
||||
public interface RpcMethod
|
||||
{
|
||||
/*
|
||||
/**
|
||||
* Initialize the Rpc method.
|
||||
*
|
||||
* @param svcConfig Service configuration object.
|
||||
* @param enabledSvcsConfig Enabled services configuration object.
|
||||
* @throws Exception
|
||||
*/
|
||||
void init(SvcConfig svcConfig, EnabledSvcsConfig enabledSvcsConfig) throws Exception;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Process Rpc.
|
||||
*
|
||||
* @param inStream Input stream with request.
|
||||
* @param out Ouput print writer for reply.
|
||||
* @throws IOException
|
||||
*/
|
||||
void invoke(InputStream inStream, PrintWriter out) throws IOException;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Return the method id.
|
||||
*
|
||||
* @return Method id.
|
||||
*/
|
||||
String getId();
|
||||
}
|
||||
|
@ -37,27 +37,27 @@ import org.apache.axis.message.MessageElement;
|
||||
import javax.xml.namespace.QName;
|
||||
import java.io.*;
|
||||
|
||||
/*
|
||||
/**
|
||||
* SessionToken class.
|
||||
*
|
||||
* <p>
|
||||
* This class constructs sessions tokens that clients can present to an ATS
|
||||
* to prove that an entity has been authenticated to a particular realm.
|
||||
* The session token consists of a SOAP message secured with WSSecurity
|
||||
* with the appropriate elements signed and with a timestamp. The body of
|
||||
* the SOAP message is as follows:
|
||||
*
|
||||
* <session_token>
|
||||
* <realm>realm value</realm>
|
||||
* <ident_id>identity id value</ident_id>
|
||||
* </session_token>
|
||||
* <p>
|
||||
* <session_token>
|
||||
* <realm>realm value</realm>
|
||||
* <ident_id>identity id value</ident_id>
|
||||
* </session_token>
|
||||
*
|
||||
*/
|
||||
public class SessionToken
|
||||
public final class SessionToken
|
||||
{
|
||||
|
||||
private String m_id = null;
|
||||
private String m_realm = null;
|
||||
private String m_token;
|
||||
private final String m_token;
|
||||
|
||||
static final String sessionTokenSoapMsg =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
@ -73,8 +73,14 @@ public class SessionToken
|
||||
static final private MessageContext axisMsgContext = new MessageContext(new AxisClient(new NullProvider()));
|
||||
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param id Id of the authenticated identity.
|
||||
* @param realm Realm where the identity id is valid.
|
||||
* @param lifetime Token lifetime.
|
||||
* @param svcConfig Service configuration object.
|
||||
* @throws Exception
|
||||
*/
|
||||
public SessionToken(String id,
|
||||
String realm,
|
||||
@ -98,9 +104,12 @@ public class SessionToken
|
||||
outStream.close();
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor given a session token string. The constructor
|
||||
* validates the token as part of its processing.
|
||||
*
|
||||
* @param token Session token string.
|
||||
* @throws Exception
|
||||
*/
|
||||
public SessionToken(String token) throws Exception
|
||||
{
|
||||
@ -150,18 +159,18 @@ public class SessionToken
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SessionToken SOAP Message
|
||||
* Get SessionToken SOAP Message.
|
||||
*
|
||||
* @param realm String containing the identity token that should be part of the message
|
||||
* @param identityId String containing the identity token type
|
||||
* @param lifetime Lifetime that should be specified in the message timestamp (seconds)
|
||||
* @param svcConfig Service Config object
|
||||
* @return <code>Message<code> SessionToken message, null if the method fails.
|
||||
* @param realm String containing the identity token that should be part of the message.
|
||||
* @param identityId String containing the identity token type.
|
||||
* @param lifetime Lifetime that should be specified in the message timestamp (seconds).
|
||||
* @param svcConfig Service Config object.
|
||||
* @return SessionToken message, null if the method fails.
|
||||
*/
|
||||
private Message getMessage(String realm,
|
||||
String identityId,
|
||||
int lifetime,
|
||||
SvcConfig svcConfig)
|
||||
private static Message getMessage(String realm,
|
||||
String identityId,
|
||||
int lifetime,
|
||||
SvcConfig svcConfig)
|
||||
{
|
||||
Message secureMessage;
|
||||
|
||||
@ -206,26 +215,32 @@ public class SessionToken
|
||||
return secureMessage;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns a string containing the session token.
|
||||
*
|
||||
* @return Session token string.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return Base64Coder.encode(m_token);
|
||||
}
|
||||
|
||||
/*
|
||||
* Method to get the Identity Id
|
||||
/**
|
||||
* Method to get the Identity Id.
|
||||
*
|
||||
* @return Identity id.
|
||||
*/
|
||||
public String getIdentId() throws Exception
|
||||
public String getIdentId()
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
/*
|
||||
* Method to get the Identity Repository Reference (Realm).
|
||||
/**
|
||||
* Method to get the Identity Repository Reference (Realm).
|
||||
*
|
||||
* @return realm
|
||||
*/
|
||||
public String getRealm() throws Exception
|
||||
public String getRealm()
|
||||
{
|
||||
return m_realm;
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ import java.io.FileInputStream;
|
||||
*
|
||||
* Class for the creation and editing of settings files.
|
||||
*
|
||||
**/
|
||||
public class SettingsFileUtil
|
||||
*/
|
||||
public final class SettingsFileUtil
|
||||
{
|
||||
/**
|
||||
* Gets document for the specified settings file.
|
||||
@ -52,7 +52,7 @@ public class SettingsFileUtil
|
||||
*/
|
||||
private static Document getSettingsFileDoc(String filePath)
|
||||
{
|
||||
Document doc = null;
|
||||
Document doc;
|
||||
|
||||
try
|
||||
{
|
||||
@ -92,7 +92,7 @@ public class SettingsFileUtil
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a starting settings document
|
||||
* Gets a starting settings document.
|
||||
*
|
||||
* @param settings String with starting settings document.
|
||||
* @return Starting settings document.
|
||||
@ -203,9 +203,10 @@ public class SettingsFileUtil
|
||||
/**
|
||||
* Gets value of the specified setting in the specified settings file.
|
||||
*
|
||||
* @param filePath Path to the settings file.
|
||||
* @param setting Name of the setting being queried.
|
||||
* @return True if the operation is successfully performed.
|
||||
* @param filePath Path to the settings file.
|
||||
* @param setting Name of the setting being queried.
|
||||
* @param settingVerifier Setting verifier object.
|
||||
* @return True if the operation is successfully performed.
|
||||
*/
|
||||
public static boolean performGetOperation(String filePath,
|
||||
String setting,
|
||||
@ -251,15 +252,16 @@ public class SettingsFileUtil
|
||||
/**
|
||||
* Sets the specified setting in the specified settings file.
|
||||
*
|
||||
* @param filePath Path to the settings file.
|
||||
* @param setting`` Name of the setting to be set.
|
||||
* @param value Value to be assigned to the setting.
|
||||
* @return True if the operation is successfully performed.
|
||||
* @param filePath Path to the settings file.
|
||||
* @param setting`` Name of the setting to be set.
|
||||
* @param value Value to be assigned to the setting.
|
||||
* @param settingVerifier Setting verifier object.
|
||||
* @return True if the operation is successfully performed.
|
||||
*/
|
||||
public static boolean performSetOperation(String filePath,
|
||||
String setting,
|
||||
String value,
|
||||
IVerifySetting settingVerifier)
|
||||
String setting,
|
||||
String value,
|
||||
IVerifySetting settingVerifier)
|
||||
{
|
||||
boolean opPerformed = false;
|
||||
|
||||
@ -275,7 +277,7 @@ public class SettingsFileUtil
|
||||
// we find the one specified.
|
||||
Element root = doc.getDocumentElement();
|
||||
Node child;
|
||||
Node next = (Node) root.getFirstChild();
|
||||
Node next = root.getFirstChild();
|
||||
boolean settingFound = false;
|
||||
while ((child = next) != null
|
||||
&& settingFound == false)
|
||||
@ -308,7 +310,7 @@ public class SettingsFileUtil
|
||||
try
|
||||
{
|
||||
// Remove text nodes
|
||||
next = (Node) root.getFirstChild();
|
||||
next = root.getFirstChild();
|
||||
while ((child = next) != null)
|
||||
{
|
||||
next = child.getNextSibling();
|
||||
@ -346,13 +348,14 @@ public class SettingsFileUtil
|
||||
/**
|
||||
* Remove specified setting from the specified settings file.
|
||||
*
|
||||
* @param filePath Path to the settings file.
|
||||
* @param setting Name of the setting to be removed.
|
||||
* @return True if the operation is successfully performed.
|
||||
* @param filePath Path to the settings file.
|
||||
* @param setting Name of the setting to be removed.
|
||||
* @param settingVerifier Setting verifier object.
|
||||
* @return True if the operation is successfully performed.
|
||||
*/
|
||||
public static boolean performRemoveOperation(String filePath,
|
||||
String setting,
|
||||
IVerifySetting settingVerifier)
|
||||
String setting,
|
||||
IVerifySetting settingVerifier)
|
||||
{
|
||||
boolean opPerformed = false;
|
||||
|
||||
@ -367,7 +370,7 @@ public class SettingsFileUtil
|
||||
// we find the one specified.
|
||||
Element root = doc.getDocumentElement();
|
||||
Node child;
|
||||
Node next = (Node) root.getFirstChild();
|
||||
Node next = root.getFirstChild();
|
||||
boolean settingFound = false;
|
||||
while ((child = next) != null
|
||||
&& settingFound == false)
|
||||
@ -384,7 +387,7 @@ public class SettingsFileUtil
|
||||
try
|
||||
{
|
||||
// Remove text nodes
|
||||
next = (Node) root.getFirstChild();
|
||||
next = root.getFirstChild();
|
||||
while ((child = next) != null)
|
||||
{
|
||||
next = child.getNextSibling();
|
||||
|
@ -34,11 +34,11 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
/**
|
||||
* SvcConfig Class.
|
||||
*
|
||||
* <p>
|
||||
* This class obtains and maintains the service configuration.
|
||||
*
|
||||
*/
|
||||
public class SvcConfig
|
||||
public final class SvcConfig
|
||||
{
|
||||
// Well known service configuration settings
|
||||
//
|
||||
@ -64,12 +64,12 @@ public class SvcConfig
|
||||
public final static String DefaultSigningKeyPasswordValue = "secret";
|
||||
|
||||
private static final String m_svcSettingsFileName = "svc.settings";
|
||||
private Map m_svcSettingsMap;
|
||||
private final Map<String,String> m_svcSettingsMap;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Class for handling Authentication Request parsing events.
|
||||
*/
|
||||
private class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
private static final class SAXHandler extends org.xml.sax.helpers.DefaultHandler
|
||||
{
|
||||
private final static int AWAITING_ROOT_ELEMENT_START = 0;
|
||||
private final static int AWAITING_SETTING_ELEMENT_START = 1;
|
||||
@ -79,14 +79,16 @@ public class SvcConfig
|
||||
|
||||
private final static String m_rootElementName = "settings";
|
||||
|
||||
private Map m_keyMap;
|
||||
private final Map<String,String> m_keyMap;
|
||||
private int m_state;
|
||||
private String m_currentKey;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param keyMap Key/Value map.
|
||||
*/
|
||||
public SAXHandler(Map keyMap)
|
||||
public SAXHandler(Map<String,String> keyMap)
|
||||
{
|
||||
super();
|
||||
|
||||
@ -95,10 +97,12 @@ public class SvcConfig
|
||||
m_state = AWAITING_ROOT_ELEMENT_START;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* endDocument() implementation.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endDocument () throws SAXException
|
||||
public final void endDocument () throws SAXException
|
||||
{
|
||||
// Verify that we are not in an invalid state
|
||||
if (m_state != DONE_PARSING)
|
||||
@ -108,10 +112,16 @@ public class SvcConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* startElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @param atts Attributes.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
public final void startElement (String uri, String name, String qName, org.xml.sax.Attributes atts) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -144,10 +154,15 @@ public class SvcConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* endElement() immplementation.
|
||||
/**
|
||||
* endElement() implementation.
|
||||
*
|
||||
* @param uri Uri.
|
||||
* @param name Local name.
|
||||
* @param qName Qualified name.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void endElement (String uri, String name, String qName) throws SAXException
|
||||
public final void endElement (String uri, String name, String qName) throws SAXException
|
||||
{
|
||||
// Proceed based on our state
|
||||
switch (m_state)
|
||||
@ -178,10 +193,15 @@ public class SvcConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* character() implementation.
|
||||
*
|
||||
* @param ch Characters with element data.
|
||||
* @param start Start position in the character array.
|
||||
* @param length Number of characters to use in the array.
|
||||
* @throws SAXException
|
||||
*/
|
||||
public void characters (char ch[], int start, int length) throws SAXException
|
||||
public final void characters (char ch[], int start, int length) throws SAXException
|
||||
{
|
||||
// Consume the data if in the right state
|
||||
if (m_state == AWAITING_SETTING_ELEMENT_DATA)
|
||||
@ -195,8 +215,12 @@ public class SvcConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param appRootPath Path to application root.
|
||||
* @param svcConfigPath Path to the service configuration.
|
||||
* @throws Exception
|
||||
*/
|
||||
public SvcConfig(String appRootPath, String svcConfigPath) throws Exception
|
||||
{
|
||||
@ -205,7 +229,7 @@ public class SvcConfig
|
||||
System.err.println("SvcConfig()- SvcConfigPath = " + svcConfigPath);
|
||||
|
||||
// Create a map to keep track of the service settings
|
||||
m_svcSettingsMap = new HashMap();
|
||||
m_svcSettingsMap = new HashMap<String, String>();
|
||||
|
||||
try
|
||||
{
|
||||
@ -246,13 +270,17 @@ public class SvcConfig
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns the value associated with the specified setting.
|
||||
*
|
||||
* @param settingName Name of the setting.
|
||||
* @return Value of the specified setting.
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getSetting(String settingName) throws Exception
|
||||
public final String getSetting(String settingName) throws Exception
|
||||
{
|
||||
// Try to find the setting in our map
|
||||
String value = (String) m_svcSettingsMap.get(settingName);
|
||||
String value = m_svcSettingsMap.get(settingName);
|
||||
if (value == null)
|
||||
{
|
||||
System.err.println("SvcConfig.getSetting()- Did not find setting " + settingName);
|
||||
|
@ -30,8 +30,8 @@ import java.io.File;
|
||||
*
|
||||
* Class for the creation and editing of svc.settings files.
|
||||
*
|
||||
**/
|
||||
public class SvcSettingsEditor implements IVerifySetting
|
||||
*/
|
||||
public final class SvcSettingsEditor implements IVerifySetting
|
||||
{
|
||||
private static final String usage =
|
||||
"usage: SvcSettingsEditor -op [settingName [settingValue]] -file settingsFilePath\n\n" +
|
||||
@ -66,7 +66,7 @@ public class SvcSettingsEditor implements IVerifySetting
|
||||
* @param setting The name of the setting being checked.
|
||||
* @return True if the specified setting is valid.
|
||||
*/
|
||||
public boolean validSetting(String setting)
|
||||
public final boolean validSetting(String setting)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
@ -96,8 +96,8 @@ public class SvcSettingsEditor implements IVerifySetting
|
||||
* @param value The value of the specified setting.
|
||||
* @return The formal name of the setting if found to be valid.
|
||||
*/
|
||||
public String validSettingNameAndValue(String setting,
|
||||
String value)
|
||||
public final String validSettingNameAndValue(String setting,
|
||||
String value)
|
||||
{
|
||||
String validSetting = null;
|
||||
|
||||
@ -182,7 +182,7 @@ public class SvcSettingsEditor implements IVerifySetting
|
||||
/**
|
||||
* Applications Entry Point
|
||||
*
|
||||
* @param args
|
||||
* @param args Argument.
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
|
@ -44,15 +44,15 @@ import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* WSSecurity Class.
|
||||
*
|
||||
* <p>
|
||||
* This class provides static methods for securing and verifying SOAP messages. SOAP messages
|
||||
* are secured by adding a timestamp and signing the appropriate elements using methods and
|
||||
* headers defined by WS* specifications.
|
||||
*
|
||||
*/
|
||||
public class WSSecurity
|
||||
public final class WSSecurity
|
||||
{
|
||||
static final private WSSecurityEngine secEngine = new WSSecurityEngine();
|
||||
static final private Crypto crypto = CryptoFactory.getInstance();
|
||||
@ -60,6 +60,9 @@ public class WSSecurity
|
||||
/**
|
||||
* Creates a SOAP message from a document.
|
||||
*
|
||||
* @param doc Message document.
|
||||
* @return SOAP message.
|
||||
* @throws Exception
|
||||
*/
|
||||
private static Message toSOAPMessage(Document doc) throws Exception
|
||||
{
|
||||
@ -70,34 +73,33 @@ public class WSSecurity
|
||||
return (org.apache.axis.Message) factory.createMessage(null, in);
|
||||
}
|
||||
|
||||
/***
|
||||
/**
|
||||
* Returns the first element that containes an Id with value
|
||||
* <code>uri</code> and <code>namespace</code>.
|
||||
* <p/>
|
||||
*
|
||||
* uri and namespace.
|
||||
* <p>
|
||||
* Copyright Note: The code for this function was copied from file
|
||||
* WSSecurityUtil.java from package org.apache.ws.security.util.
|
||||
* The Copyright notice on this file is as follows:
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2003-2006 The Apache Software Foundation, or their licensors, as
|
||||
* appropriate.
|
||||
*
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @param startNode Where to start the search
|
||||
* @param value Value of the Id attribute
|
||||
* @param namespace Namespace URI of the Id
|
||||
* @return The found element or <code>null</code>
|
||||
* @param startNode Where to start the search.
|
||||
* @param value Value of the Id attribute.
|
||||
* @param namespace Namespace URI of the Id.
|
||||
* @return The found element or null.
|
||||
*/
|
||||
private static Element findElementById(Node startNode,
|
||||
String value,
|
||||
@ -155,9 +157,9 @@ public class WSSecurity
|
||||
/**
|
||||
* Verifies SOAP envelope timestamp and signatures.
|
||||
*
|
||||
* @param envelope SOAP envelope with timestamp
|
||||
* @return <code>boolean</code> True if verification succeeds
|
||||
* @throws Exception on error
|
||||
* @param envelope SOAP envelope with timestamp
|
||||
* @return True if verification succeeds.
|
||||
* @throws Exception
|
||||
*/
|
||||
public static boolean verifyMessage(SOAPEnvelope envelope) throws Exception
|
||||
{
|
||||
@ -231,12 +233,12 @@ public class WSSecurity
|
||||
/**
|
||||
* Add timestamp and sign SOAP message in compliance with WS-Security.
|
||||
*
|
||||
* @param envelope String containing a SOAP envelope
|
||||
* @param timeToLive Value to set the timestamp timeToLive parameter in seconds
|
||||
* @param svcConfig Service Config object
|
||||
* @param includeCert True if the message should include the Public Certificate
|
||||
* @return <code>Message</code> Signed and timestamped SOAP message
|
||||
* @throws Exception on error
|
||||
* @param envelope String containing a SOAP envelope
|
||||
* @param timeToLive Value to set the timestamp timeToLive parameter in seconds
|
||||
* @param svcConfig Service Config object
|
||||
* @param includeCert True if the message should include the Public Certificate
|
||||
* @return Signed and timestamped SOAP message
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Message secureSOAPEnvelope(SOAPEnvelope envelope,
|
||||
int timeToLive,
|
||||
|
Loading…
Reference in New Issue
Block a user