Qu'est-ce qu'un framework ?
$ git clone https://github.com/lolo101/formation-spring-boot-framework
Injection
Introspection
Proxy
> Java 8 <
Control - Enter
Unzip
cd
mvn package
java -jar target/demo-0.0.1-SNAPSHOT.jar
Pas très intéressant...
Jetons le starter web dans le POM pour voir
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
$ mvn package
$ java -jar target/demo-0.0.1-SNAPSHOT.jar
Exposons un web service
sous la forme d'un controller REST
@RestController
@RequestMapping("books")
public class Books {
@GetMapping
public String books() {
return "a list of books";
}
}
$ mvn package
$ java -jar target/demo-0.0.1-SNAPSHOT.jar
http://localhost:8080/books
Ajoutons un peu de sécurité
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
$ mvn package $ java -jar target/demo-0.0.1-SNAPSHOT.jar
Propriétés
- application.properties - application.yml
Exemple : LDAP embarqué (UnboundID)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-ldap</artifactId>
</dependency>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
Exemple : LDAP embarqué (UnboundID)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-ldap</artifactId>
</dependency>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
spring.ldap.embedded.base-dn=dc=example,dc=com
spring.ldap.embedded.port=8389
application.properties
spring.ldap.embedded.base-dn=dc=example,dc=com
spring.ldap.embedded.port=8389
application.properties
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication()
.userSearchFilter("(uid={0})")
.contextSource()
.url("ldap://localhost:8389/dc=example,dc=com");
}
}
Configuration de l'AuthenticationManager
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication()
.userSearchFilter("(uid={0})")
.contextSource()
.url("ldap://localhost:8389/dc=example,dc=com");
}
}
Configuration de l'AuthenticationManager
dn: dc=example,dc=com
dc: example
description: Serveur exemple
objectClass: dcObject
objectClass: organization
o: Serveur exemple
dn: ou=people, dc=example,dc=com
ou: people
objectClass: organizationalUnit
dn: uid=user,ou=people,dc=example,dc=com
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
uid: user
cn: Lucky
sn: Luke
userPassword: dwssap
mail: user@example.com
schema.ldif (https://gist.github.com/lolo101/)
dn: dc=example,dc=com
dc: example
description: Serveur exemple
objectClass: dcObject
objectClass: organization
o: Serveur exemple
dn: ou=people, dc=example,dc=com
ou: people
objectClass: organizationalUnit
dn: uid=user,ou=people,dc=example,dc=com
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
uid: user
cn: Lucky
sn: Luke
userPassword: dwssap
mail: user@example.com
$ mvn package $ java -jar target/demo-0.0.1-SNAPSHOT.jar
schema.ldif (https://gist.github.com/lolo101/)
Stateless service
$ git clone https://github.com/lolo101/formation-spring-boot-demo.git
Servlet Filter
https://jwt.io/
https://www.postman.com/
Interceptors
Exception handling
Actuator
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
$ mvn package $ java -jar target/demo-0.0.1-SNAPSHOT.jar
Monitoring
https://glowroot.org/
https://visualvm.github.io/
µ services
$ git clone https://github.com/lolo101/formation-spring-boot-cloud.git
$ mvn package $ java -jar say-hello/target/...jar $ java -jar user/target/...jar
F5 (x3)
µ services
ServicesRegistry
$ git checkout eureka
$ mvn clean package $ java -jar discovery/target/...jar $ java -jar say-hello/target/...jar $ java -jar user/target/...jar
http://localhost:8761
µ services
API Gateway
$ git checkout api-gateway
$ mvn package $ java -jar discovery/target/...jar $ java -jar say-hello/target/...jar $ java -jar user/target/...jar $ java -jar gateway/target/...jar
http://localhost:8080
µ services
Configuration centralisée