Commit 0b2d2ffd authored by Javi Corvi's avatar Javi Corvi
Browse files

new version oauth2 keycloak integration

parent 5f782789
Pipeline #26599 passed with stage
in 5 minutes and 8 seconds
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version> <version>2.5.0</version>
</parent> </parent>
<dependencies> <dependencies>
...@@ -29,11 +29,46 @@ ...@@ -29,11 +29,46 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency> -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
...@@ -46,16 +81,8 @@ ...@@ -46,16 +81,8 @@
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- <dependency> <!-- <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> <artifactId>spring-boot-starter-security</artifactId>
......
...@@ -20,7 +20,7 @@ import es.bsc.inb.ades.rest.api.services.DocumentService; ...@@ -20,7 +20,7 @@ import es.bsc.inb.ades.rest.api.services.DocumentService;
@RestController @RestController
@CrossOrigin() @CrossOrigin(origins="*")
public class DocumentController { public class DocumentController {
@Autowired @Autowired
......
...@@ -4,7 +4,7 @@ import org.springframework.web.bind.annotation.CrossOrigin; ...@@ -4,7 +4,7 @@ import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@CrossOrigin() @CrossOrigin("*")
@RestController @RestController
public class LivenessController { public class LivenessController {
...@@ -17,4 +17,9 @@ public class LivenessController { ...@@ -17,4 +17,9 @@ public class LivenessController {
public String readeness() { public String readeness() {
return "true"; return "true";
} }
@GetMapping(path = "/hello")
public String hello() {
return "holita";
}
} }
...@@ -33,8 +33,8 @@ public class DocumentRepositoryImpl implements DocumentRepositoryCustom{ ...@@ -33,8 +33,8 @@ public class DocumentRepositoryImpl implements DocumentRepositoryCustom{
query.fields().include("name"); query.fields().include("name");
query.fields().include("processDate"); query.fields().include("processDate");
query.fields().include("status"); query.fields().include("status");
Sort sort = new Sort(Sort.Direction.ASC, "name"); //Sort sort = new Sort(Sort.Direction.ASC, "name");
query.with(sort); //query.with(sort);
List<Document> documents = mongoTemplate.find(query, Document.class); List<Document> documents = mongoTemplate.find(query, Document.class);
return documents; return documents;
} }
......
...@@ -7,7 +7,7 @@ import org.springframework.security.config.annotation.authentication.builders.Au ...@@ -7,7 +7,7 @@ import org.springframework.security.config.annotation.authentication.builders.Au
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration //@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter { public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
......
package es.bsc.inb.ades.rest.api.security.pkce;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import ch.qos.logback.core.net.LoginAuthenticator;
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity httpSecurity) throws Exception {
// httpSecurity
// .authorizeRequests().antMatchers("/**")
// .authenticated()
// .and()
// .sessionManagement()
// .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
// .and()
// .cors()
// .and()
// .csrf()
// .disable()
// .oauth2ResourceServer()
// .jwt();
httpSecurity
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/documents").permitAll()
.anyRequest().authenticated()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
//.formLogin()
//.and()
.cors()
.and()
.csrf()
.disable()
.oauth2ResourceServer()
.jwt();
//
// httpSecurity
// .authorizeRequests(authz -> authz
// .antMatchers(HttpMethod.GET, "/**").hasAuthority("SCOPE_read")
// .antMatchers(HttpMethod.POST, "/**").hasAuthority("SCOPE_write")
// .anyRequest().authenticated())
// .oauth2ResourceServer(oauth2 -> oauth2.jwt());
}
}
...@@ -251,10 +251,12 @@ public class DocumentServiceImpl implements DocumentService { ...@@ -251,10 +251,12 @@ public class DocumentServiceImpl implements DocumentService {
public String findFindingEvidenceByDocumentIdAndFindingId(Long id, Integer findingId) { public String findFindingEvidenceByDocumentIdAndFindingId(Long id, Integer findingId) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id); DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Finding findingSelected = null; Finding findingSelected = null;
Annotation sentenceRelevantText = null;
for (Annotation annotation : documentAnnotations.getRelevantSentences()) { for (Annotation annotation : documentAnnotations.getRelevantSentences()) {
for (Finding finding : annotation.getFindings()) { for (Finding finding : annotation.getFindings()) {
if(finding.getFindingId().equals(findingId)) { if(finding.getFindingId().equals(findingId)) {
findingSelected = finding; findingSelected = finding;
sentenceRelevantText = annotation;
break; break;
} }
} }
...@@ -276,7 +278,10 @@ public class DocumentServiceImpl implements DocumentService { ...@@ -276,7 +278,10 @@ public class DocumentServiceImpl implements DocumentService {
// annotation.setStartOffset(start_off + Constants.POINTS_INT); // annotation.setStartOffset(start_off + Constants.POINTS_INT);
// annotation.setEndOffset(start_off + Constants.POINTS_INT + text_size); // annotation.setEndOffset(start_off + Constants.POINTS_INT + text_size);
// return this.generateFindingSnippet3(subtext, findingSelected, start_annotation_aux); // return this.generateFindingSnippet3(subtext, findingSelected, start_annotation_aux);
Annotation annotation = findingSelected.getRelevant_text();
//I removed relevant text as atribute so ...
//Annotation annotation = findingSelected.getRelevant_text();
Annotation annotation = sentenceRelevantText;
int text_size = annotation.getEndOffset() - annotation.getStartOffset(); int text_size = annotation.getEndOffset() - annotation.getStartOffset();
int start_ = 0; int start_ = 0;
int start_off = 0; int start_off = 0;
......
...@@ -4,4 +4,5 @@ server.servlet.context-path=/pretoxapi ...@@ -4,4 +4,5 @@ server.servlet.context-path=/pretoxapi
server.port = ${SERVER_PORT} server.port = ${SERVER_PORT}
#PRETOX Database #PRETOX Database
spring.data.mongodb.uri=${MONGO_URI} spring.data.mongodb.uri=${MONGO_URI}
#KEYCLOCK configuration
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=${OAUTH2_RS_CERTS}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment