Skip to content
Snippets Groups Projects
Commit d91de48f authored by Hoai Viet Nguyen's avatar Hoai Viet Nguyen
Browse files

implement HTTP Basic Authentication

parent 26124796
No related branches found
No related tags found
No related merge requests found
......@@ -25,12 +25,15 @@ class SecurityConfig {
authorize(HttpMethod.GET,"/dashboard", hasAuthority("ROLE_USER"))
authorize("/user/tasks/**", hasAuthority("ROLE_USER"))
authorize(HttpMethod.POST, "/users", permitAll)
authorize("/api/v1/user/**",hasAuthority("ROLE_USER"))
}
formLogin {
permitAll()
defaultSuccessUrl("/dashboard",true)
}
httpBasic { }
}
return http.build()
......
......@@ -34,8 +34,8 @@ class TasksRestController (private val tasksService: TasksService, private val u
}
@GetMapping("/tasks")
fun getTasks(@PathVariable userId: UUID) : List<Task> {
val user = usersService.getUserById(userId)
fun getTasks(principal: Principal) : List<Task> {
val user = usersService.getUserByEmail(principal.name)
if(user != null) {
val tasks = tasksService.getAllByUser(user,true)
return tasks
......
......@@ -24,7 +24,7 @@
var task = {}
task.name = document.getElementById("name").value
task.open = document.getElementById("open").value
xhr.open("PUT","/api/v1/users/${task.user.id}/tasks/${task.id}")
xhr.open("PUT","/api/v1/user/tasks/${task.id}")
xhr.setRequestHeader("Content-Type", "application/json")
xhr.send(JSON.stringify(task))
xhr.onreadystatechange = function(){
......@@ -35,11 +35,11 @@
}
function deleteTask() {
xhr.open("DELETE","/api/v1/users/${task.user.id}/tasks/${task.id}")
xhr.open("DELETE","/api/v1/user/tasks/${task.id}")
xhr.send()
xhr.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 204){
window.location.href= "/users/${task.user.id}/tasks"
window.location.href= "/dashboard"
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment