You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dw...@apache.org on 2007/06/13 15:24:14 UTC
svn commit: r546862 - in /geronimo/sandbox/j2g:
plugins/org.apache.geronimo.j2g.resources.mail/test-apps/mail/
plugins/org.apache.geronimo.j2g.sources.dependence/
plugins/org.apache.geronimo.j2g.sources.dependence/src/org/apache/geronimo/j2g/sources/de...
Author: dwoods
Date: Wed Jun 13 06:24:13 2007
New Revision: 546862
URL: http://svn.apache.org/viewvc?view=rev&rev=546862
Log:
GERONIMO-3241 The J2G Sources tool should have the ability to easily add compatibility classes
Added:
geronimo/sandbox/j2g/src/main/resources/compatibility/
geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/
geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/Anybody.java (with props)
geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/DigestCallback.java (with props)
geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/GeronimoLoginModule.java (with props)
geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/GeronimoSimpleGroup.java (with props)
geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/Nobody.java (with props)
geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/PasswordHasher.java (with props)
Modified:
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources.mail/test-apps/mail/mail-geronimo-plan.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.dependence/pom.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.dependence/src/org/apache/geronimo/j2g/sources/dependence/DependenceJavaMigration.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.environment/src/org/apache/geronimo/j2g/sources/environment/AbsoluteNameSolver.java
Modified: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources.mail/test-apps/mail/mail-geronimo-plan.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources.mail/test-apps/mail/mail-geronimo-plan.xml?view=diff&rev=546862&r1=546861&r2=546862
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources.mail/test-apps/mail/mail-geronimo-plan.xml (original)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources.mail/test-apps/mail/mail-geronimo-plan.xml Wed Jun 13 06:24:13 2007
@@ -7,7 +7,7 @@
<artifactId>Mail</artifactId>
<version>1.0</version>
<type>car</type>
- </moduleId>
+ </moduleId>
<dependencies>
<dependency>
<groupId>geronimo</groupId>
Modified: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.dependence/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.dependence/pom.xml?view=diff&rev=546862&r1=546861&r2=546862
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.dependence/pom.xml (original)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.dependence/pom.xml Wed Jun 13 06:24:13 2007
@@ -36,13 +36,6 @@
<include>plugin.xml</include>
</includes>
</resource>
- <resource>
- <directory>src/org/apache/geronimo/j2g/sources/dependence/compatibility</directory>
- <targetPath>org/apache/geronimo/j2g/sources/dependence/compatibility</targetPath>
- <includes>
- <include>*.java</include>
- </includes>
- </resource>
<resource>
<directory>lib</directory>
<targetPath>lib</targetPath>
Modified: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.dependence/src/org/apache/geronimo/j2g/sources/dependence/DependenceJavaMigration.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.dependence/src/org/apache/geronimo/j2g/sources/dependence/DependenceJavaMigration.java?view=diff&rev=546862&r1=546861&r2=546862
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.dependence/src/org/apache/geronimo/j2g/sources/dependence/DependenceJavaMigration.java (original)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.dependence/src/org/apache/geronimo/j2g/sources/dependence/DependenceJavaMigration.java Wed Jun 13 06:24:13 2007
@@ -100,6 +100,10 @@
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";
@@ -189,6 +193,7 @@
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();
@@ -199,7 +204,7 @@
File addedSource = new File(pack, sourceName);
addedSource.createNewFile();
PrintWriter writer = new PrintWriter(new FileOutputStream(addedSource));
- InputStream inStream = Anybody.class.getResourceAsStream(sourceName);
+ InputStream inStream = new FileInputStream(new File(sourceDir,sourceName));
byte[] buffer = new byte[BUFFER_SIZE];
int len = 0;
Modified: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.environment/src/org/apache/geronimo/j2g/sources/environment/AbsoluteNameSolver.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.environment/src/org/apache/geronimo/j2g/sources/environment/AbsoluteNameSolver.java?view=diff&rev=546862&r1=546861&r2=546862
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.environment/src/org/apache/geronimo/j2g/sources/environment/AbsoluteNameSolver.java (original)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.environment/src/org/apache/geronimo/j2g/sources/environment/AbsoluteNameSolver.java Wed Jun 13 06:24:13 2007
@@ -17,6 +17,7 @@
package org.apache.geronimo.j2g.sources.environment;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -48,16 +49,16 @@
private static int counter = 0;
/** Property file with EJB interfaces */
- public final static String INTEFACES_PROP = "../properites/org.apache.geronimo.j2g.sources.environment/beans-interfaces.properties";
+ public final static String INTEFACES_PROP = "../properties/org.apache.geronimo.j2g.sources.environment/beans-interfaces.properties";
/** Property file with paths for searching types in jboss.xml */
- public final static String BEANS_TYPES_PROP = "../properites/org.apache.geronimo.j2g.sources.environment/beans-types.properties";
+ public final static String BEANS_TYPES_PROP = "../properties/org.apache.geronimo.j2g.sources.environment/beans-types.properties";
/**
* Property file with paths for searching home and remote interfaces in
* ejb-jar.xml
*/
- public final static String BEANS_REFS_PROP = "../properites/org.apache.geronimo.j2g.sources.environment/beans-references.properties";
+ public final static String BEANS_REFS_PROP = "../properties/org.apache.geronimo.j2g.sources.environment/beans-references.properties";
/** References in ejb-jar.xml to be found */
private final static String[] EJB_REFS = { "ejb-ref", "ejb-local-ref",
@@ -430,7 +431,10 @@
if (interfaces == null) {
interfaces = new Properties();
try {
- interfaces.load(getClass().getResourceAsStream(INTEFACES_PROP));
+ File temp = new File(INTEFACES_PROP);
+ System.out.println("I think I'm here " + temp.getAbsolutePath());
+ File propertyFile = new File(INTEFACES_PROP);
+ interfaces.load(new FileInputStream(propertyFile));
} catch (IOException ex) {
throw new NameSolvingException(
"Cannot read system property file: " + INTEFACES_PROP,
@@ -441,8 +445,8 @@
if (beansTypes == null) {
beansTypes = new Properties();
try {
- beansTypes.load(getClass()
- .getResourceAsStream(BEANS_TYPES_PROP));
+ File propertyFile = new File(BEANS_TYPES_PROP);
+ beansTypes.load(new FileInputStream(propertyFile));
} catch (IOException ex) {
throw new NameSolvingException(
"Cannot read system property file: " + BEANS_TYPES_PROP,
@@ -453,7 +457,8 @@
if (beansRefs == null) {
beansRefs = new Properties();
try {
- beansRefs.load(getClass().getResourceAsStream(BEANS_REFS_PROP));
+ File propertyFile = new File(BEANS_REFS_PROP);
+ beansRefs.load(new FileInputStream(propertyFile));
} catch (IOException ex) {
throw new NameSolvingException(
"Cannot read system property file: " + BEANS_REFS_PROP,
Added: geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/Anybody.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/Anybody.java?view=auto&rev=546862
==============================================================================
--- geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/Anybody.java (added)
+++ geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/Anybody.java Wed Jun 13 06:24:13 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();
+
+}
Propchange: geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/Anybody.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/DigestCallback.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/DigestCallback.java?view=auto&rev=546862
==============================================================================
--- geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/DigestCallback.java (added)
+++ geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/DigestCallback.java Wed Jun 13 06:24:13 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);
+}
Propchange: geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/DigestCallback.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/GeronimoLoginModule.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/GeronimoLoginModule.java?view=auto&rev=546862
==============================================================================
--- geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/GeronimoLoginModule.java (added)
+++ geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/GeronimoLoginModule.java Wed Jun 13 06:24:13 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;
+}
Propchange: geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/GeronimoLoginModule.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/GeronimoSimpleGroup.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/GeronimoSimpleGroup.java?view=auto&rev=546862
==============================================================================
--- geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/GeronimoSimpleGroup.java (added)
+++ geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/GeronimoSimpleGroup.java Wed Jun 13 06:24:13 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();
+ }
+}
Propchange: geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/GeronimoSimpleGroup.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/Nobody.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/Nobody.java?view=auto&rev=546862
==============================================================================
--- geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/Nobody.java (added)
+++ geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/Nobody.java Wed Jun 13 06:24:13 2007
@@ -0,0 +1,51 @@
+/**
+ * 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 Nobody implements Comparable, Principal {
+ public static final String NOBODY = "<NOBODY>";
+
+ public static final Nobody NOBODY_PRINCIPAL = new Nobody();
+
+ public Nobody() {
+ }
+
+ public int hashCode() {
+ return NOBODY.hashCode();
+ }
+
+ public String getName() {
+ return NOBODY;
+ }
+
+ public String toString() {
+ return NOBODY;
+ }
+
+ public boolean equals(Object another) {
+ return false;
+ }
+
+ public int compareTo(Object o) {
+ return 1;
+ }
+}
Propchange: geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/Nobody.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/PasswordHasher.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/PasswordHasher.java?view=auto&rev=546862
==============================================================================
--- geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/PasswordHasher.java (added)
+++ geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/PasswordHasher.java Wed Jun 13 06:24:13 2007
@@ -0,0 +1,103 @@
+/**
+ * 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.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+
+import org.apache.geronimo.util.encoders.Base64Encoder;
+
+public class PasswordHasher {
+
+ private final static String HEX_ENC = "HEX";
+ private final static String ISO_ENC = "ISO-8859-1";
+ private final static String BASE_64_ENC = "BASE64";
+
+ public static String calculateHash(String algorithm, String encoding, String charset, String username, String password, DigestCallback callback) {
+ String passwordHash = null;
+ byte passBytes[];
+ try {
+ if (charset == null) {
+ passBytes = password.getBytes();
+ }
+ else {
+ passBytes = password.getBytes(charset);
+ }
+ } catch (UnsupportedEncodingException uee) {
+ passBytes = password.getBytes();
+ }
+ try {
+ MessageDigest mesDigest = MessageDigest.getInstance(algorithm);
+ if (callback != null) {
+ callback.preDigest(mesDigest);
+ }
+ mesDigest.update(passBytes);
+ if (callback != null) {
+ callback.postDigest(mesDigest);
+ }
+ byte hash[] = mesDigest.digest();
+ if (encoding.equalsIgnoreCase(HEX_ENC)) {
+ passwordHash = base16Encoding(hash);
+ } else if (encoding.equalsIgnoreCase(BASE_64_ENC)) {
+ passwordHash = base64Encoding(hash);
+ }
+ } catch (Exception e) {}
+ return passwordHash;
+ }
+
+ private static String base16Encoding(byte encodedChain[]) {
+ StringBuffer buffer = new StringBuffer(encodedChain.length * 2);
+ for (int i = 0; i < encodedChain.length; i++) {
+ byte nextByte = encodedChain[i];
+ char nextChar = (char) (nextByte >> 4 & 0xf);
+ if (nextChar > '\t') {
+ nextChar = (char) ((nextChar - 10) + 97);
+ }
+ else {
+ nextChar += '0';
+ }
+ buffer.append(nextChar);
+ nextChar = (char) (nextByte & 0xf);
+ if (nextChar > '\t') {
+ nextChar = (char) ((nextChar - 10) + 97);
+ }
+ else {
+ nextChar += '0';
+ }
+ buffer.append(nextChar);
+ }
+ return buffer.toString();
+ }
+
+ private static String base64Encoding(byte bytes[]) {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ Base64Encoder encoder = new Base64Encoder();
+ try {
+ encoder.encode(bytes, 0, bytes.length, out);
+ } catch (IOException e) {}
+ String result = null;
+ try {
+ result = out.toString(ISO_ENC);
+ } catch (UnsupportedEncodingException e) {}
+ return result;
+ }
+}
Propchange: geronimo/sandbox/j2g/src/main/resources/compatibility/org.apache.geronimo.j2g.sources.dependence.compatibility/PasswordHasher.java
------------------------------------------------------------------------------
svn:eol-style = native