Commit 3d8ba5a0 authored by jcorvi's avatar jcorvi
Browse files

rest api dockerization

parent b08113a3
FROM alpine:3.9
WORKDIR /usr/local/share/rest_api
ARG REST_API_VERSION=1.0
COPY docker-build.sh /usr/local/bin/docker-build.sh
COPY src src
COPY pom.xml .
RUN mkdir logs
RUN chmod u=rwx,g=rwx,o=r /usr/local/share/rest_api -R
RUN docker-build.sh ${REST_API_VERSION}
#!/bin/sh
BASEDIR=/usr/local
REST_API_HOME="${BASEDIR}/share/rest_api/"
REST_API_VERSION=1.0
# Exit on error
set -e
if [ $# -ge 1 ] ; then
REST_API_VERSION="$1"
fi
if [ -f /etc/alpine-release ] ; then
# Installing OpenJDK 8
apk add --update openjdk8-jre
# dict tagger development dependencies
apk add openjdk8 git maven
else
# Runtime dependencies
apt-get update
apt-get install openjdk-8-jre
# The development dependencies
apt-get install openjdk-8-jdk git maven
fi
mvn clean install -DskipTests
#rename jar
mv target/ades-rest-api-0.0.1-SNAPSHOT.jar ades-rest-api-${REST_API_VERSION}.jar
cat > /usr/local/bin/ades-rest-api <<EOF
#!/bin/sh
exec java \$JAVA_OPTS -jar "${ADES_RELATION_HOME}/ades-rest-api-${REST_API_VERSION}.jar" -workdir "${REST_API_HOME}" "\$@"
EOF
chmod +x /usr/local/bin/ades-rest-api
#delete target
rm -R target src pom.xml
#add bash for nextflow
apk add bash
if [ -f /etc/alpine-release ] ; then
# Removing not needed tools
apk del openjdk8 git maven
rm -rf /var/cache/apk/*
else
apt-get remove openjdk-8-jdk git maven
rm -rf /var/cache/dpkg
fi
......@@ -51,16 +51,32 @@
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
......
......@@ -6,7 +6,7 @@ import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan("es.bsc.inb.ades")
@ComponentScan("es.bsc.inb.ades.api")
public class App {
public static void main(String[] args) {
......
package es.bsc.inb.ades.rest.api.controllers;
import org.apache.catalina.filters.CorsFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
@Configuration
@EnableWebSecurity
public class CustomWebSecurityConfigurerAdapter<MyBasicAuthenticationEntryPoint> extends WebSecurityConfigurerAdapter {
@Autowired
private MyBasicAuthenticationEntryPoint authenticationEntryPoint;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user1").password(passwordEncoder().encode("user1Pass"))
.authorities("ROLE_USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/securityNone").permitAll()
.anyRequest().authenticated()
.and()
.httpBasic()
.authenticationEntryPoint((AuthenticationEntryPoint) authenticationEntryPoint);
http.addFilterAfter(new CorsFilter(),
BasicAuthenticationFilter.class);
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
......@@ -26,6 +26,12 @@ public class DocumentController {
public Document find(@PathVariable(value="id") Long id) {
return documentService.findByDocumentId(id);
}
// @RequestMapping("/documents/{id}")
// public Document find2(@PathVariable(value="id") Long id) {
// return documentService.findByDocumentId2(id);
// }
@RequestMapping("/documents/{id}/finding/{findingId}")
public String findFinding(@PathVariable(value="id") Long id, @PathVariable(value="findingId") Integer findingId) {
String snippet = documentService.findTextSnippetByDocumentIdAndFindingId(id, findingId);
......
......@@ -11,6 +11,8 @@ public interface DocumentService {
Document findByDocumentId(Long id);
Document findByDocumentId2(Long id);
String findTextSnippetByDocumentIdAndFindingId(Long id, Integer findingId);
String findTextSnippetByDocumentIdAndFindingId2(Long id, Integer findingId);
......
......@@ -34,6 +34,12 @@ public class DocumentServiceImpl implements DocumentService {
return documentRepository.findByDocumentId(id);
}
public Document findByDocumentId2(Long id) {
documentRepository.findByDocumentId(id);
return documentRepository.findByDocumentId(id);
}
static final Map<String, String> ANNOTATION_CLASS_STYLE = createMap();
@Override
......
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