Application.java
3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package etunicorn;
import etunicorn.entity.Permission;
import etunicorn.entity.Personne;
import etunicorn.entity.Role;
import etunicorn.entity.Session;
import etunicorn.repository.PermissionRepository;
import etunicorn.repository.PersonneRepository;
import etunicorn.repository.RoleRepository;
import etunicorn.repository.SessionRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* etunicorn-server
* Copyright © 2017 Le Club Info Polytech Lille
* Tous droits réservés
*/
@Configuration
@SpringBootApplication
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public CommandLineRunner demo(PermissionRepository permissionRepository,
RoleRepository roleRepository,
PersonneRepository personneRepository,
SessionRepository sessionRepository) {
return (args) -> {
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("PERSONNE_ROLE"));
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<Permission>) 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() {
// DriverManagerDataSource dataSource = new DriverManagerDataSource();
// dataSource.setDriverClassName("com.mysql.jdbc.Driver");
// dataSource.setUrl("jdbc:mysql://localhost/etunicorn");
// dataSource.setUsername("etunicorn");
// dataSource.setPassword("etunicorn");
// return dataSource;
// }
// Properties additionalProperties() {
// Properties properties = new Properties();
// properties.setProperty("spring.jpa.hibernale.ddl-auto", "create-drop");
// properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
// return properties;
// }
}