geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmcma...@apache.org
Subject svn commit: r552557 [5/6] - in /geronimo/sandbox/j2g/plugins: org.apache.geronimo.j2g.descriptors.app/ org.apache.geronimo.j2g.descriptors.cmp/ org.apache.geronimo.j2g.descriptors.ejb/ org.apache.geronimo.j2g.descriptors.web/ org.apache.geronimo.j2g.de...
Date Mon, 02 Jul 2007 18:30:40 GMT
Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/geronimo-secutiry-plan.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/geronimo-secutiry-plan.xml?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/geronimo-secutiry-plan.xml (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/geronimo-secutiry-plan.xml Mon Jul  2 11:30:34 2007
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You 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
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   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. -->
+ <module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
+    <environment>
+        <moduleId>
+            <groupId>console</groupId>
+            <artifactId>realm-SecurityRealm</artifactId>
+            <version>1.0</version>
+            <type>car</type>
+        </moduleId>
+        <dependencies>
+            <dependency>
+                <groupId>geronimo</groupId>
+                <artifactId>j2ee-security</artifactId>
+                <type>car</type>
+            </dependency>
+        </dependencies>
+    </environment>
+    <gbean name="SecurityRealm" class="org.apache.geronimo.security.realm.GenericSecurityRealm">
+        <attribute name="realmName">SecurityRealm</attribute>
+        <reference name="ServerInfo">
+            <name>ServerInfo</name>
+        </reference>
+        <reference name="LoginService">
+            <name>JaasLoginService</name>
+        </reference>
+        <xml-reference name="LoginModuleConfiguration">
+            <log:login-config xmlns:log="http://geronimo.apache.org/xml/ns/loginconfig-1.1">
+                <log:login-module control-flag="REQUIRED" server-side="true" wrap-principals="false">
+                    <log:login-domain-name>SecurityRealm</log:login-domain-name>
+                    <log:login-module-class>org.apache.geronimo.security.realm.providers.LDAPLoginModule</log:login-module-class>
+                    <log:option name="roleSearchMatching">test</log:option>
+                    <log:option name="roleName">test</log:option>
+                    <log:option name="userSearchSubtree">test</log:option>
+                    <log:option name="roleBase">test</log:option>
+                    <log:option name="userRoleName">test</log:option>
+                    <log:option name="authentication">simple</log:option>
+                    <log:option name="connectionUsername">testname</log:option>
+                    <log:option name="connectionURL">ldap://localhost:1389</log:option>
+                    <log:option name="userBase">test</log:option>
+                    <log:option name="initialContextFactory">test</log:option>
+                    <log:option name="roleSearchSubtree">test</log:option>
+                    <log:option name="connectionPassword">testpwd</log:option>
+                    <log:option name="userSearchMatching">test</log:option>
+                </log:login-module>
+                <log:login-module control-flag="OPTIONAL" server-side="true" wrap-principals="false">
+                    <log:login-domain-name>SecurityRealm-Password</log:login-domain-name>
+                    <log:login-module-class>org.apache.geronimo.security.realm.providers.GeronimoPasswordCredentialLoginModule</log:login-module-class>
+                </log:login-module>
+                <log:login-module control-flag="OPTIONAL" server-side="true" wrap-principals="false">
+                    <log:login-domain-name>SecurityRealm-Audit</log:login-domain-name>
+                    <log:login-module-class>org.apache.geronimo.security.realm.providers.FileAuditLoginModule</log:login-module-class>
+                    <log:option name="file">~/tmp/test.log</log:option>
+                </log:login-module>
+                <log:login-module control-flag="REQUISITE" server-side="true" wrap-principals="false">
+                    <log:login-domain-name>SecurityRealm-Lockout</log:login-domain-name>
+                    <log:login-module-class>org.apache.geronimo.security.realm.providers.RepeatedFailureLockoutLoginModule</log:login-module-class>
+                    <log:option name="lockoutDurationSecs">80</log:option>
+                    <log:option name="failurePeriodSecs">80</log:option>
+                    <log:option name="failureCount">80</log:option>
+                </log:login-module>
+				<!-- test -->
+				   <log:login-module control-flag="REQUIRED" server-side="true" wrap-principals="false">
+                    <log:login-domain-name>geronimo-properties-realm</log:login-domain-name>
+                    <log:login-module-class>org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule</log:login-module-class>
+                    <log:option name="usersURI">var/security/users.properties</log:option>
+                    <log:option name="groupsURI">var/security/groups.properties</log:option>
+                </log:login-module>
+				<!-- database-->
+				 <log:login-module control-flag="REQUIRED" server-side="true" wrap-principals="false">
+                    <log:login-domain-name>TestDBSR</log:login-domain-name>
+                    <log:login-module-class>org.apache.geronimo.security.realm.providers.SQLLoginModule</log:login-module-class>
+                    <log:option name="userSelect">user select sql</log:option>
+                    <log:option name="jdbcDriver">com.mysql.jdbc.Driver</log:option>
+                    <log:option name="jdbcUser">jdbc user name</log:option>
+                    <log:option name="groupSelect">group select sql</log:option>
+                    <log:option name="jdbcPassword">jdbc user name</log:option>
+                    <log:option name="jdbcURL">jdbc url</log:option>
+				</log:login-module>
+				<!-- LDAP -->
+					<log:login-module control-flag="REQUIRED" server-side="true" wrap-principals="false">
+                    <log:login-domain-name>NameLdapSR</log:login-domain-name>
+                    <log:login-module-class>org.apache.geronimo.security.realm.providers.LDAPLoginModule</log:login-module-class>
+                    <log:option name="connectionProtocol">protocol</log:option>
+                    <log:option name="roleSearchMatching">RoleUserSearchiString</log:option>
+                    <log:option name="roleName">RoleName</log:option>
+                    <log:option name="userSearchSubtree">uesrsSearchSubTree</log:option>
+                    <log:option name="roleBase">RoleBase</log:option>
+                    <log:option name="userRoleName">UserRoleSearch</log:option>
+                    <log:option name="connectionUsername">usename</log:option>
+                    <log:option name="connectionURL">ConnectionURL</log:option>
+                    <log:option name="userBase">userbase</log:option>
+                    <log:option name="initialContextFactory">InitialContextFactory</log:option>
+                    <log:option name="roleSearchSubtree">RoleSearch</log:option>
+                    <log:option name="connectionPassword">passeotd</log:option>
+                    <log:option name="userSearchMatching">userSearchMatching</log:option>
+                </log:login-module>
+				<!-- Other -->
+				<log:login-module control-flag="REQUIRED" server-side="true" wrap-principals="false">
+                    <log:login-domain-name>NameSR</log:login-domain-name>
+                    <log:login-module-class>org.geronimo.test</log:login-module-class>
+                </log:login-module>
+					 
+            </log:login-config>
+        </xml-reference>
+    </gbean>
+</module>

Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/login-config.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/login-config.xml?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/login-config.xml (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/login-config.xml Mon Jul  2 11:30:34 2007
@@ -0,0 +1,206 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You 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
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   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. -->
+<!-- DOCTYPE policy PUBLIC
+      "-//JBoss//DTD JBOSS Security Config 3.0//EN"
+      "http://www.jboss.org/j2ee/dtd/security_config.dtd" -->
+
+<!-- The XML based JAAS login configuration read by the
+org.jboss.security.auth.login.XMLLoginConfig mbean. Add
+an application-policy element for each security domain.
+
+The outline of the application-policy is:
+<application-policy name="security-domain-name">
+  <authentication>
+    <login-module code="login.module1.class.name" flag="control_flag">
+      <module-option name = "option1-name">option1-value</module-option>
+      <module-option name = "option2-name">option2-value</module-option>
+      ...
+    </login-module>
+
+    <login-module code="login.module2.class.name" flag="control_flag">
+      ...
+    </login-module>
+    ...
+  </authentication>
+</application-policy>
+
+$Revision: 546303 $
+-->
+
+<policy>
+    <!-- Used by clients within the application server VM such as
+    mbeans and servlets that access EJBs.
+    -->
+    <application-policy name = "client-login">
+       <authentication>
+          <login-module code = "org.jboss.security.ClientLoginModule"
+             flag = "required">
+          </login-module>
+       </authentication>
+    </application-policy>
+
+    <!-- Security domain for JBossMQ -->
+    <application-policy name = "jbossmq">
+       <authentication>
+          <login-module code = "org.jboss.security.auth.spi.DatabaseServerLoginModule"
+             flag = "required">
+             <module-option name = "unauthenticatedIdentity">guest</module-option>
+             <module-option name = "dsJndiName">java:/DefaultDS/Test</module-option>
+             <module-option name = "principalsQuery">SELECT PASSWD FROM JMS_USERS WHERE USERID=?</module-option>
+             <module-option name = "rolesQuery">SELECT ROLEID, 'Roles' FROM JMS_ROLES WHERE USERID=?</module-option>
+          </login-module>
+       </authentication>
+    </application-policy>
+
+    <!-- Security domain for JBossMQ when using file-state-service.xml
+    <application-policy name = "jbossmq">
+       <authentication>
+          <login-module code = "org.jboss.mq.sm.file.DynamicLoginModule"
+             flag = "required">
+             <module-option name = "unauthenticatedIdentity">guest</module-option>
+             <module-option name = "sm.objectname">jboss.mq:service=StateManager</module-option>
+          </login-module>
+       </authentication>
+    </application-policy>
+    -->
+
+    <!-- Security domains for testing new jca framework -->
+    <application-policy name = "HsqlDbRealm">
+       <authentication>
+          <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule"
+             flag = "required">
+             <module-option name = "principal">sa</module-option>
+             <module-option name = "userName">sa</module-option>
+             <module-option name = "password"></module-option>
+             <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=DefaultDS</module-option>
+          </login-module>
+       </authentication>
+    </application-policy>
+
+    <application-policy name = "JmsXARealm">
+       <authentication>
+          <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule"
+             flag = "required">
+             <module-option name = "principal">guest</module-option>
+             <module-option name = "userName">guest</module-option>
+             <module-option name = "password">guest</module-option>
+             <module-option name = "managedConnectionFactoryName">jboss.jca:service=TxCM,name=JmsXA</module-option>
+          </login-module>
+       </authentication>
+    </application-policy>
+
+    <!-- A template configuration for the jmx-console web application. This
+      defaults to the UsersRolesLoginModule the same as other and should be
+      changed to a stronger authentication mechanism as required.
+    -->
+    <application-policy name = "jmx-console">
+       <authentication>
+          <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
+             flag = "required">
+           <module-option name="usersProperties">props/jmx-console-users.properties</module-option>
+           <module-option name="rolesProperties">props/jmx-console-roles.properties</module-option>
+          </login-module>
+       </authentication>
+    </application-policy>
+
+    <!-- A template configuration for the web-console web application. This
+      defaults to the UsersRolesLoginModule the same as other and should be
+      changed to a stronger authentication mechanism as required.
+    -->
+    <application-policy name = "web-console">
+       <authentication>
+          <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
+             flag = "required">
+             <module-option name="usersProperties">web-console-users.properties</module-option>
+             <module-option name="rolesProperties">web-console-roles.properties</module-option>
+          </login-module>
+       </authentication>
+    </application-policy>
+
+    <!-- A template configuration for the JBossWS web application (and transport layer!).
+      This defaults to the UsersRolesLoginModule the same as other and should be
+      changed to a stronger authentication mechanism as required.
+    -->
+    <application-policy name="JBossWS">
+      <authentication>
+        <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
+          flag="required">
+          <module-option name="unauthenticatedIdentity">anonymous</module-option>
+        </login-module>
+      </authentication>
+    </application-policy>
+
+    <!-- The default login configuration used by any security domain that
+    does not have a application-policy entry with a matching name
+    -->
+    <application-policy name = "other">
+       <!-- A simple server login module, which can be used when the number 
+       of users is relatively small. It uses two properties files:
+       users.properties, which holds users (key) and their password (value).
+       roles.properties, which holds users (key) and a comma-separated list of
+       their roles (value).
+       The unauthenticatedIdentity property defines the name of the principal
+       that will be used when a null username and password are presented as is
+       the case for an unuathenticated web client or MDB. If you want to
+       allow such users to be authenticated add the property, e.g.,
+       unauthenticatedIdentity="nobody"
+       -->
+       <authentication>
+          <login-module code = "org.jboss.security.auth.spi.UsersRolesLoginModule"
+             flag = "required" />
+       </authentication>
+    </application-policy>
+	
+	    <!-- This is the test 1 LDAP JBoss Configuration    -->
+	    <application-policy name="testLDAP1"> 
+        <authentication>
+         <login-module code="org.jboss.security.auth.spi.LdapLoginModule" flag="required">
+                <module-option name="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</module-option>
+                <module-option name="java.naming.provider.url">ldap://ldaphost.jboss.org:1389/</module-option>
+                <module-option name="java.naming.security.protocol">ssl</module-option>
+                <module-option name="java.naming.security.authentication">simple</module-option>
+                <module-option name="principalDNPrefix">uid=</module-option>                    
+                <module-option name="principalDNSuffix">test=test,ou=People,dc=jboss,dc=org</module-option>
+                <module-option name="rolesCtxDN">ou=Roles,dc=jboss,dc=org</module-option>
+                <module-option name="uidAttributeID">member</module-option>
+                <module-option name="matchOnUserDN">true</module-option>
+                <module-option name="roleAttributeID">cn</module-option>
+                <module-option name="roleAttributeIsDN">false </module-option>
+          </login-module>
+       </authentication>
+    </application-policy>
+	
+		    <!-- This is the test 2 LDAP JBoss Configuration    -->
+	    <application-policy name="testLDAP2"> 
+        <authentication>
+         <login-module code="org.jboss.security.auth.spi.LdapLoginModule" flag="required">
+                <module-option name="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</module-option>
+                <module-option name="java.naming.provider.url">ldap://ldaphost.jboss.org:1389/</module-option>
+                <module-option name="java.naming.security.protocol">tcp</module-option>
+                <module-option name="java.naming.security.authentication">simple</module-option>
+                <module-option name="principalDNPrefix">uid=</module-option>                    
+                <module-option name="principalDNSuffix">,ou=People,dc=jboss,dc=org</module-option>
+                <module-option name="rolesCtxDN">ou=Roles,dc=jboss,dc=org</module-option>
+                <module-option name="uidAttributeID">member</module-option>
+                <module-option name="matchOnUserDN">true</module-option>
+                <module-option name="roleAttributeID">cn</module-option>
+                <module-option name="roleAttributeIsDN">false </module-option>
+          </login-module>
+       </authentication>
+    </application-policy>
+
+</policy>
+

Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/security-geronimo-plan.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/security-geronimo-plan.xml?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/security-geronimo-plan.xml (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/security-geronimo-plan.xml Mon Jul  2 11:30:34 2007
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
+  <environment>
+    <moduleId>
+      <groupId>j2g</groupId>
+      <artifactId>security</artifactId>
+      <version>1.0</version>
+      <type>rar</type>
+    </moduleId>
+    <dependencies>
+      <dependency>
+        <groupId>geronimo</groupId>
+        <artifactId>j2ee-security</artifactId>
+        <type>car</type>
+      </dependency>
+    </dependencies>
+  </environment>
+  <gbean name="SecurityRealm" class="org.apache.geronimo.security.realm.GenericSecurityRealm">
+    <reference name="ServerInfo">
+      <name>ServerInfo</name>
+    </reference>
+    <reference name="LoginService">
+      <name>JaasLoginService</name>
+    </reference>
+    <xml-reference name="LoginModuleConfiguration">
+      <log:login-config xmlns:log="http://geronimo.apache.org/xml/ns/loginconfig-1.1">
+        <log:login-module control-flag="REQUIRED" server-side="true" wrap-principals="false">
+          <log:login-domain-name>jbossmq</log:login-domain-name>
+          <log:login-module-class>org.apache.geronimo.security.realm.providers.SQLLoginModule</log:login-module-class>
+          <log:option name="dataSourceName">DefaultDS/Test</log:option>
+          <log:option name="userSelect">SELECT PASSWD FROM JMS_USERS WHERE USERID=?</log:option>
+          <log:option name="groupSelect">SELECT ROLEID, 'Roles' FROM JMS_ROLES WHERE USERID=?</log:option>
+        </log:login-module>
+        <log:login-module control-flag="REQUIRED" server-side="true" wrap-principals="false">
+          <log:login-domain-name>jmx-console</log:login-domain-name>
+          <log:login-module-class>org.apche.geronimo.security.realm.providers.PropertiesFileLoginModule</log:login-module-class>
+          <log:option name="usersURI">var/security/user.properties</log:option>
+          <log:option name="groupsURI">var/security/user.properties</log:option>
+        </log:login-module>
+        <log:login-module control-flag="REQUIRED" server-side="true" wrap-principals="false">
+          <log:login-domain-name>web-console</log:login-domain-name>
+          <log:login-module-class>org.apche.geronimo.security.realm.providers.PropertiesFileLoginModule</log:login-module-class>
+          <log:option name="usersURI">var/security/user.properties</log:option>
+          <log:option name="groupsURI">var/security/user.properties</log:option>
+        </log:login-module>
+        <log:login-module control-flag="REQUIRED" server-side="true" wrap-principals="false">
+          <log:login-domain-name>JBossWS</log:login-domain-name>
+          <log:login-module-class>org.apche.geronimo.security.realm.providers.PropertiesFileLoginModule</log:login-module-class>
+          <log:option name="unauthenticatedIdentity">anonymous</log:option>
+        </log:login-module>
+        <log:login-module control-flag="REQUIRED" server-side="true" wrap-principals="false">
+          <log:login-domain-name>other</log:login-domain-name>
+          <log:login-module-class>org.apche.geronimo.security.realm.providers.PropertiesFileLoginModule</log:login-module-class>
+        </log:login-module>
+        <log:login-module control-flag="REQUIRED" server-side="true" wrap-principals="false">
+          <log:login-domain-name>testLDAP1</log:login-domain-name>
+          <log:login-module-class>org.apche.geronimo.security.realm.providers.LDAPLoginModule</log:login-module-class>
+          <log:option name="initialContextFactory">com.sun.jndi.ldap.LdapCtxFactory</log:option>
+          <log:option name="userBase"></log:option>
+          <log:option name="roleBase"></log:option>
+          <log:option name="userSearchSubtree">true</log:option>
+          <log:option name="roleSearchSubtree">true</log:option>
+          <log:option name="connectionURL">ldap://localhost:636</log:option>
+          <log:option name="connectionProtocol">ssl</log:option>
+          <log:option name="authentication">simple</log:option>
+          <log:option name="userSearchMatching">uid={0}test=test,ou=People,dc=jboss,dc=org</log:option>
+          <log:option name="roleSearchMatching">ou=Roles,dc=jboss,dc=org???(member={0})</log:option>
+          <log:option name="roleName">roles</log:option>
+        </log:login-module>
+        <log:login-module control-flag="REQUIRED" server-side="true" wrap-principals="false">
+          <log:login-domain-name>testLDAP2</log:login-domain-name>
+          <log:login-module-class>org.apche.geronimo.security.realm.providers.LDAPLoginModule</log:login-module-class>
+          <log:option name="initialContextFactory">com.sun.jndi.ldap.LdapCtxFactory</log:option>
+          <log:option name="userBase"></log:option>
+          <log:option name="roleBase"></log:option>
+          <log:option name="userSearchSubtree">true</log:option>
+          <log:option name="roleSearchSubtree">true</log:option>
+          <log:option name="connectionURL">ldap://localhost:389</log:option>
+          <log:option name="connectionProtocol">tcp</log:option>
+          <log:option name="authentication">simple</log:option>
+          <log:option name="userSearchMatching">uid={0},ou=People,dc=jboss,dc=org</log:option>
+          <log:option name="roleSearchMatching">ou=Roles,dc=jboss,dc=org???(member={0})</log:option>
+          <log:option name="roleName">roles</log:option>
+        </log:login-module>
+      </log:login-config>
+    </xml-reference>
+  </gbean>
+</module>

Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/datasource/test/DSResouresToolTestCase.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/datasource/test/DSResouresToolTestCase.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/datasource/test/DSResouresToolTestCase.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/datasource/test/DSResouresToolTestCase.java Mon Jul  2 11:30:34 2007
@@ -0,0 +1,72 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+package org.apache.geronimo.j2g.resources.datasource.test;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.geronimo.j2g.resources.ResourcesTool;
+import org.apache.geronimo.j2g.resources.datasource.DSResourcesTool;
+import org.apache.geronimo.j2g.util.resources.Constants;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+
+/**
+ * Test Case for the DSResouresTool
+ */
+public class DSResouresToolTestCase extends TestCase {
+    
+    
+    protected void setUp() throws Exception {
+        // To set the IOutput intialize the DescripterTool
+        ResourcesTool desTool = new ResourcesTool();
+        super.setUp();
+    }
+
+    // Test for the mysql
+    public void testDSResourcesFileMigration_mysql() {
+        File file = new File("test-apps/ds/mysql-ds.xml");
+        DSResourcesTool dsResourcesTool = new DSResourcesTool();
+        boolean result = dsResourcesTool.migrate(file);
+        assertTrue(result);
+    }
+
+    // Test for the oracle
+    public void testDSResourcesFileMigration_oracle() {
+        File file = new File("test-apps/ds/oracle-ds.xml");
+        DSResourcesTool dsResourcesTool = new DSResourcesTool();
+        boolean result = dsResourcesTool.migrate(file);
+        assertTrue(result);
+    }
+
+    // Test for the hsqldb
+    public void testDSResourcesFileMigration_hsqldb() {
+        File file = new File("test-apps/ds/hsqldb-ds.xml");
+        DSResourcesTool dsResourcesTool = new DSResourcesTool();
+        boolean result = dsResourcesTool.migrate(file);
+        assertTrue(result);
+    }
+
+    public void testMethod_createDefaultConnectionManagerElement() {
+        Namespace connectorNamespace = new Namespace("", Constants.NAMESPACE_CONNECTOR);
+        DSResourcesTool dsResourcesTool = new DSResourcesTool();
+        Element result = dsResourcesTool.createDefaultConnectionManagerElement(connectorNamespace);
+        assertNotNull(result);
+    }
+
+}

Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/jms/test/JMSResouresToolTestCase.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/jms/test/JMSResouresToolTestCase.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/jms/test/JMSResouresToolTestCase.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/jms/test/JMSResouresToolTestCase.java Mon Jul  2 11:30:34 2007
@@ -0,0 +1,48 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+package org.apache.geronimo.j2g.resources.jms.test;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.geronimo.j2g.resources.ResourcesTool;
+import org.apache.geronimo.j2g.resources.jms.JMSResourcesTool;
+import org.apache.geronimo.j2g.util.resources.Constants;
+
+/**
+ * Test Case for the JMSResouresTool
+ */
+public class JMSResouresToolTestCase extends TestCase {
+    
+    @Override //the setup method 
+    protected void setUp() throws Exception {
+        // To set the IOutput intialize the DescripterTool
+        ResourcesTool desTool = new ResourcesTool();
+        super.setUp();
+    }
+    
+    // Test for JMS Resources Migration
+    public void testJMSResourcesFileMigration() {
+        String fileLocation = Constants.TEST_RESOURCES_DIRECTORY + "jms/"
+                + Constants.JBOSS_VALID_JMS_DESTINATIONS_SERVICES_XML_FILE;
+        File file = new File(fileLocation);
+        JMSResourcesTool jmsResourcesTool = new JMSResourcesTool();
+        boolean result = jmsResourcesTool.migrate(file);
+        assertTrue(result);
+    }
+}

Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/mail/test/MailResouresToolTestCase.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/mail/test/MailResouresToolTestCase.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/mail/test/MailResouresToolTestCase.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/mail/test/MailResouresToolTestCase.java Mon Jul  2 11:30:34 2007
@@ -0,0 +1,70 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+package org.apache.geronimo.j2g.resources.mail.test;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.geronimo.j2g.resources.ResourcesTool;
+import org.apache.geronimo.j2g.resources.mail.MailResourcesTool;
+import org.apache.geronimo.j2g.util.resources.xml.XMLConversionHelper;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+
+/**
+ * Test Case for the MailResouresTool
+ */
+public class MailResouresToolTestCase extends TestCase {
+
+     
+    protected void setUp() throws Exception {
+        // To set the IOutput intialize the DescripterTool
+        ResourcesTool resTool = new ResourcesTool();
+        super.setUp();
+    }
+    
+    // Test for mail service migration
+    public void testMailResourcesFileMigration() {
+        File file = new File("test-apps/mail/mail-service.xml");
+        MailResourcesTool mailResourcesTool = new MailResourcesTool();
+        boolean result = mailResourcesTool.migrate(file);
+        assertTrue(result);
+    }
+
+    // Test for mail service migration (with plain text password authentication)
+    public void testMailResourcesFileMigration_withPassword() {
+        File file = new File("test-apps/mail/err/mail-service.xml");
+        MailResourcesTool mailResourcesTool = new MailResourcesTool();
+        boolean result = mailResourcesTool.migrate(file);
+        assertTrue(!result);
+    }
+    
+    // Test for mail service migration (with plain text password authentication)
+    public void testCDATA_Section() {
+        File file = new File("test-apps/mail/mail-geronimo-plan.xml");
+        try {
+            Document document = XMLConversionHelper.getJbossDocument(file);
+            Element element =XMLConversionHelper.obtainSubElementWithAttribute( document.getRootElement(), "gbean", "name", "mailSession");
+            Element element1 =XMLConversionHelper.obtainSubElementWithAttribute(element, "attribute", "name", "properties");
+            System.out.println(element1.getText());
+        } catch (DocumentException e) {
+            e.printStackTrace();
+        }
+    }
+}

Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/security/test/SecurityResouresToolTestCase.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/security/test/SecurityResouresToolTestCase.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/security/test/SecurityResouresToolTestCase.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/security/test/SecurityResouresToolTestCase.java Mon Jul  2 11:30:34 2007
@@ -0,0 +1,45 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+package org.apache.geronimo.j2g.resources.security.test;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.geronimo.j2g.resources.ResourcesTool;
+import org.apache.geronimo.j2g.resources.security.SecurityResourcesTool;
+
+/**
+ * Test Case for the SecurityResouresTool
+ */
+public class SecurityResouresToolTestCase extends TestCase {
+
+    @Override //the setup method 
+    protected void setUp() throws Exception {
+        // To set the IOutput intialize the ResourcesTool
+        ResourcesTool  resTool = new ResourcesTool();
+        super.setUp();
+    }
+    
+    // Test for login-config.xml file loading
+    public void testSecurityResourcesFileMigration_file() {
+        File file = new File("test-apps/security/login-config.xml");
+        SecurityResourcesTool securityResourcesTool = new SecurityResourcesTool();
+        boolean result = securityResourcesTool.migrate(file);
+        assertTrue(result);
+    }
+}

Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/APIReplaceVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/APIReplaceVisitor.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/APIReplaceVisitor.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/APIReplaceVisitor.java Mon Jul  2 11:30:34 2007
@@ -0,0 +1,151 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+package org.apache.geronimo.j2g.sources.dependence;
+
+import java.util.List;
+
+import org.apache.geronimo.j2g.common.IOutput;
+import org.apache.geronimo.j2g.common.Tool;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTMatcher;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
+
+
+/**
+ * Finds specified names and replaces its by new one.
+ */
+public class APIReplaceVisitor extends ASTVisitor {
+
+	/** Name to replace */
+	private QualifiedName targetName;
+
+	/** New name */
+	private QualifiedName newName;
+
+	/** Compilation unit */
+	private CompilationUnit unit;
+
+	/** Nodes matcher */
+	private ASTMatcher matcher;
+
+	/** Output */
+	private IOutput out;
+
+	/** Import changing flag */
+	private boolean isImportAffected;
+
+	/** Changes counter */
+	private int changes = 0; 
+	
+	/**
+	 * Constructor. Creates new instance of APIReplaceVisitor.
+	 * @param unit compilation unit.
+	 * @param targetName target name.
+	 * @param newName new name.
+	 */
+	public APIReplaceVisitor(CompilationUnit unit, QualifiedName targetName, QualifiedName newName) {
+		super(false);
+		this.targetName = targetName;
+		this.newName = newName;
+		this.unit = unit;
+		matcher = new ASTMatcher(false);
+		out = Tool.getCurrent().getOutput();
+		isImportAffected = false;
+	}
+
+	/**
+	 * Replaces qualified names in imports.
+	 */
+	public boolean visit(ImportDeclaration importDeclaration) {
+		QualifiedName name = (QualifiedName) importDeclaration.getName();
+		if (!importDeclaration.isOnDemand()) {
+			int position = name.getStartPosition();
+			if (matcher.match(name, targetName)) {
+				isImportAffected = true;
+				AST ast = importDeclaration.getAST();
+				Name replacer = ast.newName(newName.getFullyQualifiedName());
+				printChanges(name, newName, unit.getLineNumber(position), unit.getColumnNumber(position));
+				importDeclaration.setName(replacer);
+			}
+		}
+		else {
+			if (matcher.match(name, targetName.getQualifier())) {
+				List imports = unit.imports();
+				AST ast = unit.getAST();
+				ImportDeclaration newImport = ast.newImportDeclaration();
+				newImport.setName(newName);
+				imports.add(newImport);
+				isImportAffected = true;
+				out.info("New import was added: '" + newName.getFullyQualifiedName()+"'.");
+				changes++;
+			}
+		}
+		return false;
+	}
+
+	/**
+	 * Replaces qualified name.
+	 */
+	public boolean visit(QualifiedName name) {
+		int position = name.getStartPosition();
+		if (matcher.match(name, targetName)) {
+			AST ast = name.getAST();
+			Name replacer = ast.newName(newName.getFullyQualifiedName());
+			StructuralPropertyDescriptor desc = name.getLocationInParent();
+			printChanges(name, newName, unit.getLineNumber(position), unit.getColumnNumber(position));
+			name.getParent().setStructuralProperty(desc, replacer);
+		}
+		return false;
+	}
+
+	/**
+	 * Replaces simple name.
+	 */
+	public boolean visit(SimpleName name) {
+		int position = name.getStartPosition();
+		if (matcher.match(name, targetName.getName()) && isImportAffected) {
+			printChanges(name, newName.getName(), unit.getLineNumber(position), unit.getColumnNumber(position));
+			name.setIdentifier(newName.getName().getIdentifier());
+		}
+		return false;
+	}
+
+	/**
+	 * Prints out about changes in compilation unit.
+	 * @param name replaced name.
+	 * @param newName new name.
+	 * @param row row in source unit.
+	 * @param col column in source unit.
+	 */
+	private void printChanges(Name name, Name newName, int row, int col) {
+		changes++;
+		out.info("Name '" + name.getFullyQualifiedName() + "' was replaced by '" + newName.getFullyQualifiedName() + "'.", row, col);
+	}
+
+	/**
+	 * @return the changes count
+	 */
+	public int getChanges() {
+		return changes;
+	}
+}

Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/DependenceJavaMigration.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/DependenceJavaMigration.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/DependenceJavaMigration.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/DependenceJavaMigration.java Mon Jul  2 11:30:34 2007
@@ -0,0 +1,269 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+
+package org.apache.geronimo.j2g.sources.dependence;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.geronimo.j2g.common.FatalToolException;
+import org.apache.geronimo.j2g.common.IJavaMigration;
+import org.apache.geronimo.j2g.common.IOutput;
+import org.apache.geronimo.j2g.common.RollbackManager;
+import org.apache.geronimo.j2g.common.Tool;
+import org.apache.geronimo.j2g.common.ToolConstants;
+import org.apache.geronimo.j2g.sources.dependence.compatibility.Anybody;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jface.text.Document;
+import org.eclipse.text.edits.TextEdit;
+
+/**
+ * Determines all references of the source compilation unit to classes which are incompatible with
+ * Geronimo.
+ */
+public class DependenceJavaMigration implements IJavaMigration {
+	/**
+	 * Plug-in name.
+	 */
+	private final static String PLUGIN_NAME = "Dependence plug-in";
+
+	/**
+	 * Tool output
+	 */
+	private IOutput out;
+	
+	/**
+	 * Property file with default Geronimo libraries names.
+	 */
+	private final String DEFAULT_LIBS_FILENAME = "../properties/org.apache.geronimo.j2g.sources.dependence/default_jars.properties";
+
+	/**
+	 * Set of default Geronimo libraries names.
+	 */
+	private static Set defaultLibs;
+
+	/**
+	 * Compatibility sources names.
+	 */
+	private final String COMPATIBILITY_SOURCES = "../properties/org.apache.geronimo.j2g.sources.dependence/compatible_sources.properties";
+
+	/**
+	 * Set of default Geronimo libraries names.
+	 */
+	private static Properties compatibilitySources;
+
+	/**
+	 * Property file with class analogies.
+	 */
+	private final String CLASS_ANALOGIES_FILENAME = "../properties/org.apache.geronimo.j2g.sources.dependence/class_analogies.properties";
+
+	/**
+	 * Properties with class analogies.
+	 */
+	private static Properties classAnalogies;
+
+	/**
+	 * Compatibles package qualified name.
+	 */
+	private static final String COMPATIBLES_PACKAGE = "org/apache/geronimo/j2g/sources/dependence/compatibility";
+
+	/**
+	 * Location of Compatibles Files.
+	 */
+	private static final String COMPATIBLES_LOCATION = "../compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility";
+	/**
+	 * Java resources extension.
+	 */
+	private static final String JAVA_EXT = ".java";
+
+	/**
+	 * Byte buffer size.
+	 */
+	private static final int BUFFER_SIZE = 1024;
+
+	/**
+	 * Constructor. Loads default libs names and class analogies names.
+	 * @throws FatalToolException if cannot load properties file with default jars names.
+	 */
+	public DependenceJavaMigration() throws FatalToolException {
+		super();
+		if (defaultLibs == null) {
+			try {
+				File propertyFile = new File(DEFAULT_LIBS_FILENAME);
+				Properties prop = new Properties();
+				prop.load(new FileInputStream(propertyFile));
+				defaultLibs = prop.keySet();
+			} catch (IOException e) {
+				throw new FatalToolException("Cannot load properties file with default jars names.");
+			}
+		}
+
+		if (classAnalogies == null) {
+			try {
+				File propertyFile = new File(CLASS_ANALOGIES_FILENAME);
+				classAnalogies = new Properties();
+				classAnalogies.load(new FileInputStream(propertyFile));
+			} catch (IOException e) {
+				throw new FatalToolException("Cannot load properties file with class analogies.");
+			}
+		}
+		if (compatibilitySources == null) {
+			try {
+				File propertyFile = new File(COMPATIBILITY_SOURCES);
+				compatibilitySources = new Properties();
+				compatibilitySources.load(new FileInputStream(COMPATIBILITY_SOURCES));
+			} catch (IOException e) {
+				throw new FatalToolException("Cannot load properties file with compatibility classnames.");
+			}
+
+		}
+	}
+
+	/**
+	 * Determines all references of the source compilation unit to classes which are incompatible
+	 * with Geronimo.
+	 * @param source compilation unit for migration.
+	 */
+	public boolean migrate(ASTNode source) {
+		out = Tool.getCurrent().getOutput();
+		if (source instanceof CompilationUnit) {
+			CompilationUnit compilationUnit = (CompilationUnit) source;
+			String unitName = compilationUnit.getJavaElement().getElementName();
+			boolean isSourceChanged = false;
+			out.info("[" + PLUGIN_NAME + "] " + "Migration started: " + unitName);
+			Set replacedClasses = classAnalogies.keySet();
+			AST ast = compilationUnit.getAST();
+			Iterator classesIterator = replacedClasses.iterator();
+			while (classesIterator.hasNext()) {
+				String targetStr = (String) classesIterator.next();
+				String newStr = classAnalogies.getProperty(targetStr);
+				Name replaced = ast.newName(targetStr);
+				Name replacer = ast.newName(newStr);
+
+				if (replaced.isQualifiedName() && replacer.isQualifiedName()) {
+					QualifiedName targetName = (QualifiedName) replaced;
+					QualifiedName newName = (QualifiedName) replacer;
+					APIReplaceVisitor apiReplacer = new APIReplaceVisitor(compilationUnit, targetName, newName);
+					compilationUnit.accept(apiReplacer);
+					apiReplacer.visit(compilationUnit);
+					isSourceChanged = isSourceChanged || (apiReplacer.getChanges() > 0);
+				}
+				else {
+					out.error("Wrong class names for JBoss classes and it's Geronimo analogies in property file");
+					break;
+				}
+
+			}
+			try {
+				if (isSourceChanged) {
+					String path = compilationUnit.getJavaElement().getUnderlyingResource().getLocation().toPortableString();
+					String package_path = compilationUnit.getPackage().getName().getFullyQualifiedName().replace('.', IPath.SEPARATOR);
+					String src_path = path.substring(0, path.indexOf(package_path));
+					String compatible_dir = src_path + COMPATIBLES_PACKAGE;
+					File pack = new File(compatible_dir);
+					File sourceDir = new File(COMPATIBLES_LOCATION);
+					if (!pack.exists()) {
+						pack.mkdirs();
+						Set compatibleSources = compatibilitySources.keySet();
+						Iterator keys = compatibleSources.iterator();
+						while (keys.hasNext()) {
+							String classname = (String)keys.next();
+							String sourceName = classname.substring(classname.lastIndexOf('.') + 1) + JAVA_EXT;
+							File addedSource = new File(pack, sourceName);
+							addedSource.createNewFile();
+							PrintWriter writer = new PrintWriter(new FileOutputStream(addedSource));
+							InputStream inStream = new FileInputStream(new File(sourceDir,sourceName));
+
+							byte[] buffer = new byte[BUFFER_SIZE];
+							int len = 0;
+							while ((len = inStream.read(buffer)) > 0) {
+								String outpt = new String(buffer, 0, len);
+								writer.print(outpt);
+							}
+							inStream.close();
+							writer.close();
+						}
+						IWorkspace workspace = ResourcesPlugin.getWorkspace();
+						IProject project = workspace.getRoot().getProject(ToolConstants.TEMPORARY_PROJECT_NAME);
+						project.refreshLocal(IResource.DEPTH_INFINITE, null);
+					}
+					ICompilationUnit isource = (ICompilationUnit) compilationUnit.getJavaElement();
+					String contents = isource.getBuffer().getContents();
+					File file = new File(isource.getUnderlyingResource().getLocation().toOSString() + RollbackManager.BACKUP_SUFFIX);
+					file.createNewFile();
+					FileOutputStream fout = new FileOutputStream(file);
+					fout.write(contents.getBytes());
+					fout.close();
+					Document document = new Document(contents);
+					TextEdit edits = compilationUnit.rewrite(document, isource.getJavaProject().getOptions(true));
+					edits.apply(document);
+					String newSource = document.get();
+					isource.getBuffer().setContents(newSource);
+					isource.save(null, true);
+
+					ASTParser parser = ASTParser.newParser(AST.JLS3);
+					parser.setResolveBindings(true);
+					parser.setSource(isource);
+					compilationUnit = (CompilationUnit) parser.createAST(null);
+				}
+			} catch (IOException ex) {
+				out.fatal("The plug-in cannot add compatible package or save buckup because of I/O error occurs. Make sure that the source directories are not under write protection.");
+			} catch (Exception e) {
+				out.fatal("The plug-in cannot get access to the resources. Make sure that the source files are not under write protection or not deleted by another process.");
+			}
+			NodesVisitor visitor = new NodesVisitor(compilationUnit);
+			compilationUnit.accept(visitor);
+			visitor.visit(compilationUnit);
+			boolean isSourceValid = visitor.isSourceValid();
+			if (isSourceChanged && !isSourceValid) {
+				out.warn("Errors were found in source file! Changes were saved. The original file was saved with name " + unitName + RollbackManager.BACKUP_SUFFIX);
+			}
+			out.info("[" + PLUGIN_NAME + "] " + "Migration finished: " + unitName);
+			return false;
+		}
+		else {
+			out.error("[" + PLUGIN_NAME + "] " + "Wrong type of source node.");
+		}
+		return false;
+	}
+
+	/**
+	 * @return set of default lib names.
+	 */
+	public static Set getDefaultLibs() {
+		return defaultLibs;
+	}
+}

Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/NodesVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/NodesVisitor.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/NodesVisitor.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/NodesVisitor.java Mon Jul  2 11:30:34 2007
@@ -0,0 +1,353 @@
+package org.apache.geronimo.j2g.sources.dependence;
+
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.geronimo.j2g.common.FatalToolException;
+import org.apache.geronimo.j2g.common.IOutput;
+import org.apache.geronimo.j2g.common.Tool;
+import org.apache.geronimo.j2g.common.ToolConstants;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.IBinding;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.QualifiedType;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SimpleType;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+
+
+/**
+ * Visitor for ASTNode. Finds types dependencies and reports to tool output.
+ */
+public class NodesVisitor extends ASTVisitor {
+	/**
+	 * Tool output.
+	 */
+	private IOutput out;
+
+	/**
+	 * Current compilation unit.
+	 */
+	private CompilationUnit unit;
+
+	/**
+	 * Set of declared variables.
+	 */
+	private Set vars;
+
+	/**
+	 * Set of already picked libraries.
+	 */
+	private Set linkedLibs;
+
+	/**
+	 * Set of declared classes in imports.
+	 */
+	private Set imports;
+
+	/**
+	 * 
+	 */
+	
+	private boolean wrongApiUsing;
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param unit
+	 *            compilation unit which will be visited.
+	 * @param out
+	 * @param visitDocTypes
+	 */
+	public NodesVisitor(CompilationUnit unit) {
+		super(false);
+		this.out = Tool.getCurrent().getOutput();
+		this.unit = unit;
+		vars = new HashSet();
+		linkedLibs = new HashSet();
+		imports = new HashSet();
+		wrongApiUsing = false;
+		
+		List compUnitList = unit.imports();
+		Iterator listIter = compUnitList.iterator();
+		while (listIter.hasNext()) {
+			ImportDeclaration impDec = (ImportDeclaration)listIter.next();
+			if (impDec.getName().isQualifiedName()) {
+				QualifiedName qualifiedName = (QualifiedName) impDec.getName();
+				String className = qualifiedName.getName().getIdentifier();
+				imports.add(className);
+			}
+			else {
+				SimpleName simpleName = (SimpleName) impDec.getName();
+				imports.add(simpleName.getIdentifier());
+			}
+		}
+	}
+
+	/**
+	 * Solves binding and if it's corressponds to Geronimo repository library
+	 * warns about it.
+	 * 
+	 * @param binding
+	 * @throws FatalToolException
+	 */
+	private void solveBinding(IBinding binding, String name) {
+		if (binding instanceof ITypeBinding) {
+			try {
+				String linkedJarName = binding.getJavaElement().getPath().toFile().getName();
+				if (linkedJarName.startsWith(ToolConstants.GERONIMO_REP)) {
+					File lib = binding.getJavaElement().getUnderlyingResource().getRawLocation().toFile();
+					String artifactName = getGeronimoArtifactName(lib);
+					if (!linkedLibs.contains(lib.getName()) && !DependenceJavaMigration.getDefaultLibs().contains(artifactName)) {
+						out.warn("You should add '" + artifactName + "' dependency.");
+						linkedLibs.add(lib.getName());
+					}
+				}
+			} catch (JavaModelException e) {
+				out.fatal("Cannot get access to library for resolve name'" + name + "'.");
+			}
+		}
+	}
+
+	/**
+	 * Visits {@link ImportDeclaration} and trying to resolve binding.
+	 */
+	public boolean visit(ImportDeclaration importDeclaration) {
+		if (importDeclaration.resolveBinding() != null) {
+			String name = importDeclaration.getName().getFullyQualifiedName();
+			solveBinding(importDeclaration.resolveBinding(), name);
+		}
+		else {
+			printImportError(importDeclaration.getName().getFullyQualifiedName(), importDeclaration.getStartPosition());
+			if (importDeclaration.getName().isQualifiedName()) {
+				QualifiedName qualifiedName = (QualifiedName) importDeclaration.getName();
+				String className = qualifiedName.getName().getIdentifier();
+				imports.add(className);
+			}
+			else {
+				SimpleName simpleName = (SimpleName) importDeclaration.getName();
+				imports.add(simpleName.getIdentifier());
+			}
+		}
+		return false;
+	}
+
+	/**
+	 * Visits {@link QualifiedType} and trying to resolve binding.
+	 */
+	public boolean visit(QualifiedType qualifiedType) {
+		if (qualifiedType.resolveBinding() != null) {
+			String name = qualifiedType.getName().getFullyQualifiedName();
+			solveBinding(qualifiedType.resolveBinding(), name);
+			return true;
+		}
+		else {
+			Type qualifier = qualifiedType.getQualifier();
+			if (qualifier instanceof QualifiedType) {
+				if (visit((QualifiedType) qualifier)) {
+					printTypeError(qualifiedType.getName().getFullyQualifiedName(), qualifiedType.getStartPosition());
+				}
+			}
+			else {
+				if (visit((SimpleType) qualifier)) {
+					printTypeError(qualifiedType.getName().getFullyQualifiedName(), qualifiedType.getStartPosition());
+				}
+			}
+		}
+		return false;
+	}
+
+	/**
+	 * Visits {@link SimpleType} and trying to resolve binding.
+	 */
+	public boolean visit(SimpleType simpleType) {
+		if (simpleType.resolveBinding() != null) {
+			String name = simpleType.getName().getFullyQualifiedName(); 
+			solveBinding(simpleType.resolveBinding(), name );
+		}
+		else {
+			printTypeError(simpleType.getName().getFullyQualifiedName(), simpleType.getStartPosition());
+		}
+		return false;
+	}
+
+	/**
+	 * Visits {@link QualifiedName} and trying to resolve binding.
+	 */
+	public boolean visit(QualifiedName qualifiedName) {
+		if (qualifiedName.resolveBinding() != null) {
+			String name = qualifiedName.getFullyQualifiedName();
+			solveBinding(qualifiedName.resolveBinding(), name);
+			return true;
+		}
+		else {
+			Name qualifiedPart = qualifiedName.getQualifier();
+			if (qualifiedPart instanceof QualifiedName) {
+				if (visit((QualifiedName) qualifiedPart)) {
+					printTypeError(qualifiedName.getFullyQualifiedName(), qualifiedName.getStartPosition());
+				}
+				return false;
+			}
+			else {
+				if (qualifiedPart.resolveBinding() != null) {
+					printTypeError(qualifiedName.getFullyQualifiedName(), qualifiedName.getStartPosition());
+				}
+				else {
+					if (!isDeclaredVar(qualifiedPart.toString())) {
+						printTypeError(qualifiedPart.getFullyQualifiedName(), qualifiedPart.getStartPosition());
+					}
+				}
+			}
+		}
+		return false;
+	}
+
+	/**
+	 * Visits {@link MethodDeclaration} and trying to resolve binding.
+	 */
+	public boolean visit(MethodDeclaration method) {
+		List names = method.thrownExceptions();
+		if (names != null) {
+			Iterator iter = names.iterator();
+			while (iter.hasNext()) {
+				Name name = (Name) iter.next();
+				if (name.resolveBinding() != null) {
+					String nameStr = name.getFullyQualifiedName();
+					solveBinding(name.resolveBinding(), nameStr);
+				}
+				else {
+					printTypeError(name.getFullyQualifiedName(), name.getStartPosition());
+				}
+			}
+		}
+		return true;
+	}
+
+	/**
+	 * Visits {@link MethodInvocation} and trying to resolve binding.
+	 */
+	public boolean visit(MethodInvocation methodInvocation) {
+		Expression expr = methodInvocation.getExpression();
+		if (expr == null) {
+			if (methodInvocation.resolveMethodBinding() == null) {
+				printTypeError(methodInvocation.getName().getFullyQualifiedName(), methodInvocation.getStartPosition());
+			}
+		}
+		else {
+			if (expr.resolveTypeBinding() != null) {
+				String name = expr.toString();
+				solveBinding(expr.resolveTypeBinding(), name);
+			}
+			else {
+				if (expr instanceof MethodInvocation) {
+					visit((MethodInvocation) expr);
+				}
+				else if (expr instanceof QualifiedName) {
+					visit((QualifiedName) expr);
+				}
+				else if (expr instanceof SimpleName) {
+					if (!isDeclaredVar(expr.toString())) {
+						SimpleName simpleName = (SimpleName) expr;
+						printTypeError(simpleName.getFullyQualifiedName(), expr.getStartPosition());
+					}
+				}
+			}
+		}
+		return true;
+	}
+
+	/**
+	 * Visits {@link SingleVariableDeclaration} and adds variable name to the
+	 * list.
+	 */
+	public boolean visit(SingleVariableDeclaration declaration) {
+		vars.add(declaration.getName().toString());
+		return true;
+	}
+
+	/**
+	 * Visits {@link VariableDeclarationFragment} and adds variable name to the
+	 * list.
+	 */
+	public boolean visit(VariableDeclarationFragment declaration) {
+		vars.add(declaration.getName().toString());
+		return true;
+	}
+
+	/**
+	 * @param name
+	 *            simple name.
+	 * @return <code>true</code> if it is declared variable and
+	 *         <code>false</code> if not.
+	 */
+	private boolean isDeclaredVar(String name) {
+		return vars.contains(name);
+	}
+
+	/**
+	 * Prints error about not resolved name.
+	 * 
+	 * @param name
+	 *            not resolved name.
+	 * @param position
+	 *            start position in source file.
+	 */
+	private void printTypeError(String name, int position) {
+		if (!imports.contains(name)) {
+			out.error("The name '" + name + "' cannot be resolved.", unit.getLineNumber(position), unit.getColumnNumber(position));
+			wrongApiUsing = true;
+		}
+	}
+
+	/**
+	 * Prints error about not resolved import.
+	 * 
+	 * @param name
+	 *            import name.
+	 * @param position
+	 *            start position in source file.
+	 */
+	private void printImportError(String name, int position) {
+		wrongApiUsing = true;
+		out.error("The import '" + name + "' cannot be resolved.", unit.getLineNumber(position), unit.getColumnNumber(position));
+	}
+	
+	/**
+	 * Constructs Geronimo artifact name from repository library file.
+	 * 
+	 * @param libFullName
+	 *            full path to the repository library.
+	 * @return Geronimo artifact name.
+	 */
+	private String getGeronimoArtifactName(File libFullName) {
+		String fullName = libFullName.getAbsolutePath();
+		String geronimoRep = ToolConstants.GERONIMO_REPOSITORY_FOLDER + File.separator;
+		String name = fullName.substring(fullName.lastIndexOf(geronimoRep) + geronimoRep.length());
+		name = name.substring(0, name.indexOf(libFullName.getName()));
+		name = name.replace(File.separatorChar, ToolConstants.GERONIMO_SEPARATOR_CHAR);
+		String extension = fullName.substring(fullName.lastIndexOf('.') + 1);
+		return name + extension;
+	}
+	
+	/**
+	 * @return true if source uses proprietary api.
+	 */
+	public boolean isSourceValid(){
+		return !wrongApiUsing;
+	}
+	
+}

Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/Anybody.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/Anybody.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/Anybody.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/Anybody.java Mon Jul  2 11:30:34 2007
@@ -0,0 +1,60 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+/*
+ * Auto-generated by J2G Migration. 
+ */
+package org.apache.geronimo.j2g.sources.dependence.compatibility;
+
+import java.security.Principal;
+
+public class Anybody
+    implements Comparable, Principal
+{
+
+    public Anybody()
+    {
+    }
+
+    public int hashCode()
+    {
+        return ANYBODY.hashCode();
+    }
+
+    public String getName()
+    {
+        return ANYBODY;
+    }
+
+    public String toString()
+    {
+        return ANYBODY;
+    }
+
+    public boolean equals(Object another)
+    {
+        return true;
+    }
+
+    public int compareTo(Object o)
+    {
+        return 0;
+    }
+
+    public static final String ANYBODY = "<ANYBODY>";
+    public static final Anybody ANYBODY_PRINCIPAL = new Anybody();
+
+}
\ No newline at end of file

Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/DigestCallback.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/DigestCallback.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/DigestCallback.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/DigestCallback.java Mon Jul  2 11:30:34 2007
@@ -0,0 +1,32 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+/*
+ * Auto-generated by J2G Migration. 
+ */
+package org.apache.geronimo.j2g.sources.dependence.compatibility;
+
+import java.security.MessageDigest;
+import java.util.Map;
+
+public interface DigestCallback {
+
+  public abstract void init(Map map);
+
+  public abstract void preDigest(MessageDigest digest);
+
+  public abstract void postDigest(MessageDigest digest);
+}

Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/GeronimoLoginModule.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/GeronimoLoginModule.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/GeronimoLoginModule.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/GeronimoLoginModule.java Mon Jul  2 11:30:34 2007
@@ -0,0 +1,352 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+/*
+ * Auto-generated by J2G Migration. 
+ */
+package org.apache.geronimo.j2g.sources.dependence.compatibility;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.FailedLoginException;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+
+import org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal;
+import org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal;
+
+public abstract class GeronimoLoginModule implements LoginModule {
+
+	protected Subject subject;
+
+	protected CallbackHandler callbackHandler;
+
+	protected Map sharedState;
+
+	protected Map options;
+
+	protected boolean useFirstPass;
+
+	protected boolean loginOk;
+
+	protected String principalClassName;
+
+	protected Principal unauthenticatedIdentity;
+
+	private Principal identity;
+
+	private char passport[];
+
+	private String algorithm;
+
+	private String charset;
+
+	private String encoding;
+
+	private boolean ignorePasswordCase;
+
+	protected final static int USERNAME_POS = 0;
+
+	protected final static int PASSWORD_POS = 1;
+
+	public GeronimoLoginModule() {
+		algorithm = null;
+		charset = null;
+		encoding = null;
+	}
+
+	public boolean abort() throws LoginException {
+		return true;
+	}
+
+	public boolean commit() throws LoginException {
+		if (!loginOk) {
+			return false;
+		}
+		Set heads = subject.getPrincipals();
+		Principal identity = getIdentity();
+		heads.add(identity);
+		Group roleSets[] = getRoleSets();
+		for (int i = 0; i < roleSets.length; i++) {
+			Group group = roleSets[i];
+			String name = group.getName();
+			Group subjectGroup = createGroup(name, heads);
+			Principal role;
+			Enumeration members = group.members();
+			while (members.hasMoreElements()) {
+				role = (Principal) members.nextElement();
+				subjectGroup.addMember(role);
+				if(name.equals("Roles")){
+					heads.add(new GeronimoGroupPrincipal(role.getName()));
+				}
+			}
+		}
+		return true;
+	}
+
+	protected Principal getIdentity() {
+		return identity;
+	}
+
+	public void initialize(Subject subject, CallbackHandler callbackHandler,
+			Map sharedState, Map options) {
+		this.subject = subject;
+		this.callbackHandler = callbackHandler;
+		this.sharedState = sharedState;
+		this.options = options;
+		String passwordStacking = (String) options.get("password-stacking");
+		if (passwordStacking != null
+				&& passwordStacking.equalsIgnoreCase("useFirstPass")) {
+			useFirstPass = true;
+		}
+		principalClassName = (String) options.get("principalClass");
+		String name = (String) options.get("unauthenticatedIdentity");
+		if (name != null) {
+			try {
+				unauthenticatedIdentity = createIdentity(name);
+			} catch (Exception e) {
+			}
+		}
+		algorithm = (String) options.get("hashAlgorithm");
+		if (algorithm != null) {
+			encoding = (String) options.get("hashEncoding");
+			if (encoding == null) {
+				encoding = "BASE64";
+			}
+			charset = (String) options.get("hashCharset");
+		}
+		String flag = (String) options.get("ignorePasswordCase");
+		ignorePasswordCase = Boolean.valueOf(flag).booleanValue();
+	}
+
+	public boolean login() throws LoginException {
+		loginOk = false;
+		if (useFirstPass) {
+			Object identity = sharedState.get("javax.security.auth.login.name");
+			Object credential = sharedState
+					.get("javax.security.auth.login.password");
+			if (identity != null && credential != null) {
+				loginOk = true;
+			}
+		}
+		if (loginOk) {
+			Object username = sharedState.get("javax.security.auth.login.name");
+			if (username instanceof Principal) {
+				identity = (Principal) username;
+			} else {
+				try {
+					identity = createIdentity(username.toString());
+				} catch (Exception e) {
+					throw new LoginException("Failed to create principal: "
+							+ e.getMessage());
+				}
+			}
+			Object password = sharedState
+					.get("javax.security.auth.login.password");
+
+			if (password != null) {
+				if (password instanceof char[]) {
+					passport = (char[]) password;
+				} else {
+					passport = password.toString().toCharArray();
+				}
+			}
+			return true;
+		}
+		loginOk = false;
+
+		String username = null;
+		String password = null;
+
+		String[] usernameAndPassword = getUsernameAndPassword();
+
+		username = usernameAndPassword[USERNAME_POS];
+		password = usernameAndPassword[PASSWORD_POS];
+		if (username == null && password == null) {
+			identity = unauthenticatedIdentity;
+		}
+		if (identity == null) {
+			try {
+				identity = createIdentity(username);
+			} catch (Exception e) {
+				throw new LoginException("Failed to create principal: "
+						+ e.getMessage());
+			}
+			if (algorithm != null) {
+				password = createPasswordHash(username, password);
+			}
+			String expectedPassword = getUsersPassword();
+			if (!validatePassword(password, expectedPassword)) {
+				throw new FailedLoginException(
+						"Password Incorrect/Password Required");
+			}
+		}
+		if (getUseFirstPass()) {
+			sharedState.put("javax.security.auth.login.name", username);
+			sharedState.put("javax.security.auth.login.password", passport);
+		}
+		loginOk = true;
+		return loginOk;
+	}
+
+	protected String[] getUsernameAndPassword() throws LoginException {
+		String usernamePassword[] = { null, null };
+		if (callbackHandler == null) {
+			throw new LoginException(
+					"Error occurs: there are no CallbackHandler available to get information about authentication");
+		}
+		String username = null;
+		String password = null;
+		try {
+			Callback callbacks[] = { new NameCallback("Username: "), new PasswordCallback("Password: ", false) };
+			callbackHandler.handle(callbacks);
+			NameCallback nameCallback = (NameCallback) callbacks[0];
+			PasswordCallback passwordCallback = (PasswordCallback) callbacks[1];
+			username = nameCallback.getName();
+			char helperPassword[] = passwordCallback.getPassword();
+			if (helperPassword != null) {
+				passport = new char[helperPassword.length];
+				System.arraycopy(helperPassword, 0, passport, 0,
+						helperPassword.length);
+				passwordCallback.clearPassword();
+				password = new String(passport);
+			}
+		} catch (IOException ioe) {
+			throw new LoginException(ioe.toString());
+		} catch (UnsupportedCallbackException uce) {
+			throw new LoginException("CallbackHandler does not support: "
+					+ uce.getCallback());
+		}
+		usernamePassword[USERNAME_POS] = username;
+		usernamePassword[PASSWORD_POS] = password;
+		return usernamePassword;
+	}
+
+	protected boolean validatePassword(String inputPassword,
+			String expectedPassword) {
+		if (inputPassword == null || expectedPassword == null) {
+			return false;
+		}
+		return ignorePasswordCase ? inputPassword
+				.equalsIgnoreCase(expectedPassword) : inputPassword
+				.equals(expectedPassword);
+	}
+
+	protected String createPasswordHash(String username, String password) {
+		DigestCallback callback = null;
+		String callbackClassName = (String) options.get("digestCallback");
+		if (callbackClassName != null) {
+			try {
+				Class callbackClass = loadSomeClass(callbackClassName);
+				callback = (DigestCallback) callbackClass.newInstance();
+			} catch (Exception e) {
+				SecurityException securityExeption = new SecurityException(
+						"Cannot load DigestCallback");
+				securityExeption.initCause(e);
+				throw securityExeption;
+			}
+			HashMap optionsMap = new HashMap(options);
+			optionsMap.put("javax.security.auth.login.name", username);
+			optionsMap.put("javax.security.auth.login.password", password);
+			callback.init(optionsMap);
+		}
+
+		return PasswordHasher.calculateHash(algorithm, encoding, charset,
+				username, password, callback);
+	}
+
+	protected boolean getUseFirstPass() {
+		return useFirstPass;
+	}
+
+	protected Principal getUnauthenticatedIdentity() {
+		return unauthenticatedIdentity;
+	}
+
+	protected Object getCredentials() {
+		return passport;
+	}
+
+	public boolean logout() throws LoginException {
+		Principal identity = getIdentity();
+		Set principals = subject.getPrincipals();
+		principals.remove(identity);
+		return true;
+	}
+
+	protected Principal createIdentity(String username) throws Exception {
+		Principal principal = null;
+		if (principalClassName != null) {
+			Class loadedClass = loadSomeClass(principalClassName);
+			Class signatures[] = { java.lang.String.class };
+			Constructor constructorInstance = loadedClass
+					.getConstructor(signatures);
+			Object argumentsForConstructor[] = { username };
+			principal = (Principal) constructorInstance
+					.newInstance(argumentsForConstructor);
+		} else {
+			principal = new GeronimoUserPrincipal(username);
+		}
+		return principal;
+	}
+
+	private Class loadSomeClass(String classname) throws ClassNotFoundException {
+		ClassLoader loader = Thread.currentThread().getContextClassLoader();
+		return loader.loadClass(classname);
+	}
+
+	protected String getUsername() {
+		return (getIdentity() != null) ? getIdentity().getName() : null;
+	}
+
+	protected Group createGroup(String name, Set principals) {
+		Group roles = null;
+		Iterator principalsIter = principals.iterator();
+		while (principalsIter.hasNext()) {
+			Object next = principalsIter.next();
+			if (next instanceof Group) {
+				Group nextGroup = (Group) next;
+				if (nextGroup.getName().equals(name)) {
+					roles = nextGroup;
+					break;
+				}
+			}
+		}
+		if (roles == null) {
+			roles = new GeronimoSimpleGroup(name);
+			principals.add(roles);
+		}
+		return roles;
+	}
+
+	protected abstract String getUsersPassword() throws LoginException;
+
+	protected abstract Group[] getRoleSets() throws LoginException;
+}
\ No newline at end of file

Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/GeronimoSimpleGroup.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/GeronimoSimpleGroup.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/GeronimoSimpleGroup.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/GeronimoSimpleGroup.java Mon Jul  2 11:30:34 2007
@@ -0,0 +1,97 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.
+ */
+ /*
+ * Auto-generated by J2G Migration. 
+ */
+package org.apache.geronimo.j2g.sources.dependence.compatibility;
+
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal;
+
+public class GeronimoSimpleGroup extends GeronimoGroupPrincipal implements Group {
+
+	/**
+	 * Serial ID.
+	 */
+	private static final long serialVersionUID = 4220122854158936883L;
+
+	private HashMap members;
+
+	public GeronimoSimpleGroup(String name) {
+		super(name);
+		members = new HashMap(3);
+	}
+
+	public boolean addMember(Principal user) {
+		boolean isMember = members.containsKey(user);
+		if (!isMember) {
+			members.put(user, user);
+		}
+		return !isMember;
+	}
+
+	public boolean isMember(Principal member) {
+		boolean isMember = members.containsKey(member);
+		if (!isMember) {
+			isMember = member instanceof Anybody;
+			if (!isMember && (member instanceof Nobody)) {
+				return false;
+			}
+		}
+
+		if (!isMember) {
+			Collection values = members.values();
+			Iterator iter = values.iterator();
+			do {
+				if (isMember || !iter.hasNext()) {
+					break;
+				}
+				Object next = iter.next();
+				if (next instanceof Group) {
+					Group group = (Group) next;
+					isMember = group.isMember(member);
+				}
+			} while (true);
+		}
+		return isMember;
+	}
+
+	public Enumeration members() {
+		return Collections.enumeration(members.values());
+	}
+
+	public boolean removeMember(Principal user) {
+		return (members.remove(user) != null);
+	}
+
+	public String toString() {
+		String tmp = new String(getName());
+		tmp.concat("(MEMBERS:");
+		for (Iterator iter = members.keySet().iterator(); iter.hasNext(); tmp.concat(",")) {
+			tmp.concat(iter.next().toString());
+		}
+		tmp.concat(")");
+		return tmp.toString();
+	}
+}



Mime
View raw message