Skip to content
Snippets Groups Projects
Commit a7a5e1cc authored by KASMAMYTOV ELDAR p1712650's avatar KASMAMYTOV ELDAR p1712650 :computer:
Browse files

Merge branch 'TP1-ci' into TP1

parents b2be5d67 1d7b1f8e
No related branches found
No related tags found
No related merge requests found
# mif13-projet
Testing pipeline
\ No newline at end of file
......@@ -8,6 +8,8 @@
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<packaging>war</packaging>
<groupId>com.mif13</groupId>
<artifactId>auth-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
......@@ -15,13 +17,14 @@
<description>Projet de l&apos;UE MIF13. Serveur de l&apos;authentification.</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
......@@ -58,15 +61,21 @@
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>authServer</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
......
......@@ -2,9 +2,10 @@ package com.mif13.authServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
// extends SpringBootServletInitializer for .war generation
@SpringBootApplication
public class AuthServerApplication {
public class AuthServerApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(AuthServerApplication.class, args);
......
......@@ -3,12 +3,17 @@ package com.mif13.authServer.controllers;
import com.mif13.authServer.dao.UsersDao;
import com.mif13.authServer.model.User;
import com.mif13.authServer.utils.JwtHelper;
import java.io.Console;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.naming.AuthenticationException;
import javax.ws.rs.POST;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
......@@ -18,9 +23,10 @@ import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Controller
public class UserOperations {
......@@ -32,13 +38,14 @@ public class UserOperations {
this.usersRepo = usersRepo;
}
/**
* Procédure de login utilisée par un utilisateur
*
* @param login Le login de l'utilisateur. L'utilisateur doit avoir été créé préalablement et
* son login doit être présent dans le DAO.
* @param password Le password à vérifier.
* @return Une ResponseEntity avec le JWT dans le header "Authentication" si le login s'est bien
* @return Une ResponseEntity avec le JWT dans le header "Authorization" si le login s'est bien
* passé, et le code de statut approprié (204, 401 ou 404).
*/
@Operation(summary = "login utilisée par un utilisateur")
......@@ -63,6 +70,9 @@ public class UserOperations {
@RequestParam("password") String password, @RequestHeader("Origin") String origin) {
ResponseEntity<Void> response;
response = new ResponseEntity<>(HttpStatus.NO_CONTENT);
/*response.getHeaders().add("Access-Control-Expose-Headers", "Authorization");
response.getHeaders().add("Access-Control-Allow-Origin", origin);*/
String jwt;
Map<String, List<String>> headers = new HashMap<>();
......@@ -77,15 +87,15 @@ public class UserOperations {
jwt = JwtHelper.generateToken(login, origin);
if (!jwt.isEmpty()) {
// on ajoute un header Authentication avec comme valeur JWT
headers.put("Authentication", List.of(jwt));
// on ajoute un header Authorization avec comme valeur JWT
headers.put("Authorization", List.of(jwt));
} else {
throw new Exception("JWT is empty !");
}
} catch (Exception e) {
// on ajoute un header Authentication avec comme valeur LOGIN
headers.put("Authentication", List.of(login));
// on ajoute un header Authorization avec comme valeur LOGIN
headers.put("Authorization", List.of(login));
}
try {
......@@ -102,7 +112,7 @@ public class UserOperations {
}
} else {
// on ajoute un header Authentication avec comme valeur LOGIN
headers.put("Authentication", List.of(login));
headers.put("Authorization", List.of(login));
headersSpring = new MultiValueMapAdapter<>(headers);
response = new ResponseEntity<>(headersSpring, HttpStatus.NOT_FOUND);
}
......@@ -110,11 +120,7 @@ public class UserOperations {
return response;
}
/**
*
* @param login Le login de l'utilisateur.
* @return Une réponse vide avec un code de statut approprié (204, 400, 401).
*/
@Operation(summary = "Réalise la déconnexion.")
@ApiResponses(value = {
@ApiResponse(
......@@ -145,7 +151,6 @@ public class UserOperations {
if (user.isConnected()) {
user.disconnect();
response = new ResponseEntity<>(HttpStatus.NO_CONTENT);
} else {
throw new Exception("User is not connected !");
}
......@@ -155,15 +160,14 @@ public class UserOperations {
} catch (Exception e) {
e.printStackTrace();
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
}
return response;
}
/**
* .
*
* @param jwt Le token JWT qui se trouve dans le header "Authentication" de la requête
* @param jwt Le token JWT qui se trouve dans le header "Authorization" de la requête
* @param origin L'origine de la requête (pour la comparer avec celle du client, stockée dans le
* token JWT)
* @return Une réponse vide avec un code de statut approprié (204, 400, 401).
......@@ -181,8 +185,8 @@ public class UserOperations {
@GetMapping("/authenticate")
public ResponseEntity<Void> authenticate(@RequestParam("jwt") String jwt,
@RequestParam("origin") String origin) {
// TODO
ResponseEntity<Void> response = new ResponseEntity<>(HttpStatus.NO_CONTENT);
return response;
}
}
\ No newline at end of file
......@@ -16,6 +16,8 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses;
import java.util.Optional;
import java.util.regex.PatternSyntaxException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
......@@ -32,6 +34,13 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@RestController
@RequestMapping(value = "users")
......@@ -70,8 +79,8 @@ public class UserRestController {
}
)}
)
@GetMapping(value = "/{id}", produces = {MediaType.APPLICATION_JSON_VALUE,
MediaType.APPLICATION_XML_VALUE})
@GetMapping(value = "/{id}", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
//@CrossOrigin(origins = {"http://localhost", "http://192.168.75.68", "https://192.168.75.68"})
public ResponseEntity<User> getUserAsJsonOrXml(@PathVariable String id) {
Optional<User> optionalUser = usersRepo.get(id);
......@@ -147,13 +156,6 @@ public class UserRestController {
}
/**
* Cree un User a partir des parametres URL Encoded.
*
* @param login Login
* @param password Password
* @return contenu vide
*/
@Operation(summary = "Create a new user")
@ApiResponses(value = {
@ApiResponse(
......
......@@ -7,7 +7,6 @@ import java.util.regex.PatternSyntaxException;
import javax.naming.AuthenticationException;
public class User {
private final String login;
private String password;
......
package com.mif13.authServer.utils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig {
@Bean
public WebMvcConfigurer configure(){
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry){
// CORS for /login POST - CORS pas reglé
registry.addMapping("/login")
.allowedMethods("POST")
.allowedHeaders("*", "Authorization")
.allowedOrigins("http://localhost", "http://192.168.75.68", "https://192.168.75.68","https://localhost");
// CORS for /lougout POST - CORS pas reglé
registry.addMapping("/logout")
.allowedMethods("POST")
.allowedHeaders("*", "Authorization")
.allowedOrigins("http://localhost", "http://192.168.75.68", "https://192.168.75.68","https://localhost");
// CORS for /authenticate GET - Fonctionne
registry.addMapping("/authenticate")
.allowedMethods("GET")
.allowedHeaders("*")
.allowedOrigins("http://localhost", "http://192.168.75.68", "https://192.168.75.68","https://localhost");
// CORS for /users/{id} GET - Fonctionne
registry.addMapping("/{id}")
.allowedMethods("GET")
.allowedHeaders("*")
.allowedOrigins("http://localhost", "http://192.168.75.68", "https://192.168.75.68","https://localhost");
}
};
}
};
\ No newline at end of file
# Cache downloaded dependencies and plugins between builds.
# Not strictly necessary, but speeds up the builds.
cache:
key: "$CI_INTEGRATION_PIPELINE"
paths:
# Must be within the repository under test hence we can't use the
#default ~/.m2
- .m2/repository
variables:
# Use the cached directory above.
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
test-ci:
image: maven:3.6.1-jdk-11 # docker image with Maven
before_script:
- echo $CI_SSH_KEY
- ls -lah
- . ci/setup-mvn-proxy.sh
- chmod 400 $CI_SSH_KEY
script:
- ls /builds/p1712650/mif13-projet-gr02
- scp -o StrictHostKeyChecking=no -i $CI_SSH_KEY /builds/p1712650/mif13-projet-gr02/README.md gitlabci@192.168.75.68:~
deploy-auth-api:
image: maven:3.6.1-jdk-11 # docker image with Maven
variables:
Host: "gitlabci@192.168.75.68"
before_script:
- echo $CI_SSH_KEY
- ls -lah
- . ci/setup-mvn-proxy.sh
- chmod 400 $CI_SSH_KEY
script:
- cd ./auth-server/
- mvn clean package
- scp -o StrictHostKeyChecking=no -i $CI_SSH_KEY /builds/p1712650/mif13-projet-gr02/auth-server/target/authServer.war gitlabci@192.168.75.68:/opt/tomcat/webapps/authServer.war
#! /bin/sh
mkdir -p ~/.m2/
if [ -f ~/.m2/settings.xml ]; then
echo "File ~/.m2/settings.xml already exists. Please move it or remove it."
exit 1
fi
cat >~/.m2/settings.xml <<EOF
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<proxies>
EOF
NO_PROXY_MVN=$(printf '%s' "$NO_PROXY" | tr ',' '|')
for v in http_proxy FTP_PROXY ftp_proxy ALL_PROXY all_proxy HTTPS_PROXY https_proxy HTTP_PROXY
do
url=$(eval printf '%s' \$$v)
if [ -z "$url" ]; then
continue
fi
proto=${v%_*}
host=$(printf '%s' "$url" | sed 's/^.*:\/\/\([^:]*\):.*$/\1/g')
port=$(printf '%s' "$url" | sed 's/^.*:\/\/[^:]*:\(.*\)$/\1/g')
cat<<EOF >>~/.m2/settings.xml
<proxy>
<id>lyon1-$v</id>
<active>true</active>
<protocol>$proto</protocol>
<host>$host</host>
<port>$port</port>
<nonProxyHosts>$NO_PROXY_MVN</nonProxyHosts>
</proxy>
EOF
done
echo ' </proxies>' >>~/.m2/settings.xml
echo '</settings>' >>~/.m2/settings.xml
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment