Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit 33598c8

Browse files
Eric MeyerTerry Smith
authored andcommitted
Adds support for protecting incoming connections via SSL and basic authentication.
1 parent a8c063a commit 33598c8

File tree

17 files changed

+558
-74
lines changed

17 files changed

+558
-74
lines changed

.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,6 @@
106106
<classpathentry kind="lib" path="lib/test/derby-10.5.3.0.jar"/>
107107
<classpathentry kind="lib" path="lib/stax2-api-3.0.2.jar"/>
108108
<classpathentry kind="lib" path="lib/woodstox-core-asl-4.0.8.jar"/>
109+
<classpathentry kind="lib" path="lib/jopt-simple-3.2.jar" sourcepath="lib/jopt-simple-3.2-sources.jar"/>
109110
<classpathentry kind="output" path="build.eclipse"/>
110111
</classpath>

build.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
</jar>
189189
</target>
190190

191-
<target name="standalone-jar" depends="war">
191+
<target name="standalone-jar" depends="war" description="Built the stand-alone executable jar.">
192192
<delete file="build.ant/discovery_datatool_standalone.jar"/>
193193
<jar destfile="build.ant/discovery_datatool_standalone.jar">
194194
<fileset dir="build.ant/main">
@@ -197,6 +197,7 @@
197197
<include name="com/t11e/discovery/datatool/CustomLogFormatter.class"/>
198198
</fileset>
199199
<zipgroupfileset dir="lib">
200+
<include name="jopt-simple-3.2.jar"/>
200201
<include name="jetty/jetty-6.1.22.jar"/>
201202
<include name="jetty/jetty-util-6.1.22.jar"/>
202203
<include name="javax/servlet-2.5.jar"/>
@@ -213,7 +214,8 @@
213214
</target>
214215

215216
<property name="external.version" value="0.0.0"/>
216-
<target name="release" depends="standalone-jar">
217+
<target name="release" depends="standalone-jar"
218+
description="Build the distribution ZIP. Can set external.version if building from a tag.">
217219
<delete file="build.ant/discovery_datatool.zip"/>
218220
<zip destfile="build.ant/discovery_datatool-${external.version}.zip">
219221
<zipfileset prefix="discovery_datatool-${external.version}/" dir="stage" excludes="*.sh"/>

lib/jopt-simple-3.2-sources.jar

63.5 KB
Binary file not shown.

lib/jopt-simple-3.2.jar

52 KB
Binary file not shown.

src/config/jetty.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,23 @@
88
</New>
99
</Arg>
1010
</Call>
11-
11+
<Call name="addConnector">
12+
<Arg>
13+
<!--
14+
nio class not found
15+
<New class="org.mortbay.jetty.security.SslSelectChannelConnector">
16+
-->
17+
<New class="org.mortbay.jetty.security.SslSocketConnector">
18+
<Set name="Port"><SystemProperty name="jetty.ssl.port" default="8443"/></Set>
19+
<Set name="maxIdleTime">30000</Set>
20+
<Set name="keystore"><SystemProperty name="jetty.keystore" default="./datatool" /></Set>
21+
<Set name="password">datatool</Set>
22+
<Set name="keyPassword">datatool</Set>
23+
<Set name="truststore"><SystemProperty name="jetty.truststore" default="./datatool" /></Set>
24+
<Set name="trustPassword">datatool</Set>
25+
</New>
26+
</Arg>
27+
</Call>
1228
<Array id="plusConfig" type="java.lang.String">
1329
<Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
1430
<Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>

src/docroot/WEB-INF/applicationContext.xml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:context="http://www.springframework.org/schema/context"
4-
xmlns:mvc="http://www.springframework.org/schema/mvc"
54
xmlns:jee="http://www.springframework.org/schema/jee"
5+
xmlns:mvc="http://www.springframework.org/schema/mvc"
6+
xmlns:sec="http://www.springframework.org/schema/security"
67
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
78
xsi:schemaLocation="http://www.springframework.org/schema/beans
89
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
@@ -11,11 +12,28 @@
1112
http://www.springframework.org/schema/mvc
1213
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
1314
http://www.springframework.org/schema/jee
14-
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
15+
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
16+
http://www.springframework.org/schema/security
17+
http://www.springframework.org/schema/security/spring-security-3.0.xsd
18+
">
1519
<context:annotation-config/>
1620
<context:component-scan base-package="com.t11e.discovery.datatool"/>
1721
<mvc:annotation-driven/>
1822

23+
<sec:authentication-manager>
24+
<sec:authentication-provider user-service-ref="userDetailsService"/>
25+
</sec:authentication-manager>
26+
<sec:http auto-config="true" realm="datatool">
27+
<sec:custom-filter ref="BypassAuthenticationFilter" before="ANONYMOUS_FILTER"/>
28+
<sec:intercept-url pattern="/**" access="ROLE_USER" />
29+
<sec:http-basic />
30+
</sec:http>
31+
<bean id="userDetailsService" class="org.springframework.security.core.userdetails.memory.InMemoryDaoImpl">
32+
<property name="userProperties">
33+
<props/>
34+
</property>
35+
</bean>
36+
1937
<bean name="ConfigurationManager" class="com.t11e.discovery.datatool.ConfigurationManager">
2038
<property name="exitOnInvalidConfigAtStartup" value="true"/>
2139
</bean>
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<schema xmlns="http://www.w3.org/2001/XMLSchema"
3+
targetNamespace="http://transparensee.com/schema/datatool-config-3"
4+
xmlns:tns="http://transparensee.com/schema/datatool-config-3"
5+
elementFormDefault="qualified"
6+
>
7+
8+
<element name="config" type="tns:ConfigType"/>
9+
10+
<complexType name="ConfigType">
11+
<sequence>
12+
<element name="accessControl" type="tns:AccessControlType" minOccurs="0" maxOccurs="1"/>
13+
<element name="dataSources" type="tns:DataSourcesType"/>
14+
<element name="profiles" type="tns:ProfilesType"/>
15+
<element name="publishers" type="tns:PublishersType"/>
16+
</sequence>
17+
</complexType>
18+
19+
<complexType name="AccessControlType">
20+
<annotation>
21+
<documentation xml:lang="en">
22+
Optional restrict feed access using basic HTTP authentication.
23+
Since datatool-config-3.
24+
By adding the element, you turn on basic HTTP authentication.
25+
Add child user elements.
26+
</documentation>
27+
</annotation>
28+
<sequence minOccurs="0">
29+
<element name="user">
30+
<complexType>
31+
<attribute name="name" type="string" use="required"/>
32+
<attribute name="password" type="string" use="required"/>
33+
</complexType>
34+
</element>
35+
</sequence>
36+
</complexType>
37+
38+
<complexType name="DataSourcesType">
39+
<sequence minOccurs="1" maxOccurs="unbounded">
40+
<choice>
41+
<element name="dataSource" type="tns:DataSourceType"/>
42+
<element name="driver" type="tns:DriverType"/>
43+
</choice>
44+
</sequence>
45+
</complexType>
46+
47+
<complexType name="DataSourceType">
48+
<sequence minOccurs="0" maxOccurs="unbounded">
49+
<any processContents="lax"/>
50+
</sequence>
51+
<attribute name="name" type="string" use="required"/>
52+
<attribute name="jar" type="string" use="optional"/>
53+
<attribute name="class" type="string" use="required"/>
54+
</complexType>
55+
56+
<complexType name="DriverType">
57+
<sequence>
58+
<element name="url"/>
59+
<element name="username" minOccurs="0"/>
60+
<element name="password" minOccurs="0"/>
61+
<element name="properties" minOccurs="0">
62+
<complexType>
63+
<sequence minOccurs="0" maxOccurs="unbounded">
64+
<any processContents="lax"/>
65+
</sequence>
66+
</complexType>
67+
</element>
68+
</sequence>
69+
<attribute name="name" type="string" use="required"/>
70+
<attribute name="jar" type="string" use="optional"/>
71+
<attribute name="class" type="string" use="required"/>
72+
</complexType>
73+
74+
<complexType name="ProfilesType">
75+
<sequence minOccurs="1" maxOccurs="unbounded">
76+
<element name="sqlProfile" type="tns:SqlProfileType"/>
77+
</sequence>
78+
</complexType>
79+
80+
<complexType name="PublishersType">
81+
<sequence minOccurs="1" maxOccurs="unbounded">
82+
<element name="sqlPublisher" type="tns:SqlPublisherType"/>
83+
</sequence>
84+
</complexType>
85+
86+
<complexType name="SqlProfileType">
87+
<sequence>
88+
<element name="createSql" type="string" minOccurs="0">
89+
<annotation>
90+
<documentation xml:lang="en">
91+
Optional SQL used to create a profile when one is not found.
92+
Since datatool-config-2.
93+
Bound parameters:
94+
:name -- profile name
95+
Outputs:
96+
none
97+
</documentation>
98+
</annotation>
99+
</element>
100+
<element name="retrieveSql" type="tns:retrieveSql"/>
101+
<element name="updateSql" type="string"/>
102+
</sequence>
103+
<attribute name="name" type="string" use="required"/>
104+
<attribute name="dataSource" type="string" use="required"/>
105+
</complexType>
106+
107+
<complexType name="retrieveSql" mixed="true">
108+
<attribute name="startColumn" use="required"/>
109+
<attribute name="endColumn" use="required"/>
110+
</complexType>
111+
112+
<complexType name="SqlPublisherType">
113+
<sequence minOccurs="1" maxOccurs="unbounded">
114+
<element name="action" type="tns:ActionType"/>
115+
</sequence>
116+
<attribute name="name" type="string" use="required"/>
117+
<attribute name="dataSource" type="string" use="required"/>
118+
<attribute name="profile" type="string" use="required"/>
119+
</complexType>
120+
121+
<complexType name="ActionType">
122+
<sequence>
123+
<element name="query" type="string"/>
124+
</sequence>
125+
<attribute name="type" type="tns:ActionTypeType" use="required"/>
126+
<attribute name="filter" type="tns:FilterActionType" use="optional"/>
127+
<attribute name="idColumn" type="string" use="required"/>
128+
<attribute name="jsonColumnNames" type="string" use="optional"/>
129+
</complexType>
130+
131+
<simpleType name="ActionTypeType">
132+
<restriction base="string">
133+
<enumeration value="create"/>
134+
<enumeration value="delete"/>
135+
</restriction>
136+
</simpleType>
137+
138+
<simpleType name="FilterActionType">
139+
<restriction base="string">
140+
<enumeration value="delta"/>
141+
<enumeration value="snapshot"/>
142+
</restriction>
143+
</simpleType>
144+
</schema>

src/docroot/WEB-INF/web.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
<load-on-startup>2</load-on-startup>
3030
</servlet>
3131

32+
<filter>
33+
<filter-name>springSecurityFilterChain</filter-name>
34+
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
35+
</filter>
36+
<filter-mapping>
37+
<filter-name>springSecurityFilterChain</filter-name>
38+
<url-pattern>/*</url-pattern>
39+
</filter-mapping>
40+
3241
<servlet-mapping>
3342
<servlet-name>static</servlet-name>
3443
<url-pattern>/static/*</url-pattern>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.t11e.discovery.datatool;
2+
3+
import java.io.IOException;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
7+
import javax.servlet.FilterChain;
8+
import javax.servlet.ServletException;
9+
import javax.servlet.ServletRequest;
10+
import javax.servlet.ServletResponse;
11+
12+
import org.springframework.security.authentication.AnonymousAuthenticationToken;
13+
import org.springframework.security.core.GrantedAuthority;
14+
import org.springframework.security.core.authority.GrantedAuthorityImpl;
15+
import org.springframework.security.core.context.SecurityContextHolder;
16+
import org.springframework.security.core.userdetails.User;
17+
import org.springframework.stereotype.Component;
18+
import org.springframework.web.filter.GenericFilterBean;
19+
20+
@Component("BypassAuthenticationFilter")
21+
public class BypassAuthenticationFilter
22+
extends GenericFilterBean
23+
{
24+
private static final List<GrantedAuthority> DEFAULT_ROLES =
25+
Arrays.asList((GrantedAuthority) new GrantedAuthorityImpl("ROLE_USER"));
26+
private final byte[] bypassLock = {};
27+
private boolean bypass = true;
28+
29+
@Override
30+
public void doFilter(
31+
final ServletRequest request,
32+
final ServletResponse response,
33+
final FilterChain chain)
34+
throws IOException, ServletException
35+
{
36+
final boolean doBypass;
37+
synchronized (bypassLock)
38+
{
39+
doBypass = bypass;
40+
}
41+
if (doBypass && SecurityContextHolder.getContext().getAuthentication() == null)
42+
{
43+
final AnonymousAuthenticationToken auth =
44+
new AnonymousAuthenticationToken("bypass_auth", "bypass_auth", DEFAULT_ROLES);
45+
auth.setDetails(new User("bypass_auth", "bypass_auth", true, true, true, true, DEFAULT_ROLES));
46+
SecurityContextHolder.getContext().setAuthentication(auth);
47+
}
48+
chain.doFilter(request, response);
49+
}
50+
51+
public void setBypass(final boolean bypass)
52+
{
53+
synchronized (bypassLock)
54+
{
55+
this.bypass = bypass;
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)