[jboss-cvs] JBossAS SVN: r65934 - in projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/security: mapping and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 8 15:57:13 EDT 2007
Author: anil.saldhana at jboss.com
Date: 2007-10-08 15:57:13 -0400 (Mon, 08 Oct 2007)
New Revision: 65934
Added:
projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/security/mapping/
projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/security/mapping/PrincipalMappingUnitTestCase.java
projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/security/mapping/TestX509Certificate.java
Log:
SECURITY-79:principal mapping providers
Added: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/security/mapping/PrincipalMappingUnitTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/security/mapping/PrincipalMappingUnitTestCase.java (rev 0)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/security/mapping/PrincipalMappingUnitTestCase.java 2007-10-08 19:57:13 UTC (rev 65934)
@@ -0,0 +1,91 @@
+/*
+ * 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.security.mapping;
+
+import java.security.Principal;
+import java.security.cert.X509Certificate;
+import java.util.HashMap;
+
+import javax.security.auth.x500.X500Principal;
+
+import junit.framework.TestCase;
+
+import org.jboss.security.SecurityContext;
+import org.jboss.security.SecurityContextFactory;
+import org.jboss.security.SimplePrincipal;
+import org.jboss.security.config.ApplicationPolicy;
+import org.jboss.security.config.MappingInfo;
+import org.jboss.security.config.SecurityConfiguration;
+import org.jboss.security.mapping.MappingContext;
+import org.jboss.security.mapping.MappingManager;
+import org.jboss.security.mapping.config.MappingModuleEntry;
+
+//$Id$
+
+/**
+ * Tests the Principal Mapping layer
+ * @author Anil.Saldhana at redhat.com
+ * @since Oct 5, 2007
+ * @version $Revision$
+ */
+public class PrincipalMappingUnitTestCase extends TestCase
+{
+ protected void setUp() throws Exception
+ {
+ ApplicationPolicy ap = new ApplicationPolicy("test");
+ SecurityConfiguration.addApplicationPolicy(ap);
+ }
+
+ public void testX509() throws Exception
+ {
+ ApplicationPolicy ap = SecurityConfiguration.getApplicationPolicy("test");
+ String name = "org.jboss.security.mapping.providers.principal.SubjectDNMapper";
+ MappingModuleEntry mme = new MappingModuleEntry(name);
+ MappingInfo principalMappingInfo = new MappingInfo();
+ principalMappingInfo.add(mme);
+ ap.setPrincipalMappingInfo(principalMappingInfo);
+
+ String issuerDN = "CN=Fedora,OU=JBoss,O=Red Hat,C=US";
+ String subjectDN = "CN=Anil,OU=JBoss,O=Red Hat,C=US";
+
+ SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
+ MappingManager mm = sc.getMappingManager();
+ assertNotNull("MappingManager != null", mm);
+ MappingContext mc = mm.getMappingContext(Principal.class);
+ assertNotNull("MappingContext != null", mc);
+ Principal x509 = new SimplePrincipal("CN=Fedora, OU=JBoss, O=Red Hat, C=DE");
+ HashMap map = new HashMap();
+
+ X509Certificate cert = getX509Certificate(issuerDN,subjectDN);
+ X509Certificate[] certs = new X509Certificate[]{cert};
+ map.put("X509", certs);
+ mc.performMapping(map, x509);
+ Principal mappedPrincipal = (Principal) mc.getMappingResult().getMappedObject();
+ assertEquals(subjectDN,mappedPrincipal.getName());
+ }
+
+ private X509Certificate getX509Certificate(String issuerDN, String subjectDN)
+ {
+ return new TestX509Certificate(new X500Principal(issuerDN),
+ new X500Principal(subjectDN));
+ }
+}
\ No newline at end of file
Added: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/security/mapping/TestX509Certificate.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/security/mapping/TestX509Certificate.java (rev 0)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/security/mapping/TestX509Certificate.java 2007-10-08 19:57:13 UTC (rev 65934)
@@ -0,0 +1,214 @@
+/*
+ * 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.security.mapping;
+
+import java.math.BigInteger;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Principal;
+import java.security.PublicKey;
+import java.security.SignatureException;
+import java.util.Date;
+import java.util.Set;
+
+import javax.security.auth.x500.X500Principal;
+
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateExpiredException;
+import java.security.cert.CertificateNotYetValidException;
+import java.security.cert.X509Certificate;
+
+//$Id$
+
+/**
+ * Test X509Certificate
+ * @author Anil.Saldhana at redhat.com
+ * @since Oct 5, 2007
+ * @version $Revision$
+ */
+public class TestX509Certificate extends X509Certificate
+{
+ X500Principal issuer = null;
+ X500Principal subject = null;
+
+ public TestX509Certificate(X500Principal issuer, X500Principal subject)
+ {
+ this.issuer = issuer;
+ this.subject = subject;
+ }
+
+ @Override
+ public void checkValidity()
+ throws CertificateExpiredException, CertificateNotYetValidException
+ {
+ }
+
+ @Override
+ public void checkValidity(Date date)
+ throws CertificateExpiredException, CertificateNotYetValidException
+ {
+ }
+
+ @Override
+ public int getBasicConstraints()
+ {
+ return 0;
+ }
+
+ @Override
+ public Principal getIssuerDN()
+ {
+ return issuer;
+ }
+
+ @Override
+ public boolean[] getIssuerUniqueID()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean[] getKeyUsage()
+ {
+ return null;
+ }
+
+ @Override
+ public Date getNotAfter()
+ {
+ return null;
+ }
+
+ @Override
+ public Date getNotBefore()
+ {
+ return null;
+ }
+
+ @Override
+ public BigInteger getSerialNumber()
+ {
+ return null;
+ }
+
+ @Override
+ public String getSigAlgName()
+ {
+ return null;
+ }
+
+ @Override
+ public String getSigAlgOID()
+ {
+ return null;
+ }
+
+ @Override
+ public byte[] getSigAlgParams()
+ {
+ return null;
+ }
+
+ @Override
+ public byte[] getSignature()
+ {
+ return null;
+ }
+
+ @Override
+ public Principal getSubjectDN()
+ {
+ return subject;
+ }
+
+ @Override
+ public boolean[] getSubjectUniqueID()
+ {
+ return null;
+ }
+
+ @Override
+ public byte[] getTBSCertificate() throws CertificateEncodingException
+ {
+ return null;
+ }
+
+ @Override
+ public int getVersion()
+ {
+ return 0;
+ }
+
+ @Override
+ public byte[] getEncoded() throws CertificateEncodingException
+ {
+ return null;
+ }
+
+ @Override
+ public PublicKey getPublicKey()
+ {
+ return null;
+ }
+
+ @Override
+ public String toString()
+ {
+ return null;
+ }
+
+ @Override
+ public void verify(PublicKey arg0)
+ throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
+ NoSuchProviderException, SignatureException
+ {
+ }
+
+ @Override
+ public void verify(PublicKey arg0, String arg1)
+ throws CertificateException, NoSuchAlgorithmException,
+ InvalidKeyException, NoSuchProviderException, SignatureException
+ {
+ }
+
+ public Set<String> getCriticalExtensionOIDs()
+ {
+ return null;
+ }
+
+ public byte[] getExtensionValue(String arg0)
+ {
+ return null;
+ }
+
+ public Set<String> getNonCriticalExtensionOIDs()
+ {
+ return null;
+ }
+
+ public boolean hasUnsupportedCriticalExtension()
+ {
+ return false;
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list