[jboss-cvs] JBossAS SVN: r63026 - projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun May 13 12:42:32 EDT 2007
Author: anil.saldhana at jboss.com
Date: 2007-05-13 12:42:32 -0400 (Sun, 13 May 2007)
New Revision: 63026
Added:
projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/TestSecurityCache.java
Modified:
projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/JBossAuthenticationManagerUnitTestCase.java
Log:
test security cache for auth
Modified: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/JBossAuthenticationManagerUnitTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/JBossAuthenticationManagerUnitTestCase.java 2007-05-13 16:41:55 UTC (rev 63025)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/JBossAuthenticationManagerUnitTestCase.java 2007-05-13 16:42:32 UTC (rev 63026)
@@ -70,6 +70,59 @@
am.getActiveSubject().getPrincipals().contains(p));
}
+ public void testUnsuccessfulLogin() throws Exception
+ {
+ Principal p = new SimplePrincipal("jduke");
+ AppCallbackHandler acbh = new AppCallbackHandler("jduke","bad".toCharArray());
+ AuthenticationManager am = new JBossAuthenticationManager("test",acbh);
+ assertFalse(am.isValid(p, "bad"));
+ }
+
+ public void testSecurityCache() throws Exception
+ {
+ Principal p = new SimplePrincipal("jduke");
+ AppCallbackHandler acbh = new AppCallbackHandler("jduke","theduke".toCharArray());
+ JBossAuthenticationManager am = new JBossAuthenticationManager("test",acbh);
+ assertFalse("Cache Validation is false", am.fromCache());
+ assertTrue(am.isValid(p, "theduke"));
+ assertNotNull("Subject is valid",am.getActiveSubject());
+ assertTrue("Principal is present",
+ am.getActiveSubject().getPrincipals().contains(p));
+ assertFalse("Cache Validation is false", am.fromCache());
+ assertTrue(am.isValid(p, "theduke"));
+ assertTrue("Cache Validation", am.fromCache());
+ assertTrue(am.isValid(p, "theduke"));
+ assertTrue("Cache Validation", am.fromCache());
+
+ acbh = new AppCallbackHandler("jduke","dummy".toCharArray());
+ am = new JBossAuthenticationManager("test",acbh);
+ assertFalse(am.isValid(p, "dummy"));
+ assertFalse("Cache Validation is false", am.fromCache());
+ }
+
+ public void testSecurityCacheInjection() throws Exception
+ {
+ Principal p = new SimplePrincipal("jduke");
+ AppCallbackHandler acbh = new AppCallbackHandler("jduke","theduke".toCharArray());
+ JBossAuthenticationManager am = new JBossAuthenticationManager("test",acbh);
+ am.setSecurityCache(TestSecurityCache.class.getName());
+ assertFalse("Cache Validation is false", am.fromCache());
+ assertTrue(am.isValid(p, "theduke"));
+ assertNotNull("Subject is valid",am.getActiveSubject());
+ assertTrue("Principal is present",
+ am.getActiveSubject().getPrincipals().contains(p));
+ assertFalse("Cache Validation is false", am.fromCache());
+ assertTrue(am.isValid(p, "theduke"));
+ assertTrue("Cache Validation", am.fromCache());
+ assertTrue(am.isValid(p, "theduke"));
+ assertTrue("Cache Validation", am.fromCache());
+
+ acbh = new AppCallbackHandler("jduke","dummy".toCharArray());
+ am = new JBossAuthenticationManager("test",acbh);
+ assertFalse(am.isValid(p, "dummy"));
+ assertFalse("Cache Validation is false", am.fromCache());
+ }
+
private void establishSecurityConfiguration()
{
Configuration.setConfiguration(new TestConfig());
Added: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/TestSecurityCache.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/TestSecurityCache.java (rev 0)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/TestSecurityCache.java 2007-05-13 16:42:32 UTC (rev 63026)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.authentication;
+
+import java.security.Principal;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.security.auth.Subject;
+
+import org.jboss.security.SecurityConstants;
+import org.jboss.security.cache.SecurityCache;
+import org.jboss.security.cache.SecurityCacheException;
+
+//$Id$
+
+/**
+ * Test Security Cache
+ * @author Anil.Saldhana at redhat.com
+ * @since May 13, 2007
+ * @version $Revision$
+ */
+public class TestSecurityCache implements SecurityCache<Principal>
+{
+ private ConcurrentHashMap<Principal, TestCacheEntry> map =
+ new ConcurrentHashMap<Principal, TestCacheEntry>();
+
+ public void addCacheEntry(Principal p, Map<String, Object> cmap)
+ throws SecurityCacheException
+ {
+ TestCacheEntry tce = new TestCacheEntry();
+ tce.cred = (String) cmap.get(SecurityConstants.CREDENTIAL);
+ tce.subj = (Subject) cmap.get(SecurityConstants.SUBJECT);
+ map.put(p, tce);
+ }
+
+ public boolean cacheHit(Principal p)
+ {
+ return map.containsKey(p);
+ }
+
+ public void cacheOperation(Principal p, Map<String, Object> cmap)
+ throws SecurityCacheException
+ {
+ Object c = cmap.get(SecurityConstants.CREDENTIAL);
+ String cred = (String)c;
+ if(map.get(p).cred.equals(cred) == false)
+ throw new SecurityCacheException("fail");
+ }
+
+ @SuppressWarnings("unchecked")
+ public Subject get(Principal p) throws SecurityCacheException
+ {
+ return map.get(p).subj;
+ }
+
+ public class TestCacheEntry
+ {
+ public String cred;
+ public Subject subj;
+ }
+
+}
More information about the jboss-cvs-commits
mailing list