[prev in list] [next in list] [prev in thread] [next in thread]
List: opennms-cvs
Subject: [opennms-cvs] SF.net SVN: opennms:[13189]
From: brozow () users ! sourceforge ! net
Date: 2009-04-30 22:17:51
Message-ID: E1LzeZj-0007G1-9z () c3vjzd1 ! ch3 ! sourceforge ! com
[Download RAW message or body]
Revision: 13189
http://opennms.svn.sourceforge.net/opennms/?rev=13189&view=rev
Author: brozow
Date: 2009-04-30 22:17:51 +0000 (Thu, 30 Apr 2009)
Log Message:
-----------
authentication test draft
Modified Paths:
--------------
opennms/trunk/opennms-webapp/pom.xml
Added Paths:
-----------
opennms/trunk/opennms-webapp/src/test/java/org/opennms/web/springframework/security/LdapAuthTest.java
opennms/trunk/opennms-webapp/src/test/resources/applicationContext-ldapTest.xml
Modified: opennms/trunk/opennms-webapp/pom.xml
===================================================================
--- opennms/trunk/opennms-webapp/pom.xml 2009-04-30 20:26:35 UTC (rev 13188)
+++ opennms/trunk/opennms-webapp/pom.xml 2009-04-30 22:17:51 UTC (rev 13189)
@@ -557,5 +557,27 @@
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.directory.server</groupId>
+ <artifactId>apacheds-core</artifactId>
+ <version>1.0.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.directory.server</groupId>
+ <artifactId>apacheds-server-jndi</artifactId>
+ <version>1.0.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>backport-util-concurrent</groupId>
+ <artifactId>backport-util-concurrent</artifactId>
+ <version>3.1</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
Added: opennms/trunk/opennms-webapp/src/test/java/org/opennms/web/springframework/security/LdapAuthTest.java
===================================================================
--- opennms/trunk/opennms-webapp/src/test/java/org/opennms/web/springframework/security/LdapAuthTest.java \
(rev 0)
+++ opennms/trunk/opennms-webapp/src/test/java/org/opennms/web/springframework/security/LdapAuthTest.java 2009-04-30 \
22:17:51 UTC (rev 13189) @@ -0,0 +1,148 @@
+/*
+ * This file is part of the OpenNMS(R) Application.
+ *
+ * OpenNMS(R) is Copyright (C) 2009 The OpenNMS Group, Inc. All rights reserved.
+ * OpenNMS(R) is a derivative work, containing both original code, included code and \
modified + * code that was published under the GNU General Public License. Copyrights \
for modified + * and included code are below.
+ *
+ * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+ *
+ * Modifications:
+ *
+ * Original code base Copyright (C) 1999-2001 Oculan Corp. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * For more information contact:
+ * OpenNMS Licensing <license@opennms.org>
+ * http://www.opennms.org/
+ * http://www.opennms.com/
+ *
+ */
+
+package org.opennms.web.springframework.security;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.commons.codec.binary.Base64;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.mock.web.MockServletContext;
+import org.springframework.security.util.FilterChainProxy;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+
+/**
+ * @author brozow
+ *
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations={
+ "classpath:/applicationContext-ldapTest.xml",
+})
+public class LdapAuthTest {
+
+ @Autowired
+ FilterChainProxy m_authFilterChain;
+
+ MockServletContext m_servletContext;
+
+ String m_contextPath = "/opennms";
+
+ @Before
+ public void setUp() {
+ m_servletContext = new MockServletContext();
+ m_servletContext.setContextPath(m_contextPath);
+ }
+
+ @Test
+ public void testNoAuth() throws IOException, ServletException {
+
+ ServletRequest request = createRequest("GET", "/index.htm");
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ FilterChain chain = new FilterChain() {
+ public void doFilter(ServletRequest arg0, ServletResponse arg1) throws \
IOException, ServletException { + fail("Expected not to get here!");
+ }
+ };
+
+ m_authFilterChain.doFilter(request, response, chain);
+
+ assertEquals(401, response.getStatus());
+
+ }
+
+
+ @Test
+ public void testBasicAuth() throws IOException, ServletException {
+
+ MockHttpServletRequest request = createRequest("GET", "/index.htm", "bob", \
"bobspassword"); +
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ FilterChain chain = new FilterChain() {
+ public void doFilter(ServletRequest arg0, ServletResponse arg1) throws \
IOException, ServletException { + //fail("Expected not to get here!");
+ }
+ };
+
+ m_authFilterChain.doFilter(request, response, chain);
+
+ assertEquals(200, response.getStatus());
+
+ }
+
+ protected MockHttpServletRequest createRequest(String requestType, String \
urlPath) { + MockHttpServletRequest request = new \
MockHttpServletRequest(m_servletContext, requestType, m_contextPath + urlPath); + \
request.setServletPath(m_contextPath + urlPath); + \
request.setContextPath(m_contextPath); + return request;
+ }
+
+ private MockHttpServletRequest createRequest(String requestType, String urlPath, \
String user, String passwd) throws UnsupportedEncodingException { + \
MockHttpServletRequest request = createRequest(requestType, urlPath); + String \
token = user + ":" + passwd; +
+
+ byte[] encodedToken = Base64.encodeBase64(token.getBytes("UTF-8"));
+
+ byte[] prefix = "Basic ".getBytes("UTF-8");
+
+
+ byte[] headerBytes = new byte[prefix.length + encodedToken.length];
+
+ System.arraycopy(prefix, 0, headerBytes, 0, prefix.length);
+ System.arraycopy(encodedToken, 0, headerBytes, prefix.length, \
encodedToken.length); +
+ request.addHeader("Authorization", new String(headerBytes, "UTF-8"));
+ return request;
+ }
+
+}
Added: opennms/trunk/opennms-webapp/src/test/resources/applicationContext-ldapTest.xml
===================================================================
--- opennms/trunk/opennms-webapp/src/test/resources/applicationContext-ldapTest.xml \
(rev 0)
+++ opennms/trunk/opennms-webapp/src/test/resources/applicationContext-ldapTest.xml 2009-04-30 \
22:17:51 UTC (rev 13189) @@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans:beans xmlns="http://www.springframework.org/schema/security"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans \
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd + \
http://www.springframework.org/schema/security \
http://www.springframework.org/schema/security/spring-security-2.0.4.xsd"> + \
+
+ <http auto-config="true">
+ <intercept-url pattern="/**" access="ROLE_USER" />
+ <http-basic/>
+ </http>
+
+
+ <ldap-server ldif="classpath:users.ldif" />
+
+ <authentication-provider>
+ <user-service>
+ <user name="jimi" password="jimispassword" authorities="ROLE_USER, ROLE_ADMIN" \
/> + <user name="bob" password="bobspassword" authorities="ROLE_USER" />
+ </user-service>
+ </authentication-provider>
+
+ </beans:beans>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Please read the OpenNMS Mailing List FAQ:
http://www.opennms.org/wiki/index.php?page=MailingListFaq
opennms-cvs mailing list
To *unsubscribe* or change your subscription options, see the bottom of this page:
https://lists.sourceforge.net/lists/listinfo/opennms-cvs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic