[jboss-svn-commits] JBL Code SVN: r35785 - in labs/jbossrules/trunk/drools-guvnor/src: test/java/org/drools/guvnor/server/files and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 28 02:47:28 EDT 2010


Author: jervisliu
Date: 2010-10-28 02:47:27 -0400 (Thu, 28 Oct 2010)
New Revision: 35785

Added:
   labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/files/RepositoryServletTest.java
Modified:
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/files/RepositoryServlet.java
   labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/files/FeedServletTest.java
   labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/files/RestAPIServletTest.java
   labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/security/MockIdentity.java
Log:
GUVNOR-802: Refactor Guvnor authentication to tolerate no Basic Authentication headers when authentication is disabled. 

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/files/RepositoryServlet.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/files/RepositoryServlet.java	2010-10-28 06:03:27 UTC (rev 35784)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/files/RepositoryServlet.java	2010-10-28 06:47:27 UTC (rev 35785)
@@ -112,13 +112,9 @@
      * uses Seam Identity component to set the user up.
      */
     public static boolean allowUser(String auth) {
-        if (auth == null) return false;  // no auth
-        if (!auth.toUpperCase(Locale.ENGLISH).startsWith("BASIC "))
-          return false;  // we only do BASIC
+        String usr = null;
+        String pwd = null;
 
-        String[] a = unpack(auth);
-        String usr = a[0];
-        String pwd = a[1];
         if ( Contexts.isApplicationContextActive() ) {
         	//If the request is from same session, the user should be logged already.
         	if (Identity.instance().isLoggedIn()) {
@@ -126,8 +122,13 @@
         	}
         	
             Identity ids = Identity.instance();
-            ids.getCredentials().setUsername(usr);
-            ids.getCredentials().setPassword(pwd);
+            if(auth != null && auth.toUpperCase(Locale.ENGLISH).startsWith("BASIC ")) {
+                String[] a = unpack(auth);
+                usr = a[0];
+                pwd = a[1];
+                ids.getCredentials().setUsername(usr);
+                ids.getCredentials().setPassword(pwd);
+            }
             try {
                 ids.authenticate();
                 log.info(usr + " authenticated for rest api");
@@ -139,12 +140,15 @@
             }
         } else {
             //MN: NOTE THIS IS MY HACKERY TO GET IT WORKING IN GWT HOSTED MODE.
+            String[] a = unpack(auth);
+            usr = a[0];
+            pwd = a[1];
+      	
             return usr.equals("test") && pwd.equals("password");
         }
 
     }
 
-
     /**
      * For closures. Damn you java when will you catch up with the 70s.
      */
@@ -162,6 +166,4 @@
         a[1] = a[1].trim();
 		return a;
 	}
-
-
 }

Modified: labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/files/FeedServletTest.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/files/FeedServletTest.java	2010-10-28 06:03:27 UTC (rev 35784)
+++ labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/files/FeedServletTest.java	2010-10-28 06:47:27 UTC (rev 35785)
@@ -20,11 +20,14 @@
 import org.drools.repository.RulesRepository;
 import org.drools.repository.PackageItem;
 import org.drools.repository.AssetItem;
+import org.drools.guvnor.server.security.MockIdentity;
 import org.drools.guvnor.server.util.TestEnvironmentSessionHelper;
 import org.drools.guvnor.server.ServiceImplementation;
 import org.apache.util.Base64;
-import org.jboss.seam.security.AuthorizationException;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.contexts.Lifecycle;
 
+
 import javax.servlet.http.HttpServletResponse;
 import java.io.ByteArrayOutputStream;
 import java.util.Map;
@@ -35,13 +38,28 @@
  */
 public class FeedServletTest extends TestCase {
 
-    public void testPackageFeed() throws Exception {
+    public void testPackageFeed() throws Exception {        
         RulesRepository repo = new RulesRepository( TestEnvironmentSessionHelper.getSession( true ) );
         PackageItem pkg = repo.createPackage("testPackageFeed", "");
         AssetItem asset = pkg.addAsset("asset1", "desc");
         asset.updateFormat("drl");
         asset.checkin("");
+        
+       //Mock up SEAM contexts
+        Map application = new HashMap<String, Object>();
+        Lifecycle.beginApplication( application );
+        Lifecycle.beginCall();
+        MockIdentity midentity = new MockIdentity();
+        midentity.setIsLoggedIn(false);
+        midentity.setAllowLogin(false);
+        midentity.setCheckPermission(true);
+        Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
+                                          midentity );        
+        FileManagerUtils manager = new FileManagerUtils();
+        manager.setRepository(repo);
+        Contexts.getSessionContext().set( "fileManager", manager );
 
+ 
         Map<String, String> headers = new HashMap<String, String>() {
             {
                 put("Irrelevant", "garbage");
@@ -55,10 +73,12 @@
         fs.doGet(req, res);
         assertEquals(HttpServletResponse.SC_UNAUTHORIZED, res.errorCode);
 
-        //try again with bad password
+        //try again with valid user and password
+        midentity.setAllowLogin(true);
+
         headers = new HashMap<String, String>() {
             {
-                put("Authorization", "BASIC " + new String(Base64.encode("test:password".getBytes())));
+                put("Authorization", "BASIC " + new String(Base64.encode("testuser:password".getBytes())));
             }
         };
         req = new MockHTTPRequest("/org.foo/feed/package", headers, new HashMap<String, String>() {
@@ -111,7 +131,8 @@
         r = new String(out.toByteArray());
         assertNotNull(r);
         assertTrue(r.indexOf("asset1") > -1);
-
+        
+        Lifecycle.endApplication();
     }
 
     public void testCategoryFeed() throws Exception {
@@ -123,11 +144,26 @@
         asset.updateCategoryList(new String[] {"testCategoryFeedCat"});
         asset.checkin("");
 
+        //Mock up SEAM contexts
+        Map application = new HashMap<String, Object>();
+        Lifecycle.beginApplication( application );
+        Lifecycle.beginCall();
+        MockIdentity midentity = new MockIdentity();
+        midentity.setIsLoggedIn(false);
+        midentity.setAllowLogin(true);
+        midentity.setCheckPermission(true);
+        Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
+                                          midentity );
+        
+        FileManagerUtils manager = new FileManagerUtils();
+        manager.setRepository(repo);
+        Contexts.getSessionContext().set( "fileManager", manager );
 
-        //try again with bad password
+
+        //try with valid password
         HashMap<String, String> headers = new HashMap<String, String>() {
             {
-                put("Authorization", "BASIC " + new String(Base64.encode("test:password".getBytes())));
+                put("Authorization", "BASIC " + new String(Base64.encode("testuser:password".getBytes())));
             }
         };
         MockHTTPRequest req = new MockHTTPRequest("/org.foo/feed/category", headers, new HashMap<String, String>() {
@@ -136,7 +172,7 @@
                 put("viewUrl", "http://foo.bar");
             }
         });
-        MockFeedServlet fs = new MockFeedServlet();
+        FeedServlet fs = new FeedServlet();
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         MockHTTPResponse res = new MockHTTPResponse(out);
         fs.doGet(req, res);
@@ -155,7 +191,7 @@
                 put("status", "*");
             }
         });
-        fs = new MockFeedServlet();
+        fs = new FeedServlet();
         out = new ByteArrayOutputStream();
         res = new MockHTTPResponse(out);
         fs.doGet(req, res);
@@ -166,26 +202,38 @@
         assertTrue(r.indexOf("asset1") > -1);
         assertTrue(r.indexOf("http://foo.bar") > -1);
 
-
-        fs = new MockFeedServlet();
-        fs.throwAuthException = true;
+        
+        midentity.setAllowLogin(false);
+        fs = new FeedServlet();
         out = new ByteArrayOutputStream();
         res = new MockHTTPResponse(out);
         fs.doGet(req, res);
-
         assertEquals(HttpServletResponse.SC_UNAUTHORIZED, res.errorCode);
 
-
+        Lifecycle.endApplication();
     }
 
-
-
     public void testDiscussionFeed() throws Exception {
         RulesRepository repo = new RulesRepository( TestEnvironmentSessionHelper.getSession( true ) );
         PackageItem pkg = repo.createPackage("testDiscussionFeed", "");
         AssetItem asset = pkg.addAsset("asset1", "desc");
         asset.updateFormat("drl");
         asset.checkin("");
+        
+        //Mock up SEAM contexts
+        Map application = new HashMap<String, Object>();
+        Lifecycle.beginApplication( application );
+        Lifecycle.beginCall();
+        MockIdentity midentity = new MockIdentity();
+        midentity.setIsLoggedIn(false);
+        midentity.setAllowLogin(false);
+        midentity.setCheckPermission(true);
+        Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
+                                          midentity );
+        
+        FileManagerUtils manager = new FileManagerUtils();
+        manager.setRepository(repo);
+        Contexts.getSessionContext().set( "fileManager", manager );
 
         ServiceImplementation impl = new ServiceImplementation();
         impl.repository = repo;
@@ -212,6 +260,7 @@
         };
 
 
+        midentity.setAllowLogin(true);
         req = new MockHTTPRequest("/org.foo/feed/discussion", headers, new HashMap<String, String>() {
             {
                 put("package", "testDiscussionFeed");
@@ -229,24 +278,7 @@
         assertTrue(r.indexOf("This is another comment") > r.indexOf("This is a comment"));
         System.err.println(r);
 
-
-
+        Lifecycle.endApplication();
     }
-
-
-    class MockFeedServlet extends FeedServlet {
-        boolean throwAuthException = false;
-        @Override
-        void checkCategoryPermission(String cat) {
-            if (throwAuthException) throw new AuthorizationException("NO");
-            super.checkCategoryPermission(cat);    //To change body of overridden methods use File | Settings | File Templates.
-        }
-
-        @Override
-        void checkPackageReadPermission(String packageName) {
-            if (throwAuthException) throw new AuthorizationException("NO");
-            super.checkPackageReadPermission(packageName);    //To change body of overridden methods use File | Settings | File Templates.
-        }
-    }
     
 }

Added: labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/files/RepositoryServletTest.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/files/RepositoryServletTest.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/files/RepositoryServletTest.java	2010-10-28 06:47:27 UTC (rev 35785)
@@ -0,0 +1,111 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed 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.drools.guvnor.server.files;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.util.Base64;
+import org.drools.guvnor.server.security.MockIdentity;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.contexts.Lifecycle;
+
+import junit.framework.TestCase;
+
+public class RepositoryServletTest extends TestCase {
+
+	public void testAllowUser() throws Exception {
+        //Mock up SEAM contexts
+        Map application = new HashMap<String, Object>();
+        Lifecycle.beginApplication( application );
+        Lifecycle.beginCall();
+        MockIdentity midentity = new MockIdentity();
+        midentity.setIsLoggedIn(false);
+        midentity.setAllowLogin(true);
+        Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
+                                          midentity );
+
+		String authToken = "usr:pwd";
+		String encodedAuthToken = "BASIC " + new String(Base64.encode(authToken.getBytes()));
+		boolean allowed = RepositoryServlet.allowUser(encodedAuthToken);
+		assertTrue(allowed);
+		
+        Lifecycle.endApplication();
+	}
+	
+
+	public void testAllowUserNoBasicAuthticationHeader() throws Exception {
+        //Mock up SEAM contexts
+        Map application = new HashMap<String, Object>();
+        Lifecycle.beginApplication( application );
+        Lifecycle.beginCall();
+        MockIdentity midentity = new MockIdentity();
+        midentity.setIsLoggedIn(false);
+        midentity.setAllowLogin(true);
+        Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
+                                          midentity );
+
+		String encodedAuthToken = null;
+		boolean allowed = RepositoryServlet.allowUser(encodedAuthToken);
+		assertTrue(allowed);
+		
+        Lifecycle.endApplication();
+	}
+	
+	public void testAllowUserNoBasicAuthticationHeaderNotAllowLogin() throws Exception {
+        //Mock up SEAM contexts
+        Map application = new HashMap<String, Object>();
+        Lifecycle.beginApplication( application );
+        Lifecycle.beginCall();
+        MockIdentity midentity = new MockIdentity();
+        midentity.setIsLoggedIn(false);
+        midentity.setAllowLogin(false);
+        Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
+                                          midentity );
+
+		String encodedAuthToken = null;
+		boolean allowed = RepositoryServlet.allowUser(encodedAuthToken);
+		assertFalse(allowed);
+		
+        Lifecycle.endApplication();
+	}
+	
+	public void testAllowUserNotBasicAuthticationHeader() throws Exception {
+        //Mock up SEAM contexts
+        Map application = new HashMap<String, Object>();
+        Lifecycle.beginApplication( application );
+        Lifecycle.beginCall();
+        MockIdentity midentity = new MockIdentity();
+        midentity.setIsLoggedIn(false);
+        midentity.setAllowLogin(true);
+        Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
+                                          midentity );
+
+		String encodedAuthToken = "NON-Basic ";
+		boolean allowed = RepositoryServlet.allowUser(encodedAuthToken);
+		assertTrue(allowed);
+		
+        Lifecycle.endApplication();
+	}
+
+	public void testUnpack() {
+		String b42 = "BASIC " + new String( Base64.encode("user:pass".getBytes()) );
+		String[] d = RepositoryServlet.unpack(b42);
+		assertEquals("user", d[0]);
+		assertEquals("pass", d[1]);
+	}
+}

Modified: labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/files/RestAPIServletTest.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/files/RestAPIServletTest.java	2010-10-28 06:03:27 UTC (rev 35784)
+++ labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/files/RestAPIServletTest.java	2010-10-28 06:47:27 UTC (rev 35785)
@@ -22,43 +22,22 @@
 import java.util.Map;
 
 import javax.servlet.http.HttpServletResponse;
-import javax.jcr.Session;
 
 import junit.framework.TestCase;
 
 import org.apache.util.Base64;
+import org.drools.guvnor.server.security.MockIdentity;
 import org.drools.guvnor.server.util.TestEnvironmentSessionHelper;
 import org.drools.repository.AssetItem;
 import org.drools.repository.AssetItemIterator;
 import org.drools.repository.PackageItem;
 import org.drools.repository.RulesRepository;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.contexts.Lifecycle;
 
 public class RestAPIServletTest extends TestCase {
 
-
-	public void testUnpack() {
-		String b42 = "BASIC " + new String( Base64.encode("user:pass".getBytes()) );
-		RestAPIServlet serv = new RestAPIServlet();
-		String[] d = serv.unpack(b42);
-		assertEquals("user", d[0]);
-		assertEquals("pass", d[1]);
-
-	}
-
-	public void testAllowUser() {
-		RestAPIServlet serv = new RestAPIServlet();
-		assertFalse(serv.allowUser(null));
-		assertFalse(serv.allowUser(""));
-		assertFalse(serv.allowUser("bgoo"));
-		String b42 = "BASIC " + new String( Base64.encode("user:pass".getBytes()) );
-		assertFalse(serv.allowUser(b42));
-		b42 = "BASIC " + new String( Base64.encode("test:password".getBytes()) );
-		assertTrue(serv.allowUser(b42));
-	}
-
-
-
-	public void testGet() throws Exception {
+	public void testGet() throws Exception {        
 		RulesRepository repo = new RulesRepository( TestEnvironmentSessionHelper.getSession( true ) );
 		PackageItem pkg = repo.createPackage("testGetRestServlet", "");
 		AssetItem ass = pkg.addAsset("asset1", "");
@@ -66,8 +45,21 @@
 		ass.updateContent("some content");
 		ass.checkin("hey ho");
 
-
-
+        //Mock up SEAM contexts
+        Map application = new HashMap<String, Object>();
+        Lifecycle.beginApplication( application );
+        Lifecycle.beginCall();
+        MockIdentity midentity = new MockIdentity();
+        midentity.setIsLoggedIn(false);
+        midentity.setAllowLogin(false);
+        Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
+                                          midentity );        
+        FileManagerUtils manager = new FileManagerUtils();
+        manager.setRepository(repo);
+        Contexts.getSessionContext().set( "fileManager", manager );
+        Contexts.getSessionContext().set( "repository", repo );
+        
+        
 		RestAPIServlet serv = new RestAPIServlet();
 		assertNotNull(serv.getAPI());
 		Map<String, String> headers = new HashMap<String, String>() {
@@ -99,9 +91,11 @@
 		assertTrue(res.headers.containsKey("WWW-Authenticate"));
 
 		//finally, making it work
+        midentity.setAllowLogin(true);
+
 		headers = new HashMap<String, String>() {
 			{
-				put("Authorization", "BASIC " + new String(Base64.encode("test:password".getBytes())));
+				put("Authorization", "BASIC " + new String(Base64.encode("testuser:password".getBytes())));
 			}
 		};
 
@@ -129,17 +123,33 @@
 		assertFalse("some content".equals(data));
 		assertNotNull(data);
 
+        Lifecycle.endApplication();
 	}
 
 	public void testPost() throws Exception {
 		RulesRepository repo = new RulesRepository( TestEnvironmentSessionHelper.getSession() );
 		PackageItem pkg = repo.createPackage("testPostRestServlet", "");
 
+        //Mock up SEAM contexts
+        Map application = new HashMap<String, Object>();
+        Lifecycle.beginApplication( application );
+        Lifecycle.beginCall();
+        MockIdentity midentity = new MockIdentity();
+        midentity.setIsLoggedIn(false);
+        midentity.setAllowLogin(true);
+        Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
+                                          midentity );        
+        FileManagerUtils manager = new FileManagerUtils();
+        manager.setRepository(repo);
+        Contexts.getSessionContext().set( "fileManager", manager );
+        Contexts.getSessionContext().set( "repository", repo );
+        
+        
 		HashMap<String, String> headers = new HashMap<String, String>() {
 			{
 				put("Authorization", "BASIC " + new String(Base64.encode("test:password".getBytes())));
 			}
-		};
+		};		
 
 		ByteArrayInputStream in = new ByteArrayInputStream("some new content".getBytes());
 		RestAPIServlet serv = new RestAPIServlet();
@@ -174,17 +184,33 @@
 
         repo.logout();
 
+        Lifecycle.endApplication();
 	}
 
 	public void testPut() throws Exception {
-
 		RulesRepository repo = new RulesRepository( TestEnvironmentSessionHelper.getSession() );
 		PackageItem pkg = repo.createPackage("testPutRestServlet", "");
 		AssetItem ass = pkg.addAsset("asset1", "abc");
 		ass.updateFormat("drl");
 		ass.checkin("");
 		long ver = ass.getVersionNumber();
+		
+		
+        //Mock up SEAM contexts
+        Map application = new HashMap<String, Object>();
+        Lifecycle.beginApplication( application );
+        Lifecycle.beginCall();
+        MockIdentity midentity = new MockIdentity();
+        midentity.setIsLoggedIn(false);
+        midentity.setAllowLogin(true);
+        Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
+                                          midentity );        
+        FileManagerUtils manager = new FileManagerUtils();
+        manager.setRepository(repo);
+        Contexts.getSessionContext().set( "fileManager", manager );
+        Contexts.getSessionContext().set( "repository", repo );
 
+        
 		HashMap<String, String> headers = new HashMap<String, String>() {
 			{
 				put("Authorization", "BASIC " + new String(Base64.encode("test:password".getBytes())));
@@ -208,6 +234,8 @@
 		assertEquals("hey ho", ass.getCheckinComment());
 
         repo.logout();
+
+        Lifecycle.endApplication();        
 	}
 
 
@@ -217,7 +245,22 @@
 		AssetItem ass = pkg.addAsset("asset1", "abc");
 		ass.updateFormat("drl");
 		ass.checkin("");
-
+		
+        //Mock up SEAM contexts
+        Map application = new HashMap<String, Object>();
+        Lifecycle.beginApplication( application );
+        Lifecycle.beginCall();
+        MockIdentity midentity = new MockIdentity();
+        midentity.setIsLoggedIn(false);
+        midentity.setAllowLogin(true);
+        Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
+                                          midentity );        
+        FileManagerUtils manager = new FileManagerUtils();
+        manager.setRepository(repo);
+        Contexts.getSessionContext().set( "fileManager", manager );
+        Contexts.getSessionContext().set( "repository", repo );
+        
+        
 		HashMap<String, String> headers = new HashMap<String, String>() {
 			{
 				put("Authorization", "BASIC " + new String(Base64.encode("test:password".getBytes())));
@@ -240,5 +283,6 @@
 
         repo.logout();
 
+        Lifecycle.endApplication();
 	}
 }

Modified: labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/security/MockIdentity.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/security/MockIdentity.java	2010-10-28 06:03:27 UTC (rev 35784)
+++ labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/security/MockIdentity.java	2010-10-28 06:47:27 UTC (rev 35785)
@@ -38,6 +38,8 @@
 import java.util.List;
 import java.util.Set;
 
+import javax.security.auth.login.LoginException;
+
 import org.jboss.seam.contexts.Contexts;
 import org.jboss.seam.security.Credentials;
 import org.jboss.seam.security.Identity;
@@ -47,7 +49,10 @@
 	private boolean hasRole;
 	private Set<String> roles = new HashSet<String>();
 	private List<PermissionResolver> resolvers = new ArrayList<PermissionResolver>();
-    boolean loggoutCalled = false;
+	private boolean isLoggedIn = true;
+    boolean loggoutCalled = true;
+    boolean allowLogin = true;
+    boolean checkPermission = false;
 
     @Override
 	public boolean addRole(String r) {
@@ -66,8 +71,12 @@
 	}
 
 	public boolean isLoggedIn() {
-		return true;
+		return isLoggedIn;
 	}
+	
+	public void setIsLoggedIn(boolean isLoggedIn) {
+		this.isLoggedIn = isLoggedIn;
+	}
 
 	public boolean isLoggedIn(boolean attemptLogin) {
 		return true;
@@ -110,4 +119,28 @@
 			   }
 		};
 	}   
+	
+	public void authenticate() throws LoginException {
+		if(allowLogin) {
+			return;
+		}
+		
+		throw new LoginException();
+	}
+	
+	public void setAllowLogin (boolean allowLogin) {
+		this.allowLogin = allowLogin;
+	}
+	
+	public void setCheckPermission (boolean checkPermission) {
+		this.checkPermission = checkPermission;
+	}
+	
+	public void checkPermission(Object target, String action ) {
+		if(checkPermission) {
+		System.out.println("MockIdentity.checkPermission");
+		} else {
+			super.checkPermission(target, action);
+		}
+	}
 }
\ No newline at end of file



More information about the jboss-svn-commits mailing list