diff --git a/.gitignore b/.gitignore
index ad4f918..1ad7e35 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ target/
demo*/
.idea/dictionaries/
etunicorn.db
+.idea/dataSources
diff --git a/.idea/dataSources/0d8f27ad-8161-4ee1-8557-56db7fbf44cc/storage.xml b/.idea/dataSources/0d8f27ad-8161-4ee1-8557-56db7fbf44cc/storage.xml
deleted file mode 100644
index 6c5306d..0000000
--- a/.idea/dataSources/0d8f27ad-8161-4ee1-8557-56db7fbf44cc/storage.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/.idea/dataSources/a06fd1f6-5928-4430-a317-e5ebc0e00a82/storage.xml b/.idea/dataSources/a06fd1f6-5928-4430-a317-e5ebc0e00a82/storage.xml
deleted file mode 100644
index 6c5306d..0000000
--- a/.idea/dataSources/a06fd1f6-5928-4430-a317-e5ebc0e00a82/storage.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/.idea/dataSources/a88dec51-cb33-4875-a137-6d17703d6d6c/storage.xml b/.idea/dataSources/a88dec51-cb33-4875-a137-6d17703d6d6c/storage.xml
deleted file mode 100644
index 6c5306d..0000000
--- a/.idea/dataSources/a88dec51-cb33-4875-a137-6d17703d6d6c/storage.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/.idea/dataSources/ebfeef5a-f196-4340-9424-14e4e8aaadbb.xml b/.idea/dataSources/ebfeef5a-f196-4340-9424-14e4e8aaadbb.xml
deleted file mode 100644
index 1aad0f6..0000000
--- a/.idea/dataSources/ebfeef5a-f196-4340-9424-14e4e8aaadbb.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
- 1
- 1
-
-
-
- INTEGER(0,-1)|4
-
-
- 1
- VARCHAR(0,-1)|12
-
-
- 2
- VARCHAR(0,-1)|12
-
-
- 3
- TIMESTAMP(0,-1)|12
-
-
- id
- 1
-
-
-
\ No newline at end of file
diff --git a/.idea/dataSources/ebfeef5a-f196-4340-9424-14e4e8aaadbb/storage.xml b/.idea/dataSources/ebfeef5a-f196-4340-9424-14e4e8aaadbb/storage.xml
deleted file mode 100644
index 3d9a470..0000000
--- a/.idea/dataSources/ebfeef5a-f196-4340-9424-14e4e8aaadbb/storage.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/src/main/java/etunicorn/Application.java b/src/main/java/etunicorn/Application.java
index 1356403..bfd0d7f 100644
--- a/src/main/java/etunicorn/Application.java
+++ b/src/main/java/etunicorn/Application.java
@@ -8,6 +8,9 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import javax.sql.DataSource;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
/**
* etunicorn-server
@@ -23,17 +26,33 @@ public class Application {
}
@Bean
- public CommandLineRunner demo(PermissionRepository permissionRepository) {
+ public CommandLineRunner demo(PermissionRepository permissionRepository,
+ RoleRepository roleRepository,
+ PersonneRepository personneRepository,
+ SessionRepository sessionRepository) {
return (args) -> {
- permissionRepository.save(new Permission("ROLE_ADMIN"));
- permissionRepository.save(new Permission("CONSO_ADMIN"));
- permissionRepository.save(new Permission("EVNMT_ADMIN"));
+ permissionRepository.save(new Permission("PERSONNE_ADD"));
+ permissionRepository.save(new Permission("PERSONNE_EDIT"));
+ permissionRepository.save(new Permission("PERSONNE_GET"));
+ permissionRepository.save(new Permission("PERSONNE_LIST"));
+ permissionRepository.save(new Permission("PERSONNE_REMOVE"));
+ permissionRepository.save(new Permission("ROLE_ADD"));
+ permissionRepository.save(new Permission("ROLE_DELETE"));
+ permissionRepository.save(new Permission("ROLE_PERMISSION_ADD"));
+ permissionRepository.save(new Permission("ROLE_PERMISSION_LIST"));
+ permissionRepository.save(new Permission("ROLE_PERMISSION_REMOVE"));
// ...
+
+ roleRepository.save(new Role("admin", (List) permissionRepository.findAll()));
+ roleRepository.save(new Role("etudiant", new ArrayList<>()));
+ personneRepository.save(new Personne("carte", new Date(), "gbontoux", roleRepository.findByNom("admin")));
+ sessionRepository.save(new Session(personneRepository.findByLogin("gbontoux"), "A", new Date(new Date().getTime() + 1000 * 60 * 10)));
+
};
}
@Bean
- public DataSource dataSource(){
+ public DataSource dataSource() {
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.driverClassName("org.sqlite.JDBC");
dataSourceBuilder.url("jdbc:sqlite:etunicorn.db");
diff --git a/src/main/java/etunicorn/BaseController.java b/src/main/java/etunicorn/BaseController.java
new file mode 100644
index 0000000..b222de9
--- /dev/null
+++ b/src/main/java/etunicorn/BaseController.java
@@ -0,0 +1,36 @@
+package etunicorn;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * etunicorn-server
+ * Copyright © 2017 Le Club Info Polytech Lille
+ * Tous droits réservés
+ */
+@RestController
+public class BaseController {
+
+ // Permettent la vérification de permissions dans les méthodes de controlleur
+ @Autowired
+ private HttpServletRequest request;
+ @Autowired
+ private SessionService sessionService;
+ @Autowired
+ private PermissionRepository permissionRepository;
+
+ protected boolean hasPermission(Permission permission) {
+ Session session = sessionService.getSession(request);
+ if (session == null || permission == null) {
+ return false;
+ }
+ return session.hasPermission(permission);
+ }
+
+ protected boolean hasPermission(String nomPermission) {
+ Permission permission = permissionRepository.findByNom(nomPermission);
+ return hasPermission(permission);
+ }
+}
diff --git a/src/main/java/etunicorn/LoginController.java b/src/main/java/etunicorn/LoginController.java
index b64be71..4fd0009 100644
--- a/src/main/java/etunicorn/LoginController.java
+++ b/src/main/java/etunicorn/LoginController.java
@@ -7,8 +7,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
-import java.util.Date;
-
/**
* etunicorn-server
* Copyright © 2017 Le Club Info Polytech Lille
@@ -17,22 +15,27 @@ import java.util.Date;
@RestController
public class LoginController implements etunicorn.generated.LoginController {
@Autowired
- private PermissionRepository permissionRepository;
+ private PersonneRepository personneRepository;
+
+ @Autowired
+ private SessionService sessionService;
@Override
+ @RestrictedTo(authentifie = false)
public ResponseEntity> updateLogin(@RequestParam String login, @RequestParam String password) {
- // TODO C'est du debug !
- Role role = new Role();
- role.setNom("superman");
- for (Permission permission : permissionRepository.findAll()) {
- role.addPermission(permission);
+ Personne personne = personneRepository.findByLogin(login);
+ if (personne == null) {
+ return new ResponseEntity