Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T2D-298 spring boot 2 #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<version>2.0.0.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -88,22 +89,22 @@
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-data-rest</artifactId>
<version>2.8.0</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>2.8.0</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -139,4 +140,12 @@
</plugins>
</build>

<repositories>
<repository>
<id>JFrog</id>
<name>JFrog Snapshot Repository</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
</repository>
</repositories>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class PropertyRegistryServiceApplication extends SpringBootServletInitializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package uk.ac.ebi.ampt2d.registry.config;

import com.fasterxml.classmate.TypeResolver;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -43,15 +41,16 @@
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.UiConfiguration;
import springfox.documentation.swagger.web.UiConfigurationBuilder;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.lang.reflect.WildcardType;
import java.util.Arrays;
import java.util.function.Predicate;

import static springfox.documentation.schema.AlternateTypeRules.newRule;

@Configuration
@EnableSwagger2
@EnableSwagger2WebMvc
@Import({SpringDataRestConfiguration.class, BeanValidatorPluginsConfiguration.class})
public class SwaggerConfiguration {

Expand Down Expand Up @@ -85,12 +84,10 @@ public Docket propertyRegistryApi() {
}

private Predicate<String> getScanRestServicesPathPredicate() {
return Predicates.and(
Predicates.not(PathSelectors.regex("/actuator.*")), // Hide spring-actuator
Predicates.not(PathSelectors.regex("/error.*")), // Hide spring-data error
Predicates.not(PathSelectors.regex("/profile.*")),// Hide spring-data profile
Predicates.not(PathSelectors.regex("/users.*")) // Hide user-profile
);
return PathSelectors.regex(".*/actuator.*") // Hide spring-actuator
.or(PathSelectors.regex(".*/error.*")) // Hide spring-data error
.or(PathSelectors.regex(".*/profile.*")) // Hide spring-data profile
.or(PathSelectors.regex(".*/users.*")).negate(); // Hide users
}

private ApiInfo getApiInfo() {
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
spring.application.name=ampt2d-property-registry

# Bean jmx domain for actuator when using multiple applications with tomcat.
endpoints.jmx.domain=ampt2d-property-registry
spring.jmx.default-domain=ampt2d-property-registry

management.security.enabled=false

management.context-path=/actuator
management.endpoint.health.show-details=always
endpoints.health.sensitive=false

spring.datasource.url=@ampt2d-property-registry-db.url@
spring.datasource.username=@ampt2d-property-registry-db.username@
Expand All @@ -19,7 +15,6 @@ spring.jpa.generate-ddl=true

security.enabled=true
security.oauth2.resource.userInfoUri=https://www.googleapis.com/userinfo/v2/me
security.oauth2.resource.filter-order=3

spring.mail.host=@smtp-host@
spring.mail.port=587
Expand Down
14 changes: 4 additions & 10 deletions src/test/java/uk/ac/ebi/ampt2d/registry/OAuthHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package uk.ac.ebi.ampt2d.registry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.security.oauth2.resource.AuthoritiesExtractor;
import org.springframework.context.annotation.Bean;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
Expand All @@ -34,8 +34,6 @@
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;
import org.springframework.stereotype.Component;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
import uk.ac.ebi.ampt2d.registry.config.security.CustomAuthoritiesExtractor;
import uk.ac.ebi.ampt2d.registry.repositories.RegistryUserRepository;

import java.io.Serializable;
import java.util.Collection;
Expand All @@ -46,6 +44,7 @@

@Component
@EnableAuthorizationServer
@ConditionalOnProperty(name = "security.enabled", havingValue = "true")
public class OAuthHelper extends AuthorizationServerConfigurerAdapter {

@Autowired
Expand All @@ -55,7 +54,7 @@ public class OAuthHelper extends AuthorizationServerConfigurerAdapter {
private ClientDetailsService clientDetailsService;

@Autowired
private RegistryUserRepository registryUserRepository;
private AuthoritiesExtractor authoritiesExtractor;

public RequestPostProcessor bearerToken(final String clientid) {
return mockRequest -> {
Expand All @@ -69,7 +68,7 @@ private OAuth2AccessToken createAccessToken(final String clientId) {
ClientDetails client = clientDetailsService.loadClientByClientId(clientId);
Map<String, Object> clientEmailMap = new HashMap<>();
clientEmailMap.put("email", clientId);
Collection<GrantedAuthority> authorities = authoritiesExtractor(registryUserRepository).extractAuthorities(clientEmailMap);
Collection<GrantedAuthority> authorities = authoritiesExtractor.extractAuthorities(clientEmailMap);
Set<String> resourceIds = client.getResourceIds();
Set<String> scopes = client.getScope();

Expand Down Expand Up @@ -97,9 +96,4 @@ public void configure(final ClientDetailsServiceConfigurer clients) throws Excep
.withClient("testUser@gmail.com").and()
.withClient("testAdmin@gmail.com");
}

@Bean
public AuthoritiesExtractor authoritiesExtractor(RegistryUserRepository registryUserRepository) {
return new CustomAuthoritiesExtractor(registryUserRepository);
}
}
7 changes: 0 additions & 7 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
spring.application.name=ampt2d-property-registry

# Bean jmx domain for actuator when using multiple applications with tomcat.
endpoints.jmx.domain=ampt2d-property-registry
spring.jmx.default-domain=ampt2d-property-registry

management.security.enabled=false

management.context-path=/actuator
management.endpoint.health.show-details=always
endpoints.health.sensitive=false
registry.protocols=http

spring.jpa.hibernate.ddl-auto=create

spring.mail.port=587
spring.mail.test-connection=false
spring.mail.properties.mail.smtp.auth=false
spring.mail.properties.mail.smtp.ssl.enable=false

mail.from=user@domain
mail.to=user@domain
mail.subject=AMP-T2D Registry Update
Expand Down
5 changes: 5 additions & 0 deletions src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="root" level="INFO"/>
</configuration>