Author: leoli
Date: Mon Sep 10 23:23:55 2007
New Revision: 574481
URL: http://svn.apache.org/viewvc?rev=574481&view=rev
Log:
Apply patch for HARMONY-4718([classlib][auth]Harmony classlib lacks support for KeyStoreLoginModule.)
Added:
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/KeyStoreLoginModule.java
(with props)
harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/module/KeyStoreLoginModuleTest.java
(with props)
harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/fault_pass
harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/hyts_ks.bks (with props)
harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/hyts_ks_pass
Modified:
harmony/enhanced/classlib/trunk/modules/auth/.classpath
harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/LoginModuleUtils.java
harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/module/LoginModuleUtilsTest.java
Modified: harmony/enhanced/classlib/trunk/modules/auth/.classpath
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/.classpath?rev=574481&r1=574480&r2=574481&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/.classpath (original)
+++ harmony/enhanced/classlib/trunk/modules/auth/.classpath Mon Sep 10 23:23:55 2007
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry output="bin/main" kind="src" path="src/main/java/windows"/>
- <classpathentry output="bin/main" kind="src" path="src/main/java/common"/>
- <classpathentry output="bin/main" kind="src" path="src/main/java/unix"/>
- <classpathentry output="bin/test" kind="src" path="src/test/java/common"/>
- <classpathentry output="bin/test" kind="src" path="src/test/java/windows"/>
- <classpathentry output="bin/test" kind="src" path="src/test/java/unix"/>
+ <classpathentry kind="src" output="bin/main" path="src/main/java/windows"/>
+ <classpathentry kind="src" output="bin/test" path="src/test/resources"/>
+ <classpathentry kind="src" output="bin/main" path="src/main/java/common"/>
+ <classpathentry kind="src" output="bin/main" path="src/main/java/unix"/>
+ <classpathentry kind="src" output="bin/test" path="src/test/java/common"/>
+ <classpathentry kind="src" output="bin/test" path="src/test/java/windows"/>
+ <classpathentry kind="src" output="bin/test" path="src/test/java/unix"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry sourcepath="JUNIT_SRC_HOME/junitsrc.zip" kind="var" path="JUNIT_HOME/junit.jar"/>
<classpathentry kind="output" path="bin/main"/>
Added: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/KeyStoreLoginModule.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/KeyStoreLoginModule.java?rev=574481&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/KeyStoreLoginModule.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/KeyStoreLoginModule.java
Mon Sep 10 23:23:55 2007
@@ -0,0 +1,354 @@
+/*
+ * 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.harmony.auth.module;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.security.AuthProvider;
+import java.security.Key;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.Provider;
+import java.security.Security;
+import java.security.cert.CertPath;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+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.login.FailedLoginException;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+import javax.security.auth.x500.X500Principal;
+import javax.security.auth.x500.X500PrivateCredential;
+
+public class KeyStoreLoginModule implements LoginModule {
+
+ private static final String DEFAULT_KEYSTORE_TYPE = KeyStore.getDefaultType();
+
+ private LoginModuleUtils.LoginModuleStatus status = new LoginModuleUtils.LoginModuleStatus();
+
+ private Subject subject;
+
+ private CallbackHandler callbackHandler;
+
+ //private Map<String,?> sharedState;
+
+ private Map<String,?> options;
+
+ private String keyStoreURL;
+
+ private String keyStoreType;
+
+ private Provider keyStoreProvider;
+
+ private String keyStoreAlias;
+
+ private CertPath certPath;
+
+ private X500Principal principal;
+
+ private X500PrivateCredential privateCredential;
+
+ private char[] keyStorePassword;
+
+ private char[] privateKeyPassword;
+
+ private boolean needKeyStorePassword = true;
+
+ private boolean needPrivateKeyPassword = true;
+
+ public boolean abort() throws LoginException {
+ LoginModuleUtils.ACTION action = status.checkAbout();
+ if (action.equals(LoginModuleUtils.ACTION.no_action)) {
+ if (status.isLoggined()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ clear();
+ return true;
+ }
+
+ public boolean commit() throws LoginException {
+ LoginModuleUtils.ACTION action = status.checkCommit();
+ switch (action) {
+ case no_action:
+ return true;
+ case logout:
+ clear();
+ throw new LoginException("Fail to login");
+ default:
+ if (subject.isReadOnly()) {
+ clear();
+ throw new LoginException("Subject is readonly.");
+ }
+ subject.getPrincipals().add(principal);
+ subject.getPublicCredentials().add(certPath);
+ subject.getPrivateCredentials().add(privateCredential);
+ status.committed();
+ return true;
+ }
+ }
+
+ public void initialize(Subject subject, CallbackHandler callbackHandler,
+ Map<String, ?> sharedState, Map<String, ?> options) {
+ if (null == options) {
+ throw new NullPointerException();
+ }
+ this.subject = subject;
+ this.callbackHandler = callbackHandler;
+ // this.sharedState = sharedState;
+ this.options = options;
+
+ //clear state
+ this.keyStoreAlias = null;
+ this.keyStorePassword = null;
+ this.privateKeyPassword = null;
+ status.initialized();
+ }
+
+ public boolean login() throws LoginException {
+ LoginModuleUtils.ACTION action = status.checkLogin();
+ if (action.equals(LoginModuleUtils.ACTION.no_action)) {
+ return true;
+ }
+ getKeyStoreParameters();
+ getPrincipalsFromKeyStore();
+ status.logined();
+ return true;
+ }
+
+ public boolean logout() throws LoginException {
+ LoginModuleUtils.ACTION action = status.checkLogout();
+ if (action.equals(LoginModuleUtils.ACTION.no_action)) {
+ return true;
+ }
+ clear();
+ return true;
+ }
+
+
+ private void getKeyStoreParameters() throws LoginException {
+ // Get parameters from options.
+ keyStoreURL = (String) options.get("keyStoreURL");
+ keyStoreType = (String) options.get("keyStoreType");
+ if (null == keyStoreType) {
+ keyStoreType = DEFAULT_KEYSTORE_TYPE;
+ }
+ String keyStoreProvider = (String)options.get("keyStoreProvider");
+ if(keyStoreProvider != null){
+ this.keyStoreProvider = Security.getProvider(keyStoreProvider);
+ }
+ keyStoreAlias = (String) options.get("keyStoreAlias");
+ String keyStorePasswordURL = (String) options.get("keyStorePasswordURL");
+ String privateKeyPasswordURL = (String) options.get("privateKeyPasswordURL");
+ boolean has_protected_authentication_path = "true"
+ .equalsIgnoreCase((String) options.get("protected"));
+
+ if (keyStoreType != null && keyStoreType.equals("PKCS11")) {
+ if (!keyStoreURL.equals("NONE")
+ || privateKeyPasswordURL != null) {
+ throw new LoginException(
+ "PKCS11 must have NONE as keyStoreURL and privateKeyPasswordURL unset");
+ }
+ needPrivateKeyPassword = false;
+ }
+
+ if (has_protected_authentication_path) {
+ if (keyStorePasswordURL != null && privateKeyPasswordURL != null) {
+ throw new LoginException(
+ "Protected authentication path must have keyStorePasswordURL and
privateKeyPasswordURL unset");
+ }
+ needKeyStorePassword = false;
+ needPrivateKeyPassword = false;
+ }
+
+ if (this.callbackHandler != null) {
+ this.getParametersWithCallbackHandler();
+ } else {
+ this.getParametersWithoutCallbackHandler(keyStorePasswordURL,
+ privateKeyPasswordURL);
+ }
+
+ // privateKeyPassword is empty, use keystorepassword instead.
+ if (needPrivateKeyPassword
+ && (privateKeyPassword == null || privateKeyPassword.length == 0))
{
+ privateKeyPassword = keyStorePassword;
+ }
+ }
+
+
+ private void getParametersWithCallbackHandler() throws LoginException {
+ ArrayList<Callback> callbacks = new ArrayList<Callback>();
+ NameCallback keyStoreAliasNameCallback = new NameCallback(
+ "KeyStore Alias");
+ callbacks.add(keyStoreAliasNameCallback);
+ PasswordCallback keyStorePasswordCallback = null;
+ if (needKeyStorePassword) {
+ keyStorePasswordCallback = new PasswordCallback(
+ "KeyStore password", false);
+ callbacks.add(keyStorePasswordCallback);
+ }
+ PasswordCallback privateKeyPasswordCallback = null;
+ if (needPrivateKeyPassword) {
+ privateKeyPasswordCallback = new PasswordCallback(
+ "PrivateKey password", false);
+ callbacks.add(privateKeyPasswordCallback);
+ }
+
+ try {
+ callbackHandler.handle(callbacks.toArray(new Callback[callbacks
+ .size()]));
+ } catch (Exception e) {
+ throw new LoginException(e.toString());
+ }
+ keyStoreAlias = keyStoreAliasNameCallback.getName();
+ if (needKeyStorePassword) {
+ keyStorePassword = keyStorePasswordCallback.getPassword();
+ }
+ if (needPrivateKeyPassword) {
+ privateKeyPassword = privateKeyPasswordCallback.getPassword();
+ }
+ }
+
+ private void getParametersWithoutCallbackHandler(
+ String keyStorePasswordURL, String privateKeyPasswordURL)
+ throws LoginException {
+ InputStream keyStorePasswordInputStream = null;
+ InputStream privateKeyPasswordInputStream = null;
+ try {
+ if (keyStorePasswordURL != null) {
+ keyStorePasswordInputStream = new URL(keyStorePasswordURL)
+ .openStream();
+ this.keyStorePassword = LoginModuleUtils
+ .getPassword(keyStorePasswordInputStream);
+ }
+
+ if (privateKeyPasswordURL != null) {
+ privateKeyPasswordInputStream = new URL(privateKeyPasswordURL)
+ .openStream();
+ privateKeyPassword = LoginModuleUtils
+ .getPassword(privateKeyPasswordInputStream);
+ }
+ } catch (Exception e) {
+
+ } finally {
+ if (keyStorePasswordInputStream != null) {
+ try {
+ keyStorePasswordInputStream.close();
+ } catch (IOException e1) {
+ }
+ }
+ if (privateKeyPasswordInputStream != null) {
+ try {
+ privateKeyPasswordInputStream.close();
+ } catch (IOException e1) {
+ }
+ }
+ }
+
+ if (null == keyStoreURL || (needKeyStorePassword && null == keyStorePassword))
{
+ throw new LoginException(
+ "Failure to get KeyStore or KeyStore Password");
+ }
+ }
+
+ private void getPrincipalsFromKeyStore() throws LoginException {
+
+ InputStream keyStoreInputStream;
+ try {
+
+ KeyStore keyStore = keyStoreProvider == null ? KeyStore
+ .getInstance(keyStoreType) : KeyStore.getInstance(
+ keyStoreType, keyStoreProvider);
+ keyStoreInputStream = keyStoreURL.equals("NONE") ? null : new URL(
+ keyStoreURL).openStream();
+
+ keyStore.load(keyStoreInputStream, keyStorePassword);
+ Certificate[] certificates = keyStore
+ .getCertificateChain(keyStoreAlias);
+ if (null == certificates || certificates.length == 0) {
+ throw new FailedLoginException(
+ "Cannot find certificate path for " + keyStoreAlias);
+ }
+ List<Certificate> list = new ArrayList<Certificate>(
+ certificates.length);
+ for (int i = 0; i < certificates.length; i++) {
+ list.add(certificates[i]);
+ }
+ CertificateFactory certificateFactory = CertificateFactory
+ .getInstance("X.509");
+ certPath = certificateFactory.generateCertPath(list);
+
+ X509Certificate firstCertificate = (X509Certificate) certificates[0];
+ principal = new X500Principal(firstCertificate.getSubjectDN()
+ .getName());
+
+ Key privateKey = keyStore.getKey(keyStoreAlias, privateKeyPassword);
+ if (null == privateKey || !(privateKey instanceof PrivateKey)) {
+ throw new FailedLoginException("Cannot find private key for "
+ + keyStoreAlias);
+ }
+ privateCredential = new X500PrivateCredential(firstCertificate,
+ (PrivateKey) privateKey, keyStoreAlias);
+
+ } catch (Exception e) {
+ if (e instanceof LoginException) {
+ throw (LoginException) e;
+ }
+ throw new LoginException(e.toString());
+ }
+ }
+
+ private void clear() throws LoginException {
+ LoginModuleUtils.clearPassword(keyStorePassword);
+ keyStorePassword = null;
+ LoginModuleUtils.clearPassword(privateKeyPassword);
+ privateKeyPassword = null;
+
+ if (keyStoreProvider instanceof AuthProvider) {
+ ((AuthProvider) (keyStoreProvider)).logout();
+ }
+
+ if (principal != null) {
+ subject.getPrincipals().remove(principal);
+ principal = null;
+ }
+ if (certPath != null) {
+ subject.getPublicCredentials().remove(certPath);
+ certPath = null;
+ }
+ if (privateCredential != null) {
+ subject.getPrivateCredentials().remove(privateCredential);
+ privateCredential.destroy();
+ privateCredential = null;
+ }
+ status.logouted();
+ }
+
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/KeyStoreLoginModule.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/LoginModuleUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/LoginModuleUtils.java?rev=574481&r1=574480&r2=574481&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/LoginModuleUtils.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/LoginModuleUtils.java
Mon Sep 10 23:23:55 2007
@@ -25,16 +25,16 @@
public class LoginModuleUtils {
+ public static enum ACTION {
+ no_action, login, commit, logout
+ };
+
public final static class LoginModuleStatus {
private static enum PHASE {
uninitialized, initialized, logined, committed
};
- public static enum ACTION {
- no_action, login, commit, logout
- };
-
private PHASE phase;
public LoginModuleStatus(){
@@ -56,7 +56,26 @@
public void logouted(){
phase = PHASE.logined;
}
+
+ public boolean isLoggined(){
+ return phase.equals(PHASE.logined) || phase.equals(PHASE.committed);
+ }
+
+ public boolean isCommitted(){
+ return phase.equals(PHASE.committed);
+ }
+
+ public ACTION checkAbout() {
+ switch (phase) {
+ case uninitialized:
+ case initialized:
+ return ACTION.no_action;
+ default:
+ return ACTION.logout;
+ }
+ }
+
public ACTION checkLogin() throws LoginException {
switch (phase) {
case uninitialized:
Added: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/module/KeyStoreLoginModuleTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/module/KeyStoreLoginModuleTest.java?rev=574481&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/module/KeyStoreLoginModuleTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/module/KeyStoreLoginModuleTest.java
Mon Sep 10 23:23:55 2007
@@ -0,0 +1,196 @@
+/*
+ * 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.harmony.auth.tests.module;
+
+import java.security.Principal;
+import java.util.HashMap;
+import java.util.Set;
+
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginException;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.auth.module.KeyStoreLoginModule;
+
+import tests.support.resource.Support_Resources;
+
+public class KeyStoreLoginModuleTest extends TestCase {
+
+ // module options
+ private HashMap<String, String> options = new HashMap<String, String>();
+
+ private final String KEYSTORE_URL = "file:"
+ + Support_Resources.getAbsoluteResourcePath("hyts_ks.bks");
+
+ private final String KEYSTORE_PASSWORD_URL = "file:"
+ + Support_Resources.getAbsoluteResourcePath("hyts_ks_pass");
+
+ private final String KEYSTORE_FAULTPASSWORD_URL = "file:"
+ + Support_Resources.getAbsoluteResourcePath("fault_pass");
+
+ private final String KEYSTORE_ALIAS = "mykey";
+
+ public void test_abort() throws LoginException {
+ KeyStoreLoginModule ksm = new KeyStoreLoginModule();
+ try {
+ assertFalse("Should return false if login failed or no login", ksm
+ .abort());
+ } catch (LoginException e) {
+ fail("Abort failed");
+ }
+ Subject subject = new Subject();
+ subject.setReadOnly();
+ ksm.initialize(subject, null, null, options);
+ try {
+ assertFalse("Should return false if login failed or no login", ksm
+ .abort());
+ } catch (Exception e) {
+ fail("Not any exception here");
+ }
+ options.remove("keyStorePasswordURL");
+ options.put("keyStorePasswordURL", KEYSTORE_FAULTPASSWORD_URL);
+ subject = new Subject();
+ ksm.initialize(subject, null, null, options);
+ try {
+ ksm.login();
+ fail("login should fail");
+ } catch (LoginException e) {
+ assertFalse("Should return false because of login failure", ksm
+ .abort());
+ }
+ options.remove("keyStorePasswordURL");
+ options.put("keyStorePasswordURL", KEYSTORE_PASSWORD_URL);
+ subject = new Subject();
+ ksm.initialize(subject, null, null, options);
+ ksm.login();
+ assertTrue("Should return true if login was successful", ksm
+ .abort());
+ }
+
+ public void test_commit() {
+ KeyStoreLoginModule module = new KeyStoreLoginModule();
+ Subject subject = new Subject();
+ module.initialize(subject, null, null, options);
+ try {
+ assertTrue("Login should be successful", module.login());
+ module.commit();
+ } catch (LoginException e) {
+ e.printStackTrace();
+ fail("Login shouldn't fail");
+ }
+ Set<Principal> principals = subject.getPrincipals();
+ assertFalse("Should get at least one principal", principals.isEmpty());
+ Set subjects = subject.getPrivateCredentials();
+ assertFalse("Should get at least one private credential", subjects
+ .isEmpty());
+ Set subjects2 = subject.getPublicCredentials();
+ assertFalse("Should get at least one public credential", subjects2
+ .isEmpty());
+ subject = new Subject();
+ subject.setReadOnly();
+ module.initialize(subject, null, null, options);
+ try {
+ assertFalse("Commit shouldn't be successful", module.commit());
+ fail("Should throw LoginException here because of trying to clear read-only subject");
+ } catch (LoginException e) {
+ // expected LoginException here
+ }
+
+ }
+
+ public void test_initialize() {
+ KeyStoreLoginModule module = new KeyStoreLoginModule();
+ try {
+ module.initialize(null, null, null, null);
+ fail("Should throw NullPointerException here.");
+ } catch (NullPointerException e) {
+ // expected NullPointerException
+ }
+ }
+
+ public void test_login() {
+ KeyStoreLoginModule module = new KeyStoreLoginModule();
+ HashMap<String, String> emptyOptions = new HashMap<String, String>();
+ module.initialize(null, null, null, emptyOptions);
+ try {
+ module.login();
+ fail("Should throw LoginException here.");
+ } catch (LoginException e) {
+ // expected LoginException
+ }
+
+ Subject subject = new Subject();
+ module.initialize(subject, null, null, options);
+ try {
+ assertTrue("Login should be successful", module.login());
+ } catch (LoginException e) {
+ fail("Login shouldn't fail");
+ }
+ options.put("keyStorePasswordURL", KEYSTORE_FAULTPASSWORD_URL);
+ module.initialize(subject, null, null, options);
+ try {
+ assertFalse("Login shouldn't be successful", module.login());
+ fail("Login should fail");
+ } catch (LoginException e) {
+ // expected Loginexception here
+ }
+ }
+
+ public void test_logout() {
+ KeyStoreLoginModule module = new KeyStoreLoginModule();
+ Subject subject = new Subject();
+ module.initialize(subject, null, null, options);
+ try {
+ assertTrue("Login should be successful", module.login());
+ module.commit();
+ } catch (LoginException e) {
+ fail("Login shouldn't fail");
+ }
+ Set<Principal> principals = subject.getPrincipals();
+ assertFalse("Should get at least one principal", principals.isEmpty());
+ Set subjects = subject.getPrivateCredentials();
+ assertFalse("Should get at least one private credential", subjects
+ .isEmpty());
+ Set subjects2 = subject.getPublicCredentials();
+ assertFalse("Should get at least one public credential", subjects2
+ .isEmpty());
+ try {
+ assertTrue("Should be true", module.logout());
+ } catch (LoginException e) {
+ fail("Logout failed");
+ }
+ principals = subject.getPrincipals();
+ assertTrue("Principals should be cleared", principals.isEmpty());
+ subjects = subject.getPrivateCredentials();
+ assertTrue("Private credential should be cleared", subjects.isEmpty());
+ subjects2 = subject.getPublicCredentials();
+ assertTrue("Public credential should be cleared", subjects2.isEmpty());
+ }
+
+ protected void setUp() throws Exception {
+ options.put("keyStoreURL", KEYSTORE_URL);
+ options.put("keyStorePasswordURL", KEYSTORE_PASSWORD_URL);
+ options.put("keyStoreAlias", KEYSTORE_ALIAS);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ options.clear();
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/module/KeyStoreLoginModuleTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/module/LoginModuleUtilsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/module/LoginModuleUtilsTest.java?rev=574481&r1=574480&r2=574481&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/module/LoginModuleUtilsTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/module/LoginModuleUtilsTest.java
Mon Sep 10 23:23:55 2007
@@ -97,7 +97,7 @@
}
status.initialized();
- assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.login, status
+ assertEquals(LoginModuleUtils.ACTION.login, status
.checkLogin());
try {
@@ -106,31 +106,31 @@
// expected
}
- assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+ assertEquals(LoginModuleUtils.ACTION.no_action,
status.checkLogout());
status.logined();
- assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+ assertEquals(LoginModuleUtils.ACTION.no_action,
status.checkLogin());
- assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.commit, status
+ assertEquals(LoginModuleUtils.ACTION.commit, status
.checkCommit());
- assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+ assertEquals(LoginModuleUtils.ACTION.no_action,
status.checkLogout());
status.committed();
- assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+ assertEquals(LoginModuleUtils.ACTION.no_action,
status.checkLogin());
- assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+ assertEquals(LoginModuleUtils.ACTION.no_action,
status.checkCommit());
- assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.logout, status
+ assertEquals(LoginModuleUtils.ACTION.logout, status
.checkLogout());
status.logined();
- assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+ assertEquals(LoginModuleUtils.ACTION.no_action,
status.checkLogin());
- assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.commit, status
+ assertEquals(LoginModuleUtils.ACTION.commit, status
.checkCommit());
- assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+ assertEquals(LoginModuleUtils.ACTION.no_action,
status.checkLogout());
}
Added: harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/fault_pass
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/fault_pass?rev=574481&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/fault_pass (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/fault_pass Mon Sep 10
23:23:55 2007
@@ -0,0 +1 @@
+fault_pass
Added: harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/hyts_ks.bks
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/hyts_ks.bks?rev=574481&view=auto
==============================================================================
Binary file - no diff available.
Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/hyts_ks.bks
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/hyts_ks_pass
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/hyts_ks_pass?rev=574481&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/hyts_ks_pass (added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/hyts_ks_pass Mon Sep 10
23:23:55 2007
@@ -0,0 +1 @@
+abcdef
|