Skip to content

Commit e9f5f53

Browse files
authored
Disable LDAP-based auth (#223)
* Disable current auth config * Add token validation dependencies * Disable LDAP based auth, hardcode user * Deploy from branch * Look in Maven Central first * Put central at the start of repository list * Keep the Postgres driver dependency * Adjust resources to recommended * Remove commented code * Reset deploy workflow trigger
1 parent cd304d4 commit e9f5f53

File tree

8 files changed

+79
-80
lines changed

8 files changed

+79
-80
lines changed

.mvn/settings.xml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@
1010
<activeByDefault>true</activeByDefault>
1111
</activation>
1212
<repositories>
13+
<repository>
14+
<id>central</id>
15+
<name>Central Repository</name>
16+
<url>https://repo.maven.apache.org/maven2</url>
17+
<snapshots>
18+
<enabled>false</enabled>
19+
</snapshots>
20+
</repository>
21+
1322
<repository>
1423
<id>github</id>
1524
<name>GitHub Packages</name>
1625
<url>https://maven.pkg.github.com/${github.repository}</url>
1726
</repository>
27+
1828
<repository>
1929
<id>maven-restlet</id>
2030
<name>Public online Restlet repository</name>
@@ -23,12 +33,4 @@
2333
</repositories>
2434
</profile>
2535
</profiles>
26-
27-
<mirrors>
28-
<mirror>
29-
<id>maven-restletMirror</id>
30-
<url>https://maven.restlet.talend.com</url>
31-
<mirrorOf>maven-restlet</mirrorOf>
32-
</mirror>
33-
</mirrors>
3436
</settings>

.nais/test/klass-forvaltning.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ spec:
1717
max: 1
1818
resources:
1919
requests:
20-
cpu: 100m
21-
memory: 768Mi
20+
cpu: 400m
21+
memory: 448Mi
2222
limits:
23-
memory: 768Mi
23+
memory: 576Mi
2424
env:
2525
- name: SPRING_PROFILES_ACTIVE
2626
value: frontend, postgres, small-import, skip-indexing, ad-offline, embedded-solr

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ run-klass-forvaltning-local:
4545
popd; \
4646
${sdk} env clear
4747

48+
.PHONY: run-klass-forvaltning-local-postgres
49+
run-klass-forvaltning-local-postgres:
50+
pushd klass-forvaltning && \
51+
${sdk} env && \
52+
mvn spring-boot\:run -Dspring.profiles.active=postgres-local,embedded-solr,frontend,skip-indexing,small-import,ad-offline; \
53+
popd; \
54+
${sdk} env clear
55+
56+
4857
.PHONY: run-klass-forvaltning-local-mariadb
4958
# Requires that a MariaDB instance is already running with a database called klass and a user called klass.
5059
# The environment variable KLASS_ENV_MARIADB_PASSWORD must be specified with the password for the klass user.

klass-forvaltning/pom.xml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
<properties>
1313
<java.version>1.8</java.version>
14+
<maven.compiler.source>1.8</maven.compiler.source>
15+
<maven.compiler.target>1.8</maven.compiler.target>
16+
1417
<github.repository>statisticsnorway/klass</github.repository>
1518
<!-- Klass dependencies are built with support for Java 8 and Spring Boot 1.4.4.
1619
Newer versions are not supported -->
@@ -38,6 +41,7 @@
3841
<spring-restdocs.version>1.2.1.RELEASE</spring-restdocs.version>
3942
<solr-version>5.5.5</solr-version>
4043
<spring-data-solr-version>2.1.0.RELEASE</spring-data-solr-version>
44+
<postgresql.version>42.7.5</postgresql.version>
4145
</properties>
4246

4347
<parent>
@@ -54,14 +58,15 @@
5458
</scm>
5559

5660
<repositories>
57-
<repository>
58-
<id>vaadin-addons</id>
59-
<url>https://maven.vaadin.com/vaadin-addons</url>
60-
</repository>
6161
<repository>
6262
<id>github</id>
6363
<url>https://maven.pkg.github.com/${github.repository}</url>
6464
</repository>
65+
66+
<repository>
67+
<id>vaadin-addons</id>
68+
<url>https://maven.vaadin.com/vaadin-addons</url>
69+
</repository>
6570
</repositories>
6671

6772
<dependencies>
@@ -81,6 +86,22 @@
8186
<artifactId>spring-data-solr</artifactId>
8287
<version>${spring-data-solr-version}</version>
8388
</dependency>
89+
<dependency>
90+
<groupId>org.postgresql</groupId>
91+
<artifactId>postgresql</artifactId>
92+
<version>${postgresql.version}</version>
93+
</dependency>
94+
95+
<dependency>
96+
<groupId>org.springframework.security</groupId>
97+
<artifactId>spring-security-oauth2-resource-server</artifactId>
98+
<version>5.1.13.RELEASE</version>
99+
</dependency>
100+
<dependency>
101+
<groupId>org.springframework.security</groupId>
102+
<artifactId>spring-security-oauth2-jose</artifactId>
103+
<version>5.1.13.RELEASE</version>
104+
</dependency>
84105

85106
<!--TOMCAT-->
86107
<dependency>

klass-forvaltning/src/main/java/no/ssb/klass/designer/MainView.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
package no.ssb.klass.designer;
22

3-
import static com.google.common.base.Preconditions.*;
4-
5-
import java.util.List;
6-
7-
import org.springframework.beans.factory.annotation.Autowired;
8-
import org.springframework.security.core.Authentication;
9-
import org.vaadin.spring.security.VaadinSecurity;
10-
113
import com.google.common.collect.Iterables;
124
import com.vaadin.navigator.Navigator;
135
import com.vaadin.navigator.ViewChangeListener;
@@ -17,7 +9,6 @@
179
import com.vaadin.ui.MenuBar;
1810
import com.vaadin.ui.NativeSelect;
1911
import com.vaadin.ui.UI;
20-
2112
import no.ssb.klass.core.model.ClassificationType;
2213
import no.ssb.klass.core.model.User;
2314
import no.ssb.klass.designer.admin.AdminView;
@@ -31,10 +22,19 @@
3122
import no.ssb.klass.designer.util.KlassTheme;
3223
import no.ssb.klass.designer.util.ParameterUtil;
3324
import no.ssb.klass.designer.util.VaadinUtil;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
import org.springframework.beans.factory.annotation.Autowired;
28+
import org.vaadin.spring.security.VaadinSecurity;
29+
30+
import java.util.List;
31+
32+
import static com.google.common.base.Preconditions.checkNotNull;
3433

3534
@SpringUI
3635
@SuppressWarnings("serial")
3736
public class MainView extends MainDesign implements ViewChangeListener {
37+
private static final Logger log = LoggerFactory.getLogger(MainView.class);
3838
private Navigator navigator;
3939

4040
private final SpringViewProvider springViewProvider;
@@ -46,7 +46,7 @@ public class MainView extends MainDesign implements ViewChangeListener {
4646

4747
@Autowired
4848
public MainView(ClassificationFacade classificationFacade, SpringViewProvider springViewProvider,
49-
VaadinSecurity vaadinSecurity, KlassLoginService vaadinLoginService, UserContext userContext) {
49+
VaadinSecurity vaadinSecurity, KlassLoginService vaadinLoginService, UserContext userContext) {
5050
this.springViewProvider = springViewProvider;
5151
this.klassLoginService = vaadinLoginService;
5252
this.vaadinSecurity = vaadinSecurity;
@@ -84,15 +84,12 @@ private void createInnholdBruksstatistikkView() {
8484
}
8585

8686
private void verifyUser() {
87-
Authentication authentication = vaadinSecurity.getAuthentication();
88-
if (!userContext.hasUser() && vaadinSecurity.isRememberMeAuthenticated()) {
89-
// create user based on remembered credentials (Remember me)
90-
try {
91-
User user = klassLoginService.getUserFromAuthentication(authentication);
92-
userContext.setUser(user);
93-
} catch (Exception e) {
94-
vaadinSecurity.logout();
95-
}
87+
if (!userContext.hasUser()) {
88+
/* TODO https://statistics-norway.atlassian.net/browse/DPMETA-916
89+
Replace hardcoded user with user info extracted from the token
90+
*/
91+
log.debug("Set User {}", userContext);
92+
userContext.setUser(new User("kno@ssb.no", "Kari Nordmann", "854"));
9693
}
9794
}
9895

klass-forvaltning/src/main/java/no/ssb/klass/forvaltning/config/production/KlassAuthenticationConfiguration.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package no.ssb.klass.forvaltning.config.production;
22

3+
import no.ssb.klass.core.ldap.KlassUserDetailsMapper;
34
import org.hibernate.validator.constraints.NotEmpty;
45
import org.springframework.beans.factory.annotation.Value;
56
import org.springframework.context.annotation.Bean;
6-
import org.springframework.context.annotation.Configuration;
7-
import org.springframework.context.annotation.Profile;
87
import org.springframework.ldap.core.support.LdapContextSource;
98
import org.springframework.security.authentication.AuthenticationProvider;
109
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
@@ -18,16 +17,13 @@
1817
import org.springframework.security.web.authentication.rememberme.InMemoryTokenRepositoryImpl;
1918
import org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices;
2019

21-
import no.ssb.klass.core.config.ConfigurationProfiles;
22-
import no.ssb.klass.core.ldap.KlassUserDetailsMapper;
23-
2420
/**
2521
* Configuration for production environment, all test beans are excluded
2622
*
2723
* @author Mads Lundemo, SSB.
2824
*/
29-
@Configuration
30-
@Profile(value = ConfigurationProfiles.PRODUCTION)
25+
//@Configuration
26+
//@Profile(value = ConfigurationProfiles.PRODUCTION)
3127
public class KlassAuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter {
3228

3329
/**
@@ -86,11 +82,11 @@ public LdapContextSource ldapContext() {
8682
@Bean
8783
public FilterBasedLdapUserSearch ldapUserSearch(LdapContextSource ldapContext) {
8884
FilterBasedLdapUserSearch search = new FilterBasedLdapUserSearch(searchBase, searchFilter, ldapContext);
89-
String[] attributes = { KlassUserDetailsMapper.SECTION_ATTRIBUTE,
85+
String[] attributes = {KlassUserDetailsMapper.SECTION_ATTRIBUTE,
9086
KlassUserDetailsMapper.NAME_ATTRIBUTE,
9187
KlassUserDetailsMapper.MAIL_ATTRIBUTE,
9288
KlassUserDetailsMapper.MOBILE_PHONE_ATTRIBUTE,
93-
KlassUserDetailsMapper.LANDLINE_PHONE_ATTRIBUTE };
89+
KlassUserDetailsMapper.LANDLINE_PHONE_ATTRIBUTE};
9490
search.setReturningAttributes(attributes);
9591
search.setSearchSubtree(true);
9692
return search;

klass-forvaltning/src/main/java/no/ssb/klass/forvaltning/config/production/KlassSecurityConfiguration.java

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
package no.ssb.klass.forvaltning.config.production;
22

3-
import no.ssb.klass.core.config.ConfigurationProfiles;
4-
import org.hibernate.validator.constraints.NotEmpty;
5-
import org.springframework.beans.factory.annotation.Autowired;
6-
import org.springframework.beans.factory.annotation.Value;
3+
import no.ssb.klass.designer.ui.LoginUI;
4+
import no.ssb.klass.forvaltning.config.test.KlassTestAuthenticationConfiguration;
5+
import no.ssb.klass.forvaltning.controllers.monitor.MonitorController;
6+
import no.ssb.klass.forvaltning.controllers.ping.PingController;
77
import org.springframework.context.annotation.Configuration;
88
import org.springframework.context.annotation.Import;
99
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
1010
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
1111
import org.springframework.security.config.annotation.web.builders.WebSecurity;
1212
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
13-
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
14-
import org.springframework.security.web.authentication.RememberMeServices;
1513
import org.vaadin.spring.annotation.EnableVaadinExtensions;
1614
import org.vaadin.spring.security.annotation.EnableVaadinSharedSecurity;
1715

18-
import no.ssb.klass.forvaltning.config.test.KlassTestAuthenticationConfiguration;
19-
import no.ssb.klass.forvaltning.controllers.monitor.MonitorController;
20-
import no.ssb.klass.forvaltning.controllers.ping.PingController;
21-
import no.ssb.klass.designer.ui.KlassUI;
22-
import no.ssb.klass.designer.ui.LoginUI;
23-
2416
/**
2517
* @author Mads Lundemo, SSB.
2618
*/
19+
2720
@Configuration
2821
@EnableVaadinExtensions
2922
@EnableVaadinSharedSecurity
@@ -33,45 +26,26 @@ public class KlassSecurityConfiguration extends WebSecurityConfigurerAdapter {
3326

3427
private static final String WILDCARD = "**";
3528

36-
@NotEmpty
37-
@Value("${klass.env.security.ldap.remember.time}")
38-
private int rememberTime;
39-
40-
@NotEmpty
41-
@Value("${klass.env.security.remember.key}")
42-
private String rememberKey;
43-
44-
@Autowired
45-
private RememberMeServices rememberMeServices;
46-
4729
@Override
4830
public void configure(WebSecurity web) throws Exception {
4931
web.ignoring().antMatchers("/VAADIN/" + WILDCARD);
5032
}
5133

5234
@Override
5335
protected void configure(HttpSecurity http) throws Exception {
54-
http.exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/" + LoginUI.PATH));
55-
http.rememberMe()
56-
.key(rememberKey)
57-
.rememberMeServices(rememberMeServices)
58-
.tokenValiditySeconds(rememberTime);
59-
// .useSecureCookie(true); TODO enable secure cookie when(or if) we switch to
60-
// https
61-
6236
http.authorizeRequests()
6337
.antMatchers("/" + LoginUI.PATH).permitAll()
6438
.antMatchers("/vaadinServlet/UIDL/" + WILDCARD).permitAll()
65-
.antMatchers("/vaadinServlet/HEARTBEAT/" + WILDCARD).authenticated()
66-
.antMatchers("/" + KlassUI.PATH + "/" + WILDCARD).authenticated()
39+
// .antMatchers("/vaadinServlet/HEARTBEAT/" + WILDCARD).authenticated()
40+
// .antMatchers("/" + KlassUI.PATH + "/" + WILDCARD).authenticated()
6741
.antMatchers("/manage/" + WILDCARD).hasRole("KLASS_ADMINISTRATOR")
6842
.antMatchers("/" + WILDCARD).permitAll()
6943

7044
.antMatchers(PingController.PATH).permitAll()
7145
.antMatchers(MonitorController.PATH).permitAll()
72-
.anyRequest().authenticated().and().sessionManagement()
73-
.sessionFixation()
74-
.migrateSession()
46+
// .anyRequest().authenticated().and().sessionManagement()
47+
// .sessionFixation()
48+
// .migrateSession()
7549
.and()
7650
// disable csrf to avoid conflict with vaadins (or else we would have two csrfs)
7751
.csrf().disable()

klass-shared/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
<klass.doc.env.url/>
2626
<klass.doc.env.port/>
2727

28-
<postgresql.version>42.7.5</postgresql.version>
2928
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3029
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
3130
<findbugs-version>3.0.5</findbugs-version>
@@ -39,6 +38,7 @@
3938
<asciidoctor-version>1.6.0</asciidoctor-version>
4039
<maven-jaxb2-plugin-version>2.5.0</maven-jaxb2-plugin-version>
4140
<tomcat7-maven-plugin-version>2.2</tomcat7-maven-plugin-version>
41+
<postgresql.version>42.7.5</postgresql.version>
4242
</properties>
4343

4444
<dependencies>

0 commit comments

Comments
 (0)