Commit a13d6d0f28e9b521888fc14e4fe50dc7989e4234
1 parent
b7ef4a2e
Fichier de configuration YAML
Un fichier YAML permet maintenant de définir un utilisateur admin (email et mot de passe) et d'établir la liste des noeuds et leurs informations. Sa présence est obligatoire.
Showing
14 changed files
with
239 additions
and
30 deletions
Show diff stats
... | ... | @@ -0,0 +1,15 @@ |
1 | +adminEmail: pfe@pfe.fr | |
2 | +adminPassword: pfepfe | |
3 | +nodes: | |
4 | + - name: AT-001 | |
5 | + ip: '85.10.201.246' | |
6 | + arch: ARM | |
7 | + - name: AT-002 | |
8 | + ip: '85.10.201.247' | |
9 | + arch: ARM | |
10 | + - name: AT-003 | |
11 | + ip: '85.10.201.248' | |
12 | + arch: ARM | |
13 | + - name: ATTTT-004 | |
14 | + ip: '85.10.201.249' | |
15 | + arch: ARM | |
0 | 16 | \ No newline at end of file | ... | ... |
29.3 KB
PFE06/pom.xml
... | ... | @@ -30,6 +30,11 @@ |
30 | 30 | <artifactId>spring-boot-starter-data-jpa</artifactId> |
31 | 31 | </dependency> |
32 | 32 | <dependency> |
33 | + <groupId>org.yaml</groupId> | |
34 | + <artifactId>snakeyaml</artifactId> | |
35 | + <version>1.21</version> | |
36 | + </dependency> | |
37 | + <dependency> | |
33 | 38 | <groupId>org.springframework.boot</groupId> |
34 | 39 | <artifactId>spring-boot-starter-web</artifactId> |
35 | 40 | </dependency> | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/AppConfig.java
0 → 100644
... | ... | @@ -0,0 +1,72 @@ |
1 | +package com.PFE.ServerManager; | |
2 | + | |
3 | +import org.springframework.beans.factory.annotation.Autowired; | |
4 | +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | |
5 | +import org.springframework.stereotype.Component; | |
6 | +import org.yaml.snakeyaml.TypeDescription; | |
7 | +import org.yaml.snakeyaml.Yaml; | |
8 | +import org.yaml.snakeyaml.constructor.Constructor; | |
9 | + | |
10 | +import javax.annotation.PostConstruct; | |
11 | +import java.io.*; | |
12 | +import java.util.*; | |
13 | + | |
14 | + | |
15 | +@Component | |
16 | +public class AppConfig { | |
17 | + | |
18 | + @Autowired | |
19 | + CustomerRepository customerRepository; | |
20 | + | |
21 | + @Autowired | |
22 | + RoleRepository roleRepository; | |
23 | + | |
24 | + @Autowired | |
25 | + MajRepository majRepository; | |
26 | + | |
27 | + @Autowired | |
28 | + BCryptPasswordEncoder bCryptPasswordEncoder; | |
29 | + | |
30 | + @Autowired | |
31 | + NodeRepository nodeRepository; | |
32 | + | |
33 | + @PostConstruct | |
34 | + public void init() { | |
35 | + System.out.println("============= Configuration de l'application ============="); | |
36 | + | |
37 | + Yaml yaml = new Yaml(new Constructor(ConfYAML.class)); | |
38 | + InputStream inputStream = null; | |
39 | + try { | |
40 | + inputStream = new FileInputStream(new File("app.conf")); | |
41 | + } catch (FileNotFoundException e) { | |
42 | + e.printStackTrace(); | |
43 | + } | |
44 | + ConfYAML conf = yaml.load(inputStream); | |
45 | + | |
46 | + Customer n = new Customer(); | |
47 | + n.setEmail(conf.getAdminEmail()); | |
48 | + n.setPassword(bCryptPasswordEncoder.encode(conf.getAdminPassword())); | |
49 | + n.setId((int)(customerRepository.count() + 1)); | |
50 | + n.setActive(1); | |
51 | + | |
52 | + Customer temp = customerRepository.findByEmail(conf.getAdminEmail()); | |
53 | + Role userRole = roleRepository.findByRole("ADMIN"); | |
54 | + n.setRoles(new HashSet<Role>(Arrays.asList(userRole))); | |
55 | + | |
56 | + if(temp == null) { | |
57 | + customerRepository.save(n); | |
58 | + } | |
59 | + | |
60 | + Iterator<NodeYAML> iter = conf.getNodes().iterator(); | |
61 | + while (iter.hasNext()) { | |
62 | + NodeYAML element = iter.next(); | |
63 | + Node node = new Node(); | |
64 | + node.setName(element.getName()); | |
65 | + node.setArch(element.getArch()); | |
66 | + node.setIp(element.getIp()); | |
67 | + node.setNode_id((int)(nodeRepository.count() + 1)); | |
68 | + nodeRepository.save(node); | |
69 | + } | |
70 | + | |
71 | + } | |
72 | +} | |
0 | 73 | \ No newline at end of file | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/ConfYAML.java
0 → 100644
... | ... | @@ -0,0 +1,35 @@ |
1 | +package com.PFE.ServerManager; | |
2 | + | |
3 | +import java.util.List; | |
4 | + | |
5 | +public class ConfYAML { | |
6 | + | |
7 | + private String adminEmail; | |
8 | + private String adminPassword; | |
9 | + private List<NodeYAML> nodes; | |
10 | + | |
11 | + public void setAdminEmail(String adminEmail) { | |
12 | + this.adminEmail = adminEmail; | |
13 | + } | |
14 | + | |
15 | + public void setAdminPassword(String adminPassword) { | |
16 | + this.adminPassword = adminPassword; | |
17 | + } | |
18 | + | |
19 | + public void setNodes(List<NodeYAML> nodes) { | |
20 | + this.nodes = nodes; | |
21 | + } | |
22 | + | |
23 | + public String getAdminEmail() { | |
24 | + return adminEmail; | |
25 | + } | |
26 | + | |
27 | + public String getAdminPassword() { | |
28 | + return adminPassword; | |
29 | + } | |
30 | + | |
31 | + public List<NodeYAML> getNodes() { | |
32 | + return nodes; | |
33 | + } | |
34 | + | |
35 | +} | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/CustomerRepository.java
... | ... | @@ -10,7 +10,5 @@ import org.springframework.stereotype.Repository; |
10 | 10 | //Need to check if "extends JpaRepository is more useful" |
11 | 11 | @Repository |
12 | 12 | public interface CustomerRepository extends JpaRepository<Customer, Integer> { |
13 | - | |
14 | 13 | Customer findByEmail(String email); |
15 | - | |
16 | 14 | } | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/MainController.java
... | ... | @@ -23,6 +23,9 @@ import javax.servlet.annotation.MultipartConfig; |
23 | 23 | public class MainController { |
24 | 24 | |
25 | 25 | @Autowired |
26 | + NodeRepository nodeRepository; | |
27 | + | |
28 | + @Autowired | |
26 | 29 | CustomerRepository customerRepository; |
27 | 30 | |
28 | 31 | @Autowired |
... | ... | @@ -69,6 +72,8 @@ public class MainController { |
69 | 72 | modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); |
70 | 73 | modelAndView.addObject("customerRole", customer.getRole()); |
71 | 74 | modelAndView.addObject("customerMaj", customer.getMaj()); |
75 | + List<Node> nodes = nodeRepository.findAll(); | |
76 | + modelAndView.addObject("nodes", nodes); | |
72 | 77 | |
73 | 78 | File file = new File("files"); |
74 | 79 | File[] dirs = file.listFiles(); | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/Node.java
0 → 100644
... | ... | @@ -0,0 +1,54 @@ |
1 | +package com.PFE.ServerManager; | |
2 | + | |
3 | +import javax.persistence.*; | |
4 | + | |
5 | +@Entity | |
6 | +@Table(name = "node") | |
7 | +public class Node { | |
8 | + @Id | |
9 | + @Column(name = "node_id", columnDefinition = "serial") | |
10 | + @GeneratedValue(strategy = GenerationType.AUTO) | |
11 | + private Integer node_id; | |
12 | + | |
13 | + @Column(name = "name") | |
14 | + private String name; | |
15 | + | |
16 | + @Column(name = "ip") | |
17 | + private String ip; | |
18 | + | |
19 | + @Column(name = "arch") | |
20 | + private String arch; | |
21 | + | |
22 | + public void setNode_id(Integer node_id) { | |
23 | + this.node_id = node_id; | |
24 | + } | |
25 | + | |
26 | + public void setName(String name) { | |
27 | + this.name = name; | |
28 | + } | |
29 | + | |
30 | + public void setIp(String ip) { | |
31 | + this.ip = ip; | |
32 | + } | |
33 | + | |
34 | + public void setArch(String arch) { | |
35 | + this.arch = arch; | |
36 | + } | |
37 | + | |
38 | + public Integer getNode_id() { | |
39 | + return node_id; | |
40 | + } | |
41 | + | |
42 | + public String getName() { | |
43 | + return name; | |
44 | + } | |
45 | + | |
46 | + public String getIp() { | |
47 | + return ip; | |
48 | + } | |
49 | + | |
50 | + public String getArch() { | |
51 | + return arch; | |
52 | + } | |
53 | + | |
54 | +} | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/NodeRepository.java
0 → 100644
PFE06/src/main/java/com/PFE/ServerManager/NodeYAML.java
0 → 100644
... | ... | @@ -0,0 +1,33 @@ |
1 | +package com.PFE.ServerManager; | |
2 | + | |
3 | +public class NodeYAML { | |
4 | + | |
5 | + private String name; | |
6 | + private String ip; | |
7 | + private String arch; | |
8 | + | |
9 | + public void setName(String name) { | |
10 | + this.name = name; | |
11 | + } | |
12 | + | |
13 | + public void setIp(String ip) { | |
14 | + this.ip = ip; | |
15 | + } | |
16 | + | |
17 | + public void setArch(String arch) { | |
18 | + this.arch = arch; | |
19 | + } | |
20 | + | |
21 | + public String getName() { | |
22 | + return name; | |
23 | + } | |
24 | + | |
25 | + public String getIp() { | |
26 | + return ip; | |
27 | + } | |
28 | + | |
29 | + public String getArch() { | |
30 | + return arch; | |
31 | + } | |
32 | + | |
33 | +} | ... | ... |
PFE06/src/main/resources/application.properties
... | ... | @@ -8,10 +8,12 @@ spring.jpa.hibernate.ddl-auto=create |
8 | 8 | #"update" met à jour la base données |
9 | 9 | |
10 | 10 | #Postgres config : |
11 | -spring.datasource.url=jdbc:postgresql://localhost:5432/sql_only | |
11 | +spring.datasource.url=jdbc:postgresql://localhost:3306/sql_only | |
12 | 12 | spring.datasource.username=postgres |
13 | -spring.datasource.password=glopglop | |
14 | - | |
13 | +spring.datasource.password=admin | |
14 | +#spring.datasource.url=jdbc:postgresql://localhost:5432/sql_only | |
15 | +#spring.datasource.username=postgres | |
16 | +#spring.datasource.password=glopglop | |
15 | 17 | |
16 | 18 | # montre les communications JPA avec la BDD |
17 | 19 | spring.jpa.show-sql = true | ... | ... |
PFE06/src/main/resources/data.sql
1 | 1 | /* ce fichier doit être placé dans les ressources afin d'être utilisé */ |
2 | -INSERT INTO "role" VALUES (1,'ADMIN'); | |
3 | -INSERT INTO "role" VALUES (2,'USER'); | |
4 | -INSERT INTO "customer" VALUES (1,1,'admin@admin.fr','$2a$10$GflhaD2IYuErynuOlxS2W.Gp1kXksVdiSviYN/lDYCsuH.lVm6Ph2'); /*pseudo : admin // password : admin // role : ADMIN*/ | |
5 | -INSERT INTO "customer_role" VALUES (1,1); | |
6 | -INSERT INTO "customer" VALUES (2,1,'user@user.fr','$2a$10$0Fnls/gTQS1zA6rj1ZlxfuyyKNpCBDA1tcCqQMroPDIj1fRyhgv/O'); /*pseudo : user // password : user // role : USER*/ | |
7 | -INSERT INTO "customer_role" VALUES (2,2); | |
8 | 2 | \ No newline at end of file |
3 | + | |
4 | +INSERT INTO "role" VALUES (1, 'ADMIN'); | |
5 | +INSERT INTO "role" VALUES (2, 'USER'); | |
9 | 6 | \ No newline at end of file | ... | ... |
No preview for this file type
PFE06/src/main/resources/templates/session.html
... | ... | @@ -61,25 +61,10 @@ |
61 | 61 | </tr> |
62 | 62 | </thead> |
63 | 63 | <tbody> |
64 | - <tr> | |
65 | - <td>AT-001</td> | |
66 | - <td>85.10.201.246</td> | |
67 | - <td>ARM</td> | |
68 | - </tr> | |
69 | - <tr> | |
70 | - <td>AT-002</td> | |
71 | - <td>85.10.201.245</td> | |
72 | - <td>ARM</td> | |
73 | - </tr> | |
74 | - <tr> | |
75 | - <td>AT-003</td> | |
76 | - <td>85.10.201.244</td> | |
77 | - <td>ARM</td> | |
78 | - </tr> | |
79 | - <tr> | |
80 | - <td>ST-002</td> | |
81 | - <td>85.10.201.243</td> | |
82 | - <td>ARM</td> | |
64 | + <tr th:each="node : ${nodes}"> | |
65 | + <td th:text="${node.getName()}">name</td> | |
66 | + <td th:text="${node.getIp()}">ip</td> | |
67 | + <td th:text="${node.getArch()}">arch</td> | |
83 | 68 | </tr> |
84 | 69 | </tbody> |
85 | 70 | </table> | ... | ... |