Skip to content

Commit 09bb590

Browse files
committed
Added SAML authentication backend (w.i.p.)
1 parent 2f6c833 commit 09bb590

5 files changed

Lines changed: 355 additions & 2 deletions

File tree

.settings/org.eclipse.jdt.core.prefs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
3+
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
44
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
55
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
66
org.eclipse.jdt.core.compiler.compliance=1.8

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
<id>clojars</id>
4040
<url>http://clojars.org/repo/</url>
4141
</repository>
42+
<repository>
43+
<!-- Currently used only for the opensaml 2.6.6 dependency -->
44+
<id>alfresco</id>
45+
<url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
46+
</repository>
4247
</repositories>
4348

4449
<dependencies>
@@ -161,6 +166,13 @@
161166
<version>4.7.0.Final</version>
162167
</dependency>
163168

169+
<!-- SAML -->
170+
<dependency>
171+
<groupId>org.springframework.security.extensions</groupId>
172+
<artifactId>spring-security-saml2-core</artifactId>
173+
<version>1.0.9.RELEASE</version>
174+
</dependency>
175+
164176
<!-- Kerberos -->
165177
<dependency>
166178
<groupId>org.apache.kerby</groupId>

src/main/java/eu/openanalytics/containerproxy/auth/AuthenticationBackendFactory.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import eu.openanalytics.containerproxy.auth.impl.LDAPAuthenticationBackend;
3434
import eu.openanalytics.containerproxy.auth.impl.NoAuthenticationBackend;
3535
import eu.openanalytics.containerproxy.auth.impl.OpenIDAuthenticationBackend;
36+
import eu.openanalytics.containerproxy.auth.impl.SAMLAuthenticationBackend;
3637
import eu.openanalytics.containerproxy.auth.impl.SimpleAuthenticationBackend;
3738
import eu.openanalytics.containerproxy.auth.impl.SocialAuthenticationBackend;
3839
import eu.openanalytics.containerproxy.auth.impl.WebServiceAuthenticationBackend;
@@ -50,10 +51,14 @@ public class AuthenticationBackendFactory extends AbstractFactoryBean<IAuthentic
5051
@Inject
5152
private ApplicationContext applicationContext;
5253

53-
// Special case for keycloak: this component registers some beans of its own.
54+
// These backends register some beans of their own, so must be instantiated here.
55+
5456
@Inject
5557
private KeycloakAuthenticationBackend keycloakBackend;
5658

59+
@Inject
60+
private SAMLAuthenticationBackend samlBackend;
61+
5762
@Override
5863
public Class<?> getObjectType() {
5964
return IAuthenticationBackend.class;
@@ -88,6 +93,8 @@ protected IAuthenticationBackend createInstance() throws Exception {
8893
case WebServiceAuthenticationBackend.NAME:
8994
backend = new WebServiceAuthenticationBackend();
9095
break;
96+
case SAMLAuthenticationBackend.NAME:
97+
return samlBackend;
9198
}
9299
if (backend == null) throw new RuntimeException("Unknown authentication type:" + type);
93100

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package eu.openanalytics.containerproxy.auth.impl;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
5+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6+
import org.springframework.security.saml.SAMLAuthenticationProvider;
7+
import org.springframework.security.saml.SAMLEntryPoint;
8+
import org.springframework.security.saml.metadata.MetadataGeneratorFilter;
9+
import org.springframework.security.web.access.channel.ChannelProcessingFilter;
10+
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
11+
import org.springframework.stereotype.Component;
12+
13+
import eu.openanalytics.containerproxy.auth.IAuthenticationBackend;
14+
import eu.openanalytics.containerproxy.auth.impl.saml.SAMLConfiguration.SAMLFilterSet;
15+
16+
@Component
17+
public class SAMLAuthenticationBackend implements IAuthenticationBackend {
18+
19+
public static final String NAME = "saml";
20+
21+
@Autowired(required = false)
22+
private SAMLEntryPoint samlEntryPoint;
23+
24+
@Autowired(required = false)
25+
private MetadataGeneratorFilter metadataGeneratorFilter;
26+
27+
@Autowired(required = false)
28+
private SAMLFilterSet samlFilter;
29+
30+
@Autowired(required = false)
31+
private SAMLAuthenticationProvider samlAuthenticationProvider;
32+
33+
@Override
34+
public String getName() {
35+
return NAME;
36+
}
37+
38+
@Override
39+
public boolean hasAuthorization() {
40+
return true;
41+
}
42+
43+
@Override
44+
public void configureHttpSecurity(HttpSecurity http) throws Exception {
45+
http
46+
.exceptionHandling().authenticationEntryPoint(samlEntryPoint)
47+
.and()
48+
.addFilterBefore(metadataGeneratorFilter, ChannelProcessingFilter.class)
49+
.addFilterAfter(samlFilter, BasicAuthenticationFilter.class);
50+
}
51+
52+
@Override
53+
public void configureAuthenticationManagerBuilder(AuthenticationManagerBuilder auth) throws Exception {
54+
auth.authenticationProvider(samlAuthenticationProvider);
55+
}
56+
57+
@Override
58+
public String getLogoutSuccessURL() {
59+
return "/";
60+
}
61+
}

0 commit comments

Comments
 (0)