cmlenz 2003/06/10 06:41:54
Modified: integration/ant/src/java/org/apache/cactus/integration/ant/deployment
WebXmlTag.java WebXml.java
integration/ant/src/test/org/apache/cactus/integration/ant/deployment
TestWebXml.java
Log:
Implementation of basic login-config support (no form-login-config support yet,
though)
Revision Changes Path
1.5 +34 -22
jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/deployment/WebXmlTag.java
Index: WebXmlTag.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/deployment/WebXmlTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WebXmlTag.java 10 Jun 2003 12:56:58 -0000 1.4
+++ WebXmlTag.java 10 Jun 2003 13:41:53 -0000 1.5
@@ -149,13 +149,13 @@
new WebXmlTag("listener");
/**
- * Element name 'servlet',
+ * Element name 'servlet'.
*/
public static final WebXmlTag SERVLET =
new WebXmlTag("servlet");
/**
- * Element name 'servlet-name',
+ * Element name 'servlet-name'.
*/
public static final WebXmlTag SERVLET_NAME =
new WebXmlTag("servlet-name");
@@ -173,115 +173,127 @@
new WebXmlTag("servlet-class");
/**
- * Element name 'servlet-mapping',
+ * Element name 'servlet-mapping'.
*/
public static final WebXmlTag SERVLET_MAPPING =
new WebXmlTag("servlet-mapping");
/**
- * Element name 'url-pattern',
+ * Element name 'url-pattern'.
*/
public static final WebXmlTag URL_PATTERN =
new WebXmlTag("url-pattern");
/**
- * Element name 'session-config',
+ * Element name 'session-config'.
*/
public static final WebXmlTag SESSION_CONFIG =
new WebXmlTag("session-config", false);
/**
- * Element name 'mime-mapping',
+ * Element name 'mime-mapping'.
*/
public static final WebXmlTag MIME_MAPPING =
new WebXmlTag("mime-mapping");
/**
- * Element name 'welcome-file-list',
+ * Element name 'welcome-file-list'.
*/
public static final WebXmlTag WELCOME_FILE_LIST =
new WebXmlTag("welcome-file-list", false);
/**
- * Element name 'error-page',
+ * Element name 'error-page'.
*/
public static final WebXmlTag ERROR_PAGE =
new WebXmlTag("error-page");
/**
- * Element name 'taglib',
+ * Element name 'taglib'.
*/
public static final WebXmlTag TAGLIB =
new WebXmlTag("taglib");
/**
- * Element name 'resource-env-ref',
+ * Element name 'resource-env-ref'.
*/
public static final WebXmlTag RESOURCE_ENV_REF =
new WebXmlTag("resource-env-ref");
/**
- * Element name 'resource-ref',
+ * Element name 'resource-ref'.
*/
public static final WebXmlTag RESOURCE_REF =
new WebXmlTag("resource-ref");
/**
- * Element name 'security-constraint',
+ * Element name 'security-constraint'.
*/
public static final WebXmlTag SECURITY_CONSTRAINT =
new WebXmlTag("security-constraint");
/**
- * Element name 'web-resource-collection',
+ * Element name 'web-resource-collection'.
*/
public static final WebXmlTag WEB_RESOURCE_COLLECTION =
new WebXmlTag("web-resource-collection");
/**
- * Element name 'web-resource-name',
+ * Element name 'web-resource-name'.
*/
public static final WebXmlTag WEB_RESOURCE_NAME =
new WebXmlTag("web-resource-name");
/**
- * Element name 'auth-constraint',
+ * Element name 'auth-constraint'.
*/
public static final WebXmlTag AUTH_CONSTRAINT =
new WebXmlTag("auth-constraint");
/**
- * Element name 'login-config',
+ * Element name 'login-config'.
*/
public static final WebXmlTag LOGIN_CONFIG =
new WebXmlTag("login-config", false);
/**
- * Element name 'security-role',
+ * Element name 'auth-method'.
+ */
+ public static WebXmlTag AUTH_METHOD =
+ new WebXmlTag("auth-method");
+
+ /**
+ * Element name 'realm-name'.
+ */
+ public static WebXmlTag REALM_NAME =
+ new WebXmlTag("realm-name");
+
+ /**
+ * Element name 'security-role'.
*/
public static final WebXmlTag SECURITY_ROLE =
new WebXmlTag("security-role");
/**
- * Element name 'role-name',
+ * Element name 'role-name'.
*/
public static final WebXmlTag ROLE_NAME =
new WebXmlTag("role-name");
/**
- * Element name 'env-entry',
+ * Element name 'env-entry'.
*/
public static final WebXmlTag ENV_ENTRY =
new WebXmlTag("env-entry");
/**
- * Element name 'ejb-ref',
+ * Element name 'ejb-ref'.
*/
public static final WebXmlTag EJB_REF =
new WebXmlTag("ejb-ref");
/**
- * Element name 'ejb-local-ref',
+ * Element name 'ejb-local-ref'.
*/
public static final WebXmlTag EJB_LOCAL_REF =
new WebXmlTag("ejb-local-ref");
1.6 +59 -1
jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/deployment/WebXml.java
Index: WebXml.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/deployment/WebXml.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- WebXml.java 10 Jun 2003 12:57:51 -0000 1.5
+++ WebXml.java 10 Jun 2003 13:41:53 -0000 1.6
@@ -798,6 +798,64 @@
}
/**
+ * Returns whether the descriptor has a login configuration.
+ *
+ * @return <code>true</code> if a login config is defined,
+ * <code>false</code> otherwise
+ */
+ public final boolean hasLoginConfig()
+ {
+ return (getLoginConfig() != null);
+ }
+
+ /**
+ * Returns whether the descriptor has a login configuration.
+ *
+ * @return <code>true</code> if a login config is defined,
+ * <code>false</code> otherwise
+ */
+ public final Element getLoginConfig()
+ {
+ Iterator loginConfigElements = getElements(WebXmlTag.LOGIN_CONFIG);
+ if (loginConfigElements.hasNext())
+ {
+ return (Element) loginConfigElements.next();
+ }
+ return null;
+ }
+
+ /**
+ * Returns the authorization method defined by the login configuration.
+ *
+ * @return The authorization method
+ */
+ public final String getLoginConfigAuthMethod()
+ {
+ return getNestedText(getLoginConfig(), WebXmlTag.AUTH_METHOD);
+ }
+
+ /**
+ *
+ *
+ * @param theRealmName
+ * @param theAuthMethod
+ */
+ public void setLoginConfig(String theAuthMethod, String theRealmName)
+ {
+ if ((theRealmName == null) || (theAuthMethod == null))
+ {
+ throw new NullPointerException();
+ }
+ Element loginConfigElement =
+ document.createElement(WebXmlTag.LOGIN_CONFIG.getTagName());
+ loginConfigElement.appendChild(
+ createNestedText(WebXmlTag.AUTH_METHOD, theAuthMethod));
+ loginConfigElement.appendChild(
+ createNestedText(WebXmlTag.REALM_NAME, theRealmName));
+ replaceElement(WebXmlTag.LOGIN_CONFIG, loginConfigElement);
+ }
+
+ /**
* Adds a new security role to the descriptor.
*
* @param theRoleName The name of the role to add
1.5 +93 -3
jakarta-cactus/integration/ant/src/test/org/apache/cactus/integration/ant/deployment/TestWebXml.java
Index: TestWebXml.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/integration/ant/src/test/org/apache/cactus/integration/ant/deployment/TestWebXml.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestWebXml.java 10 Jun 2003 12:56:58 -0000 1.4
+++ TestWebXml.java 10 Jun 2003 13:41:54 -0000 1.5
@@ -1026,7 +1026,8 @@
}
/**
- * TODO
+ * Tests whether a security-constraint with no roles is successfully added
+ * to an empty descriptor.
*
* @throws Exception If an unexpected error occurs
*/
@@ -1041,7 +1042,8 @@
}
/**
- * TODO
+ * Tests whether a security-constraint with two roles is successfully added
+ * to an empty descriptor.
*
* @throws Exception If an unexpected error occurs
*/
@@ -1070,6 +1072,94 @@
roleNameElements.item(0).getChildNodes().item(0).getNodeValue());
assertEquals("role2",
roleNameElements.item(1).getChildNodes().item(0).getNodeValue());
+ }
+
+ /**
+ * Tests whether checking an empty descriptor for a login configuration
+ * results in <code>false</code>.
+ *
+ * @throws Exception If an unexpected error occurs
+ */
+ public void testHasLoginConfigEmpty()
+ throws Exception
+ {
+ String xml = "<web-app></web-app>";
+ Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
+ WebXml webXml = new WebXml(doc);
+ assertTrue(!webXml.hasLoginConfig());
+ }
+
+ /**
+ * Tests whether checking a descriptor with a login configuration for a
+ * login configuration results in <code>true</code>.
+ *
+ * @throws Exception If an unexpected error occurs
+ */
+ public void testHasLoginConfig()
+ throws Exception
+ {
+ String xml = "<web-app>"
+ + " <login-config>"
+ + " <auth-method>BASIC</auth-method>"
+ + " </login-config>"
+ + "</web-app>";
+ Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
+ WebXml webXml = new WebXml(doc);
+ assertTrue(webXml.hasLoginConfig());
+ }
+
+ /**
+ * Tests retrieving the authentication method from a descriptor.
+ *
+ * @throws Exception If an unexpected error occurs
+ */
+ public void testGetLoginConfigAuthMethod()
+ throws Exception
+ {
+ String xml = "<web-app>"
+ + " <login-config>"
+ + " <auth-method>BASIC</auth-method>"
+ + " </login-config>"
+ + "</web-app>";
+ Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
+ WebXml webXml = new WebXml(doc);
+ assertEquals("BASIC", webXml.getLoginConfigAuthMethod());
+ }
+
+ /**
+ * Tests retrieving the authentication method from a descriptor.
+ *
+ * @throws Exception If an unexpected error occurs
+ */
+ public void testSetLoginConfigAdding()
+ throws Exception
+ {
+ String xml = "<web-app></web-app>";
+ Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
+ WebXml webXml = new WebXml(doc);
+ webXml.setLoginConfig("BASIC", "Test Realm");
+ assertTrue(webXml.hasLoginConfig());
+ assertEquals("BASIC", webXml.getLoginConfigAuthMethod());
+ }
+
+ /**
+ * Tests retrieving the authentication method from a descriptor.
+ *
+ * @throws Exception If an unexpected error occurs
+ */
+ public void testSetLoginConfigReplacing()
+ throws Exception
+ {
+ String xml = "<web-app>"
+ + " <login-config>"
+ + " <auth-method>DIGEST</auth-method>"
+ + " </login-config>"
+ + "</web-app>";
+ Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
+ WebXml webXml = new WebXml(doc);
+ webXml.setLoginConfig("BASIC", "Test Realm");
+ assertTrue(webXml.hasLoginConfig());
+ assertEquals("BASIC", webXml.getLoginConfigAuthMethod());
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]