harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r570655 - in /harmony/enhanced/classlib/trunk/modules/auth/src: main/java/common/org/apache/harmony/auth/module/LoginModuleUtils.java test/java/common/org/apache/harmony/auth/tests/module/LoginModuleUtilsTest.java
Date Wed, 29 Aug 2007 06:26:26 GMT
Author: leoli
Date: Tue Aug 28 23:26:25 2007
New Revision: 570655

URL: http://svn.apache.org/viewvc?rev=570655&view=rev
Log:
[classlib][auth]Add LoginModule status control facilities in org.apache.harmony.auth.module.LoginModuleUtils.

Modified:
    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/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=570655&r1=570654&r2=570655&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
Tue Aug 28 23:26:25 2007
@@ -21,8 +21,80 @@
 import java.io.InputStream;
 import java.util.Arrays;
 
+import javax.security.auth.login.LoginException;
+
 public class LoginModuleUtils {
+    
+    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(){
+            phase = PHASE.uninitialized;
+        }
+        
+        public void initialized(){
+            phase = PHASE.initialized;
+        }
+        
+        public void logined(){
+            phase = PHASE.logined;
+        }
+        
+        public void committed(){
+            phase = PHASE.committed;
+        }
+        
+        public void logouted(){
+            phase = PHASE.logined;
+        }
+
+        public ACTION checkLogin() throws LoginException {
+            switch (phase) {
+            case uninitialized:
+                throw new LoginException("Login Module is not initialized.");
+            case initialized:
+                return ACTION.login;
+            default:
+                return ACTION.no_action;
+            }
+        }
+
+        public ACTION checkCommit() throws LoginException {
+            switch (phase) {
+            case uninitialized:
+                throw new LoginException("Login Module is not initialized.");
+            case initialized:
+                return ACTION.logout;
+            case logined:
+                return ACTION.commit;
+            default:
+                return ACTION.no_action;
+            }
+        }
 
+        public ACTION checkLogout() throws LoginException {
+            switch (phase) {
+            case uninitialized:
+                throw new LoginException("Login Module is not initialized.");
+            case initialized:
+            case logined:
+                return ACTION.no_action;
+            default:
+                return ACTION.logout;
+            }
+        }
+    }
+    
+    
     /**
      * Reads the password stored in an inputstream to a char array.
      * 

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=570655&r1=570654&r2=570655&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
Tue Aug 28 23:26:25 2007
@@ -21,6 +21,8 @@
 import java.io.InputStream;
 import java.util.Arrays;
 
+import javax.security.auth.login.LoginException;
+
 import org.apache.harmony.auth.module.LoginModuleUtils;
 
 import junit.framework.TestCase;
@@ -72,6 +74,64 @@
         LoginModuleUtils.clearPassword(password);
         password = new char[0];
         LoginModuleUtils.clearPassword(password);
+    }
+    
+    public void testLoginModuleStatus() throws Exception {
+        LoginModuleUtils.LoginModuleStatus status = new LoginModuleUtils.LoginModuleStatus();
+        try {
+            status.checkLogin();
+        } catch (LoginException e) {
+            // expected
+        }
+
+        try {
+            status.checkCommit();
+        } catch (LoginException e) {
+            // expected
+        }
+
+        try {
+            status.checkLogout();
+        } catch (LoginException e) {
+            // expected
+        }
+
+        status.initialized();
+        assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.login, status
+                .checkLogin());
+
+        try {
+            status.checkCommit();
+        } catch (LoginException e) {
+            // expected
+        }
+
+        assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+                status.checkLogout());
+
+        status.logined();
+        assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+                status.checkLogin());
+        assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.commit, status
+                .checkCommit());
+        assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+                status.checkLogout());
+
+        status.committed();
+        assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+                status.checkLogin());
+        assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+                status.checkCommit());
+        assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.logout, status
+                .checkLogout());
+
+        status.logined();
+        assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+                status.checkLogin());
+        assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.commit, status
+                .checkCommit());
+        assertEquals(LoginModuleUtils.LoginModuleStatus.ACTION.no_action,
+                status.checkLogout());
     }
 
 }



Mime
View raw message