Skip to content

Commit

Permalink
WIP1
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Dec 16, 2019
1 parent 29bfc0e commit 01be231
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 18 deletions.
1 change: 0 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ FROM gcr.io/distroless/java
ARG JAR_FILE

COPY ${JAR_FILE} app.jar
COPY loader.properties loader.properties

EXPOSE 8080

Expand Down
4 changes: 3 additions & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ dependencies {
// Envers for persistent entities versioning
compile 'org.hibernate:hibernate-envers'

//Pacj4 sub-project
runtimeOnly project(':pac4j-module')

enversTestCompile sourceSets.main.output
enversTestCompile sourceSets.test.output
enversTestCompile configurations.compile
Expand Down Expand Up @@ -367,7 +370,6 @@ docker {
pull true
noCache true
files tasks.bootJar.outputs
files 'src/main/docker-files/loader.properties'
buildArgs(['JAR_FILE': "shibui-${version}.jar"])
}

Expand Down
5 changes: 5 additions & 0 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@ shibui.mail.html.email-template-path-prefix=/mail/html/
shibui.mail.system-email-address=doNotReply@shibui.org

shibui.roles=ROLE_ADMIN,ROLE_USER,ROLE_NONE

#In order to enable authentication via configured pac4j library (with external SAMl Idp, for example)
#This property must be set to true and pac4j properties configured. For sample pac4j properties, see application.yml
#for an example pac4j configuration
#shibui.pac4j-enabled=true
18 changes: 18 additions & 0 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
#shibui:
# pac4j-enabled: true
# pac4j:
# keystorePath: "/etc/shibui/samlKeystore.jks"
# keystorePassword: "changeit"
# privateKeyPassword: "changeit"
# serviceProviderEntityId: "https://idp.example.com/shibui"
# serviceProviderMetadataPath: "/etc/shibui/sp-metadata.xml"
# identityProviderMetadataPath: "/etc/shibui/idp-metadata.xml"
# forceServiceProviderMetadataGeneration: false
# callbackUrl: "https://localhost:8443/callback"
# maximumAuthenticationLifetime: 3600000
# saml2ProfileMapping:
# username: urn:oid:0.9.2342.19200300.100.1.1
# firstname: urn:oid:2.5.4.42
# lastname: urn:oid:2.5.4.4
# email: urn:oid:0.9.2342.19200300.100.1.3

custom:
attributes:
# Default attributes
Expand Down
3 changes: 0 additions & 3 deletions pac4j-module/Dockerfile

This file was deleted.

17 changes: 5 additions & 12 deletions pac4j-module/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'groovy'
id 'com.palantir.docker' version '0.20.1'
//id 'com.palantir.docker' version '0.20.1'
id 'jacoco'
id 'org.springframework.boot' version '2.0.0.RELEASE' apply false
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
Expand Down Expand Up @@ -40,19 +40,12 @@ dependencies {

annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"

docker project(':backend')
//docker project(':backend')
}

docker {
/*docker {
name 'unicon/shibui-pac4j'
tags 'latest-pac4j'
files configurations.runtime, tasks.jar.outputs
noCache true
}

task testme(type: Copy) {
from configurations.runtime
into temporaryDir
}
}*/

tasks.docker.dependsOn(tasks.jar, ':backend:docker')
//tasks.docker.dependsOn(tasks.jar, ':backend:docker')
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import org.pac4j.saml.client.SAML2Client;
import org.pac4j.saml.client.SAML2ClientConfiguration;
import org.pac4j.saml.credentials.authenticator.SAML2Authenticator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(name = "shibui.pac4j-enabled", havingValue = "true")
public class Pac4jConfiguration {
@Bean
public SAML2ModelAuthorizationGenerator saml2ModelAuthorizationGenerator(UserRepository userRepository) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package net.unicon.shibui.pac4j;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "shibui.pac4j")
@EnableConfigurationProperties
@ConditionalOnProperty(name = "shibui.pac4j-enabled", havingValue = "true")
public class Pac4jConfigurationProperties {
private String keystorePath = "/tmp/samlKeystore.jks";
private String keystorePassword = "changeit";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.pac4j.springframework.security.web.SecurityFilter;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
Expand All @@ -24,7 +25,9 @@

@Configuration
@AutoConfigureOrder(-1)
@ConditionalOnProperty(name = "shibui.pac4j-enabled", havingValue = "true")
@AutoConfigureAfter(EmailConfiguration.class)

public class WebSecurity {
@Bean("webSecurityConfig")
public WebSecurityConfigurerAdapter webSecurityConfigurerAdapter(final Config config, UserRepository userRepository, RoleRepository roleRepository, Optional<EmailService> emailService, Pac4jConfigurationProperties pac4jConfigurationProperties) {
Expand All @@ -33,6 +36,7 @@ public WebSecurityConfigurerAdapter webSecurityConfigurerAdapter(final Config co

@Configuration
@Order(0)
@ConditionalOnProperty(name = "shibui.pac4j-enabled", havingValue = "true")
public static class FaviconSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
Expand All @@ -42,6 +46,7 @@ protected void configure(HttpSecurity http) throws Exception {

@Configuration
@Order(1)
@ConditionalOnProperty(name = "shibui.pac4j-enabled", havingValue = "true")
public static class UnsecuredSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
Expand All @@ -51,6 +56,7 @@ protected void configure(HttpSecurity http) throws Exception {

@Configuration
@Order(2)
@ConditionalOnProperty(name = "shibui.pac4j-enabled", havingValue = "true")
public static class ErrorSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
Expand Down Expand Up @@ -102,7 +108,7 @@ public void configure(org.springframework.security.config.annotation.web.builder
}

@Bean
public AuditorAware<String> defaultAuditorAware() {
public AuditorAware<String> pac4jAuditorAware() {
return new Pac4jAuditorAware();
}
}

0 comments on commit 01be231

Please sign in to comment.