[jboss-cvs] JBossAS SVN: r110890 - in projects/jboss-jca/trunk/common/src: main/java/org/jboss/jca/common/metadata and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Mar 11 04:13:03 EST 2011
Author: maeste
Date: 2011-03-11 04:13:03 -0500 (Fri, 11 Mar 2011)
New Revision: 110890
Added:
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DsSecurity.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsSecurityImpl.java
projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/ds/DsParserForReauthPluginTestCase.java
projects/jboss-jca/trunk/common/src/test/resources/ds/unit/reauth-plugin-ds.xml
projects/jboss-jca/trunk/common/src/test/resources/ds/unit/reauth-plugin-xa-ds.xml
Modified:
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/CommonDataSource.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/AbstractParser.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceAbstractImpl.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceImpl.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/XADataSourceImpl.java
projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd
Log:
JBJCA-516 xsd and metadata support for reauth-plugin
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/CommonDataSource.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/CommonDataSource.java 2011-03-11 02:17:23 UTC (rev 110889)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/CommonDataSource.java 2011-03-11 09:13:03 UTC (rev 110890)
@@ -23,7 +23,6 @@
import org.jboss.jca.common.api.metadata.JCAMetadata;
import org.jboss.jca.common.api.metadata.ValidatableMetadata;
-import org.jboss.jca.common.api.metadata.common.Credential;
/**
*
@@ -57,7 +56,7 @@
* @return the security.
*/
- public Credential getSecurity();
+ public DsSecurity getSecurity();
/**
* Get the validation.
Added: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DsSecurity.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DsSecurity.java (rev 0)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/metadata/ds/DsSecurity.java 2011-03-11 09:13:03 UTC (rev 110890)
@@ -0,0 +1,125 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.common.api.metadata.ds;
+
+import org.jboss.jca.common.api.metadata.common.Credential;
+import org.jboss.jca.common.api.metadata.common.Extension;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public interface DsSecurity extends Credential
+{
+
+ /**
+ * Get the reauthPlugin extension
+ *
+ * @return the reauthPlugin
+ */
+ public Extension getReauthPlugin();
+
+ /**
+ *
+ * A Tag.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+ public enum Tag
+ {
+ /** always first
+ *
+ */
+ UNKNOWN(null),
+
+ /**
+ * userName tag
+ */
+ USERNAME("user-name"),
+ /**
+ * password tag
+ */
+ PASSWORD("password"),
+
+ /**
+ * security-domain tag
+ */
+ SECURITY_DOMAIN("security-domain"),
+
+ /**
+ * reauth-plugin tag
+ */
+ REAUTH_PLUGIN("reauth-plugin");
+
+ private final String name;
+
+ /**
+ *
+ * Create a new Tag.
+ *
+ * @param name a name
+ */
+ Tag(final String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Get the local name of this element.
+ *
+ * @return the local name
+ */
+ public String getLocalName()
+ {
+ return name;
+ }
+
+ private static final Map<String, Tag> MAP;
+
+ static
+ {
+ final Map<String, Tag> map = new HashMap<String, Tag>();
+ for (Tag element : values())
+ {
+ final String name = element.getLocalName();
+ if (name != null)
+ map.put(name, element);
+ }
+ MAP = map;
+ }
+
+ /**
+ *
+ * Static method to get enum instance given localName XsdString
+ *
+ * @param localName a XsdString used as localname (typically tag name as defined in xsd)
+ * @return the enum instance
+ */
+ public static Tag forName(String localName)
+ {
+ final Tag element = MAP.get(localName);
+ return element == null ? UNKNOWN : element;
+ }
+
+ }
+}
+
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/AbstractParser.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/AbstractParser.java 2011-03-11 02:17:23 UTC (rev 110889)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/AbstractParser.java 2011-03-11 09:13:03 UTC (rev 110890)
@@ -28,7 +28,6 @@
import org.jboss.jca.common.api.metadata.common.Extension;
import org.jboss.jca.common.api.metadata.common.Recovery;
import org.jboss.jca.common.api.metadata.ds.DataSource;
-import org.jboss.jca.common.api.metadata.ds.Validation;
import org.jboss.jca.common.api.metadata.ds.XaDataSource;
import org.jboss.jca.common.api.validator.ValidateException;
import org.jboss.jca.common.metadata.common.CommonPoolImpl;
@@ -595,6 +594,7 @@
throw new ParserException("Reached end of xml document unexpectedly");
}
+
/**
*
* Parse recovery tag
@@ -653,7 +653,7 @@
break;
}
case PLUGIN : {
- plugin = parseExtension(reader, tag);
+ plugin = parseExtension(reader, tag.getLocalName());
break;
}
default :
@@ -677,7 +677,7 @@
* @throws ParserException in case of error
* @throws ValidateException in case of error
*/
- protected Extension parseExtension(XMLStreamReader reader, Validation.Tag enclosingTag) throws XMLStreamException,
+ protected Extension parseExtension(XMLStreamReader reader, String enclosingTag) throws XMLStreamException,
ParserException,
ValidateException
{
@@ -703,12 +703,12 @@
switch (reader.nextTag())
{
case END_ELEMENT : {
- if (Validation.Tag.forName(reader.getLocalName()) == enclosingTag)
+ if (reader.getLocalName().equals(enclosingTag))
{
if (className == null)
{
throw new ParserException("mandatory class-name attribute missing in " +
- enclosingTag.getLocalName());
+ enclosingTag);
}
return new Extension(className, properties);
@@ -741,81 +741,6 @@
throw new ParserException("Reached end of xml document unexpectedly");
}
- /**
- *
- * parse the Extension tag
- *
- * @param reader reader
- * @param enclosingTag enclosingTag
- * @return the parsed extension object
- * @throws XMLStreamException in case of error
- * @throws ParserException in case of error
- * @throws ValidateException in case of error
- */
- protected Extension parseExtension(XMLStreamReader reader, Recovery.Tag enclosingTag) throws XMLStreamException,
- ParserException,
- ValidateException
- {
-
- String className = null;
- Map<String, String> properties = null;
-
- for (Extension.Attribute attribute : Extension.Attribute.values())
- {
- switch (attribute)
- {
- case CLASS_NAME : {
- className = attributeAsString(reader, attribute.getLocalName());
- break;
- }
- default :
- break;
- }
- }
-
- while (reader.hasNext())
- {
- switch (reader.nextTag())
- {
- case END_ELEMENT : {
- if (Recovery.Tag.forName(reader.getLocalName()) == enclosingTag)
- {
- if (className == null)
- {
- throw new ParserException("mandatory class-name attribute missing in " +
- enclosingTag.getLocalName());
- }
-
- return new Extension(className, properties);
- }
- else
- {
- if (Extension.Tag.forName(reader.getLocalName()) == Extension.Tag.UNKNOWN)
- {
- throw new ParserException("unexpected end tag" + reader.getLocalName());
- }
- }
- break;
- }
- case START_ELEMENT : {
- switch (Extension.Tag.forName(reader.getLocalName()))
- {
- case CONFIG_PROPERTY : {
- if (properties == null)
- properties = new HashMap<String, String>();
- properties.put(attributeAsString(reader, "name"), elementAsString(reader));
- break;
- }
- default :
- throw new ParserException("Unexpected element:" + reader.getLocalName());
- }
- break;
- }
- }
- }
- throw new ParserException("Reached end of xml document unexpectedly");
- }
-
private static class SecurityActions
{
/**
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceAbstractImpl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceAbstractImpl.java 2011-03-11 02:17:23 UTC (rev 110889)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceAbstractImpl.java 2011-03-11 09:13:03 UTC (rev 110890)
@@ -21,9 +21,9 @@
*/
package org.jboss.jca.common.metadata.ds;
-import org.jboss.jca.common.api.metadata.common.Credential;
import org.jboss.jca.common.api.metadata.ds.CommonDataSource;
import org.jboss.jca.common.api.metadata.ds.DataSource;
+import org.jboss.jca.common.api.metadata.ds.DsSecurity;
import org.jboss.jca.common.api.metadata.ds.Statement;
import org.jboss.jca.common.api.metadata.ds.TimeOut;
import org.jboss.jca.common.api.metadata.ds.TransactionIsolation;
@@ -56,7 +56,7 @@
/**
* security
*/
- protected final Credential security;
+ protected final DsSecurity security;
/**
* statement
@@ -121,7 +121,7 @@
* @throws ValidateException ValidateException
*/
protected DataSourceAbstractImpl(TransactionIsolation transactionIsolation, TimeOut timeOut,
- Credential security, Statement statement, Validation validation, String urlDelimiter,
+ DsSecurity security, Statement statement, Validation validation, String urlDelimiter,
String urlSelectorStrategyClassName, Boolean useJavaContext, String poolName, Boolean enabled, String jndiName,
boolean spy)
throws ValidateException
@@ -173,7 +173,7 @@
*/
@Override
- public final Credential getSecurity()
+ public final DsSecurity getSecurity()
{
return security;
}
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceImpl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceImpl.java 2011-03-11 02:17:23 UTC (rev 110889)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DataSourceImpl.java 2011-03-11 09:13:03 UTC (rev 110890)
@@ -22,8 +22,8 @@
package org.jboss.jca.common.metadata.ds;
import org.jboss.jca.common.api.metadata.common.CommonPool;
-import org.jboss.jca.common.api.metadata.common.Credential;
import org.jboss.jca.common.api.metadata.ds.DataSource;
+import org.jboss.jca.common.api.metadata.ds.DsSecurity;
import org.jboss.jca.common.api.metadata.ds.Statement;
import org.jboss.jca.common.api.metadata.ds.TimeOut;
import org.jboss.jca.common.api.metadata.ds.TransactionIsolation;
@@ -83,7 +83,7 @@
*/
public DataSourceImpl(String connectionUrl, String driverClass, String module,
TransactionIsolation transactionIsolation, Map<String, String> connectionProperties, TimeOut timeOut,
- Credential security, Statement statement, Validation validation, String urlDelimiter,
+ DsSecurity security, Statement statement, Validation validation, String urlDelimiter,
String urlSelectorStrategyClassName, String newConnectionSql, boolean useJavaContext, String poolName,
boolean enabled, String jndiName, boolean spy, CommonPool pool) throws ValidateException
{
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java 2011-03-11 02:17:23 UTC (rev 110889)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsParser.java 2011-03-11 09:13:03 UTC (rev 110890)
@@ -23,11 +23,11 @@
import org.jboss.jca.common.api.metadata.common.CommonPool;
import org.jboss.jca.common.api.metadata.common.CommonXaPool;
-import org.jboss.jca.common.api.metadata.common.Credential;
import org.jboss.jca.common.api.metadata.common.Extension;
import org.jboss.jca.common.api.metadata.common.Recovery;
import org.jboss.jca.common.api.metadata.ds.DataSource;
import org.jboss.jca.common.api.metadata.ds.DataSources;
+import org.jboss.jca.common.api.metadata.ds.DsSecurity;
import org.jboss.jca.common.api.metadata.ds.Statement;
import org.jboss.jca.common.api.metadata.ds.Statement.TrackStatementsEnum;
import org.jboss.jca.common.api.metadata.ds.TimeOut;
@@ -178,7 +178,7 @@
TransactionIsolation transactionIsolation = null;
Map<String, String> xaDataSourceProperty = new HashMap<String, String>();
TimeOut timeOutSettings = null;
- Credential securitySettings = null;
+ DsSecurity securitySettings = null;
Statement statementSettings = null;
Validation validationSettings = null;
String urlDelimiter = null;
@@ -287,7 +287,7 @@
break;
}
case SECURITY : {
- securitySettings = parseCredential(reader);
+ securitySettings = parseDsSecurity(reader);
break;
}
case STATEMENT : {
@@ -316,6 +316,64 @@
throw new ParserException("Reached end of xml document unexpectedly");
}
+ private DsSecurity parseDsSecurity(XMLStreamReader reader) throws XMLStreamException, ParserException,
+ ValidateException
+ {
+
+ String userName = null;
+ String password = null;
+ String securityDomain = null;
+ Extension reauthPlugin = null;
+
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case END_ELEMENT : {
+ if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.SECURITY)
+ {
+
+ return new DsSecurityImpl(userName, password, securityDomain, reauthPlugin);
+ }
+ else
+ {
+ if (DsSecurity.Tag.forName(reader.getLocalName()) == DsSecurity.Tag.UNKNOWN)
+ {
+ throw new ParserException("unexpected end tag" + reader.getLocalName());
+ }
+ }
+ break;
+ }
+ case START_ELEMENT : {
+ DsSecurity.Tag tag = DsSecurity.Tag.forName(reader.getLocalName());
+ switch (tag)
+ {
+ case PASSWORD : {
+ password = elementAsString(reader);
+ break;
+ }
+ case USERNAME : {
+ userName = elementAsString(reader);
+ break;
+ }
+ case SECURITY_DOMAIN : {
+ securityDomain = elementAsString(reader);
+ break;
+ }
+ case REAUTH_PLUGIN : {
+ reauthPlugin = parseExtension(reader, tag.getLocalName());
+ break;
+ }
+ default :
+ throw new ParserException("Unexpected element:" + reader.getLocalName());
+ }
+ break;
+ }
+ }
+ }
+ throw new ParserException("Reached end of xml document unexpectedly");
+ }
+
private DataSource parseDataSource(XMLStreamReader reader) throws XMLStreamException, ParserException,
ValidateException
{
@@ -325,7 +383,7 @@
TransactionIsolation transactionIsolation = null;
Map<String, String> connectionProperties = new HashMap<String, String>();
TimeOut timeOutSettings = null;
- Credential securitySettings = null;
+ DsSecurity securitySettings = null;
Statement statementSettings = null;
Validation validationSettings = null;
String urlDelimiter = null;
@@ -433,7 +491,7 @@
break;
}
case SECURITY : {
- securitySettings = parseCredential(reader);
+ securitySettings = parseDsSecurity(reader);
break;
}
case STATEMENT : {
@@ -509,11 +567,11 @@
break;
}
case EXCEPTIONSORTER : {
- exceptionSorter = parseExtension(reader, currTag);
+ exceptionSorter = parseExtension(reader, currTag.getLocalName());
break;
}
case STALECONNECTIONCHECKER : {
- staleConnectionChecker = parseExtension(reader, currTag);
+ staleConnectionChecker = parseExtension(reader, currTag.getLocalName());
break;
}
case USEFASTFAIL : {
@@ -525,7 +583,7 @@
break;
}
case VALIDCONNECTIONCHECKER : {
- validConnectionChecker = parseExtension(reader, currTag);
+ validConnectionChecker = parseExtension(reader, currTag.getLocalName());
break;
}
default :
Added: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsSecurityImpl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsSecurityImpl.java (rev 0)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/DsSecurityImpl.java 2011-03-11 09:13:03 UTC (rev 110890)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.common.metadata.ds;
+
+import org.jboss.jca.common.api.metadata.common.Extension;
+import org.jboss.jca.common.api.metadata.ds.DsSecurity;
+import org.jboss.jca.common.api.validator.ValidateException;
+import org.jboss.jca.common.metadata.common.CredentialImpl;
+
+/**
+ *
+ * A DsSecurityImpl.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public class DsSecurityImpl extends CredentialImpl implements DsSecurity
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -5782260654400841898L;
+ private final Extension reauthPlugin;
+
+ /**
+ * Create a new DsSecurityImpl.
+ *
+ * @param userName userName
+ * @param password password
+ * @param securityDomain securityDomain
+ * @param reauthPlugin reauthPlugin
+ * @throws ValidateException in case of validation error
+ */
+ public DsSecurityImpl(String userName, String password, String securityDomain, Extension reauthPlugin)
+ throws ValidateException
+ {
+ super(userName, password, securityDomain);
+ this.reauthPlugin = reauthPlugin;
+ }
+
+ @Override
+ public Extension getReauthPlugin()
+ {
+ return reauthPlugin;
+ }
+
+ @Override
+ public void validate() throws ValidateException
+ {
+ //just super.validate(). The reaut-plugin is not mandatory
+ super.validate();
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((reauthPlugin == null) ? 0 : reauthPlugin.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (!(obj instanceof DsSecurityImpl))
+ return false;
+ DsSecurityImpl other = (DsSecurityImpl) obj;
+ if (reauthPlugin == null)
+ {
+ if (other.reauthPlugin != null)
+ return false;
+ }
+ else if (!reauthPlugin.equals(other.reauthPlugin))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "DsSecurityImpl [reauthPlugin=" + reauthPlugin + ", getUserName()=" + getUserName() +
+ ", getPassword()=" + getPassword() + ", getSecurityDomain()=" + getSecurityDomain() + "]";
+ }
+
+}
+
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/XADataSourceImpl.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/XADataSourceImpl.java 2011-03-11 02:17:23 UTC (rev 110889)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ds/XADataSourceImpl.java 2011-03-11 09:13:03 UTC (rev 110890)
@@ -22,8 +22,8 @@
package org.jboss.jca.common.metadata.ds;
import org.jboss.jca.common.api.metadata.common.CommonXaPool;
-import org.jboss.jca.common.api.metadata.common.Credential;
import org.jboss.jca.common.api.metadata.common.Recovery;
+import org.jboss.jca.common.api.metadata.ds.DsSecurity;
import org.jboss.jca.common.api.metadata.ds.Statement;
import org.jboss.jca.common.api.metadata.ds.TimeOut;
import org.jboss.jca.common.api.metadata.ds.TransactionIsolation;
@@ -82,7 +82,7 @@
* @param recovery recovery
* @throws ValidateException ValidateException
*/
- public XADataSourceImpl(TransactionIsolation transactionIsolation, TimeOut timeOut, Credential security,
+ public XADataSourceImpl(TransactionIsolation transactionIsolation, TimeOut timeOut, DsSecurity security,
Statement statement, Validation validation, String urlDelimiter, String urlSelectorStrategyClassName,
boolean useJavaContext, String poolName, boolean enabled, String jndiName, boolean spy,
Map<String, String> xaDataSourceProperty, String xaDataSourceClass, String module, String newConnectionSql,
Modified: projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd
===================================================================
--- projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd 2011-03-11 02:17:23 UTC (rev 110889)
+++ projects/jboss-jca/trunk/common/src/main/resources/schema/datasources_1_0.xsd 2011-03-11 09:13:03 UTC (rev 110890)
@@ -710,12 +710,12 @@
</xs:extension>
</xs:complexContent>
</xs:complexType>
- <xs:complexType name="credentialType">
+ <xs:complexType name="dsSecurityType">
<xs:sequence>
<xs:element name="user-name" type="xs:token" minOccurs="0">
<xs:annotation>
<xs:documentation>
- <![CDATA[[
+ <![CDATA[[
Specify the username used when creating a new connection.
Ex: <user-name>sa</user-name>
]]>
@@ -725,7 +725,7 @@
<xs:element name="password" type="xs:token" minOccurs="0">
<xs:annotation>
<xs:documentation>
- <![CDATA[[
+ <![CDATA[[
Specify the password used when creating a new connection.
Ex: <password>sa-pass</password>
]]>
@@ -746,8 +746,9 @@
</xs:documentation>
</xs:annotation>
</xs:element>
+ <xs:element name="reauth-plugin" type="extensionType" minOccurs="0" maxOccurs="1"></xs:element>
</xs:sequence>
- </xs:complexType>
+ </xs:complexType>
<xs:complexType name="extensionType">
<xs:sequence>
Added: projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/ds/DsParserForReauthPluginTestCase.java
===================================================================
--- projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/ds/DsParserForReauthPluginTestCase.java (rev 0)
+++ projects/jboss-jca/trunk/common/src/test/java/org/jboss/jca/common/metadata/ds/DsParserForReauthPluginTestCase.java 2011-03-11 09:13:03 UTC (rev 110890)
@@ -0,0 +1,150 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.common.metadata.ds;
+
+import org.jboss.jca.common.api.metadata.common.Extension;
+import org.jboss.jca.common.api.metadata.ds.DataSource;
+import org.jboss.jca.common.api.metadata.ds.DataSources;
+import org.jboss.jca.common.api.metadata.ds.DsSecurity;
+import org.jboss.jca.common.api.metadata.ds.XaDataSource;
+import org.jboss.jca.common.api.validator.ValidateException;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.isNull;
+
+/**
+ *
+ * A DsParserForMinimalFileTestCase.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public class DsParserForReauthPluginTestCase
+{
+
+ private static DsParser parser;
+
+ /**
+ *
+ * beforeClass method
+ *
+ * @throws Exception in casae of file not found
+ */
+ @BeforeClass
+ public static void beforeClass() throws Exception
+ {
+ parser = new DsParser();
+ //this property is set just to make possible property substitution defined in test resources.
+ //but property substitution is not the goal of this test case see DsParserForTemplateReplaceTestCase for that
+ System.setProperty("jboss.server.data.dir", "/tmp");
+ }
+
+ /**
+ *
+ * shouldParseXaDsWithReauthPlugin
+ *
+ * @throws Exception test passes if a {@link ValidateException} has been
+ * thrown
+ */
+ @Test()
+ public void shouldParseXaDsWithReauthPlugin() throws Exception
+ {
+
+ //given
+ File xmlFile = new File(Thread.currentThread().getContextClassLoader()
+ .getResource("ds/unit/reauth-plugin-xa-ds.xml")
+ .toURI());
+ //when
+ DataSources datasources = doParse(xmlFile);
+ XaDataSource ds = datasources.getXaDataSource().get(0);
+ DsSecurity security = ds.getSecurity();
+ assertThat(security, not(isNull()));
+ Extension plugin = security.getReauthPlugin();
+ assertThat(security.getUserName(), is("sa"));
+ assertThat(security.getPassword(), is("sa"));
+ assertThat(plugin.getClassName(), is("myClassName"));
+ assertThat(plugin.getConfigPropertiesMap().size(), is(1));
+ assertThat(plugin.getConfigPropertiesMap().get("MyProperty"), is("MyPropertyValue"));
+
+ //then
+ }
+
+ /**
+ *
+ * shouldParseXaDsWithReauthPlugin
+ *
+ * @throws Exception test passes if a {@link ValidateException} has been
+ * thrown
+ */
+ @Test()
+ public void shouldParseDsWithReauthPlugin() throws Exception
+ {
+
+ //given
+ File xmlFile = new File(Thread.currentThread().getContextClassLoader()
+ .getResource("ds/unit/reauth-plugin-ds.xml")
+ .toURI());
+ //when
+ DataSources datasources = doParse(xmlFile);
+ DataSource ds = datasources.getDataSource().get(0);
+ DsSecurity security = ds.getSecurity();
+ assertThat(security, not(isNull()));
+ Extension plugin = security.getReauthPlugin();
+ assertThat(security.getUserName(), is("sa"));
+ assertThat(security.getPassword(), is("sa"));
+ assertThat(plugin.getClassName(), is("myClassName"));
+ assertThat(plugin.getConfigPropertiesMap().size(), is(1));
+ assertThat(plugin.getConfigPropertiesMap().get("MyProperty"), is("MyPropertyValue"));
+
+ //then
+ }
+
+ private DataSources doParse(File xmlFile) throws FileNotFoundException, Exception, IOException, ValidateException
+ {
+ FileInputStream is = null;
+
+ try
+ {
+ is = new FileInputStream(xmlFile);
+ //when
+ DataSources ds = parser.parse(is);
+ return ds;
+ }
+ finally
+ {
+ if (is != null)
+ is.close();
+ }
+ }
+
+
+}
Added: projects/jboss-jca/trunk/common/src/test/resources/ds/unit/reauth-plugin-ds.xml
===================================================================
--- projects/jboss-jca/trunk/common/src/test/resources/ds/unit/reauth-plugin-ds.xml (rev 0)
+++ projects/jboss-jca/trunk/common/src/test/resources/ds/unit/reauth-plugin-ds.xml 2011-03-11 09:13:03 UTC (rev 110890)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<datasources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://www.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
+
+ <datasource jndi-name="java:/H2DS" pool-name="H2DS">
+ <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
+ <driver-class>org.h2.Driver</driver-class>
+ <security>
+ <user-name>sa</user-name>
+ <password>sa</password>
+ <reauth-plugin class-name="myClassName">
+ <config-property name="MyProperty">MyPropertyValue</config-property>
+ </reauth-plugin>
+ </security>
+ </datasource>
+
+</datasources>
Added: projects/jboss-jca/trunk/common/src/test/resources/ds/unit/reauth-plugin-xa-ds.xml
===================================================================
--- projects/jboss-jca/trunk/common/src/test/resources/ds/unit/reauth-plugin-xa-ds.xml (rev 0)
+++ projects/jboss-jca/trunk/common/src/test/resources/ds/unit/reauth-plugin-xa-ds.xml 2011-03-11 09:13:03 UTC (rev 110890)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<datasources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://www.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
+
+ <xa-datasource jndi-name="java:/H2XADS" pool-name="H2XADS">
+ <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
+ <xa-datasource-property name="URL">jdbc:h2:mem:test</xa-datasource-property>
+ <security>
+ <!-- Have to defined as a primary property - otherwise it won't work -->
+ <user-name>sa</user-name>
+ <!-- Have to defined as a primary property - otherwise it won't work -->
+ <password>sa</password>
+ <reauth-plugin class-name="myClassName">
+ <config-property name="MyProperty">MyPropertyValue</config-property>
+ </reauth-plugin>
+ </security>
+ </xa-datasource>
+
+</datasources>
More information about the jboss-cvs-commits
mailing list