Commit d8f3cb28 authored by Arthur.Pautrel's avatar Arthur.Pautrel
Browse files

TP14 finished

parent 253c6489
......@@ -26,6 +26,14 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......
package gic.i4gic.robotapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SecurityConfiguration {
public static void main(String[] args) {
SpringApplication.run(SecurityConfiguration.class, args);
}
}
......@@ -31,10 +31,4 @@ public class TaskController {
public String task5() {
return "task05";
}
// @GetMapping("/tp14/task2")
// public String index(Model model) {
// model.addAttribute("robot_name", "HelloRobot");
// return "task02";
// }
}
\ No newline at end of file
package gic.i4gic.robotapp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/css/**").permitAll()
.and()
.formLogin()
.loginPage("/tp14/task2")
.defaultSuccessUrl("/tp14/task5")
.permitAll()
.and()
.logout()
.permitAll()
.and().csrf().disable();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("Arthur").password("{noop}123456").roles("USER");
}
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="ISO-8859-1">
<title>Task 2</title>
......@@ -32,11 +34,12 @@
font-size: 15px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="login-form">
<form action="task5" method="POST">
<form th:action="@{/tp14/task5}" method="POST">
<h2 class="text-center">Log in</h2>
<div class="form-group">
<input name="username" type="text" class="form-control" placeholder="Username" required="required">
......@@ -46,8 +49,8 @@
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block">Log in</button>
</div>
</form>
</div>
</form>
<p class="text-center"><a href="task3">Create an Account</a></p>
</div>
</body>
......
<p>Failed to log in</p>
<style>
.p {
color: "red";
}
</style>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment