Skip to content

Commit

Permalink
Springboot 3.3.0, initial
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmccormackbconline committed May 31, 2024
1 parent f94be99 commit ddd1c24
Show file tree
Hide file tree
Showing 63 changed files with 149 additions and 168 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ plugins {
id 'java'
id 'idea'
id 'jacoco'
id 'org.springframework.boot' version '2.7.1'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.springframework.boot' version '3.3.0'
id 'io.spring.dependency-management' version '1.1.5'
id 'com.github.node-gradle.node' version '3.5.1'
id 'io.gatling.gradle' version '3.9.0.1'
id 'org.sonarqube' version '3.5.0.2730'
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/uk/co/bconline/ndelius/UserManagementAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;

@OpenAPIDefinition(
info = @Info(
title = "Delius User Management Tool (UMT)",
description = "REST API to enable NPS-ICT to effectively create and maintain user accounts in the National Delius application, and to allow external services to securely authenticate Probation staff.",
contact = @Contact(name = "Unilink", url = "https://unilink.com")),
externalDocs = @ExternalDocumentation(description = "GitHub", url = "https://github.com/ministryofjustice/ndelius-um"))
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableMethodSecurity(prePostEnabled = true)
@SpringBootApplication(exclude = {EmbeddedLdapAutoConfiguration.class})
public class UserManagementAPI {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.springframework.web.method.HandlerMethod;
import uk.co.bconline.ndelius.util.AuthUtils;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

import static java.util.Optional.ofNullable;
import static org.springframework.web.servlet.HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import uk.co.bconline.ndelius.model.ErrorResponse;
import uk.co.bconline.ndelius.model.ForbiddenResponse;

import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolationException;
import javax.validation.ElementKind;
import javax.validation.Path;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.ElementKind;
import jakarta.validation.Path;
import java.util.Iterator;

import static java.util.stream.Collectors.toList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration;
import org.springframework.boot.autoconfigure.ldap.LdapConnectionDetails;
import org.springframework.boot.autoconfigure.ldap.LdapProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -38,9 +39,9 @@ public LdapConfig(Environment environment) {
@Bean
@Primary
@Override
public LdapContextSource ldapContextSource(LdapProperties properties, Environment environment,
public LdapContextSource ldapContextSource(LdapConnectionDetails connectionDetails, LdapProperties properties,
ObjectProvider<DirContextAuthenticationStrategy> dirContextAuthenticationStrategy) {
val ctxSource = super.ldapContextSource(properties, environment, dirContextAuthenticationStrategy);
val ctxSource = super.ldapContextSource(connectionDetails, properties, dirContextAuthenticationStrategy);
val pooled = Boolean.parseBoolean(properties.getBaseEnvironment().getOrDefault("com.sun.jndi.ldap.connect.pool", "false"));
ctxSource.setPooled(pooled);
return ctxSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration;
import org.springframework.boot.autoconfigure.ldap.LdapConnectionDetails;
import org.springframework.boot.autoconfigure.ldap.LdapProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -23,10 +24,10 @@ public class LdapExportConfig extends LdapAutoConfiguration {

@Override
@Bean("exportLdapContextSource")
public LdapContextSource ldapContextSource(LdapProperties properties, Environment environment,
public LdapContextSource ldapContextSource(LdapConnectionDetails connectionDetails, LdapProperties properties,
ObjectProvider<DirContextAuthenticationStrategy> dirContextAuthenticationStrategy) {
properties.setUsername(exportUser);
val ctxSource = super.ldapContextSource(properties, environment, dirContextAuthenticationStrategy);
val ctxSource = super.ldapContextSource(connectionDetails, properties, dirContextAuthenticationStrategy);
val pooled = Boolean.parseBoolean(properties.getBaseEnvironment().getOrDefault("com.sun.jndi.ldap.connect.pool", "false"));
ctxSource.setPooled(pooled);
return ctxSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import uk.co.bconline.ndelius.config.data.embedded.interceptor.AliasInterceptor;
import uk.co.bconline.ndelius.config.data.embedded.interceptor.MemberOfInterceptor;

import javax.annotation.PreDestroy;
import jakarta.annotation.PreDestroy;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.springframework.stereotype.Component;
import redis.embedded.RedisServer;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import java.io.IOException;

@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
Expand All @@ -28,15 +29,14 @@
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.web.servlet.view.RedirectView;
import uk.co.bconline.ndelius.config.security.provider.endpoint.PathMatchRedirectResolver;
import uk.co.bconline.ndelius.config.security.provider.token.PreAuthenticatedTokenGranter;
import uk.co.bconline.ndelius.config.security.provider.token.store.redis.SaferRedisTokenStore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import static java.util.Arrays.asList;

Expand Down Expand Up @@ -87,8 +87,8 @@ public void configure(AuthorizationServerSecurityConfigurer security) {
security.realm("ndelius-clients")
.passwordEncoder(passwordEncoder)
.tokenKeyAccess("permitAll()")
.checkTokenAccess("isAuthenticated()")
.addTokenEndpointAuthenticationFilter(new CorsFilter(corsConfigurationSource()));
.checkTokenAccess("isAuthenticated()");
// .addTokenEndpointAuthenticationFilter((Filter) new CorsFilter(corsConfigurationSource()));
}

@Override
Expand Down Expand Up @@ -135,7 +135,7 @@ public static ConfigureRedisAction configureRedisAction() {
*/
@Bean
public HandlerInterceptor invalidateSessionInterceptor() {
return new HandlerInterceptorAdapter() {
return new HandlerInterceptor() {
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response, Object handler,
Expand All @@ -153,6 +153,11 @@ public void postHandle(HttpServletRequest request,
};
}

@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}

private TokenGranter tokenGranter(final AuthorizationServerEndpointsConfigurer endpoints) {
// Append the token granter for the 'preauthenticated' grant_type to the list of oauth token granters
return new CompositeTokenGranter(asList(endpoints.getTokenGranter(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,16 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.crypto.password.LdapShaPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import uk.co.bconline.ndelius.util.LdapUtils;

import static org.springframework.web.cors.CorsConfiguration.ALL;

@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {

@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.mvcMatchers("/api/**").authenticated()
.and().cors()
.and().headers().frameOptions().disable()
.and().csrf().disable();
}
public class ResourceServerConfig {

@Bean
public WebMvcConfigurer corsConfigurer() {
Expand All @@ -37,11 +23,6 @@ public void addCorsMappings(CorsRegistry registry) {
};
}

@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.resourceId("NDelius");
}

@Bean
public PasswordEncoder passwordEncoder() {
return new LdapShaPasswordEncoder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.web.SecurityFilterChain;

@Order(1)
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
public class WebSecurityConfig {

@Bean
@Override
public AuthenticationManager authenticationManager() throws Exception {
return super.authenticationManager();
}
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(auth -> auth
.requestMatchers("/login", "/oauth/authorize")
.permitAll()
.anyRequest().authenticated()).formLogin(form -> form.loginPage("/login").permitAll())
.httpBasic(basic -> basic.realmName("ndelius-users"))
.headers(options -> options.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable));

@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.requestMatchers()
.antMatchers("/login", "/oauth/authorize")
.and().authorizeRequests()
.anyRequest().authenticated()
.and().formLogin().loginPage("/login").permitAll()
.and().httpBasic().realmName("ndelius-users")
.and().headers().frameOptions().disable();
return http.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import uk.co.bconline.ndelius.validator.NewUsernameMustNotAlreadyExist;
import uk.co.bconline.ndelius.validator.UsernameMustNotAlreadyExist;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/uk/co/bconline/ndelius/model/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.*;

import javax.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotBlank;

@Getter
@Builder
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/uk/co/bconline/ndelius/model/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;

import javax.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotBlank;
import java.util.List;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package uk.co.bconline.ndelius.model;

import javax.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotBlank;

import lombok.*;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/uk/co/bconline/ndelius/model/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;

import javax.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotBlank;
import java.util.List;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/uk/co/bconline/ndelius/model/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.*;

import javax.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotBlank;

@Getter
@Builder
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/uk/co/bconline/ndelius/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import lombok.*;
import uk.co.bconline.ndelius.validator.*;

import javax.persistence.Transient;
import javax.validation.Valid;
import javax.validation.constraints.*;
import jakarta.persistence.Transient;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.*;

import javax.persistence.*;
import jakarta.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Cache;

import javax.persistence.*;
import jakarta.persistence.*;
import java.io.Serializable;

import static org.hibernate.annotations.CacheConcurrencyStrategy.READ_ONLY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.hibernate.annotations.Cache;
import uk.co.bconline.ndelius.model.entity.converter.YNConverter;

import javax.persistence.*;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import jakarta.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import jakarta.persistence.Embeddable;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import java.io.Serializable;

@Embeddable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Cache;

import javax.persistence.*;
import jakarta.persistence.*;
import java.io.Serializable;

import static org.hibernate.annotations.CacheConcurrencyStrategy.READ_ONLY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Getter;
import org.hibernate.annotations.Cache;

import javax.persistence.*;
import jakarta.persistence.*;
import java.io.Serializable;

import static org.hibernate.annotations.CacheConcurrencyStrategy.READ_ONLY;
Expand Down
Loading

0 comments on commit ddd1c24

Please sign in to comment.