Merge pull request 'Feature/Redirect_to_Files' (#9) from Feature/Redirect_to_Files into master

Reviewed-on: #9
pull/13/head
L_DelOff 2023-03-15 21:35:29 +03:00
commit 0f8f09ac2e
6 changed files with 33 additions and 11 deletions

View File

@ -1,7 +1,6 @@
package ru.ldeloff.hedgehogcloud.config; package ru.ldeloff.hedgehogcloud.config;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -9,17 +8,11 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.Set;
@Component @Component
public class AuthenticationSuccessUserHandler implements AuthenticationSuccessHandler { public class AuthenticationSuccessUserHandler implements AuthenticationSuccessHandler {
@Override @Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities()); response.sendRedirect("/files");
if (roles.contains("ROLE_ADMIN")) {
response.sendRedirect("/admin");
} else {
response.sendRedirect("/user");
}
} }
} }

View File

@ -49,8 +49,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/login").anonymous() .antMatchers("/login").anonymous()
.antMatchers("/").authenticated() .antMatchers("/").authenticated()
// защищенные URL // защищенные URL
.antMatchers("/admin/**").access("hasAnyRole('ROLE_ADMIN')") //.antMatchers("/admin/**").access("hasAnyRole('ROLE_ADMIN')")
.antMatchers("/user").permitAll() //.antMatchers("/files").permitAll()
.and().formLogin(); .and().formLogin();
} }

View File

@ -0,0 +1,15 @@
package ru.ldeloff.hedgehogcloud.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/files")
public class FilesController {
@GetMapping(value = "")
public String mainPage() {
return "files";
}
}

View File

@ -2,11 +2,13 @@ package ru.ldeloff.hedgehogcloud.controller;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller @Controller
@RequestMapping("/login")
public class LoginController { public class LoginController {
@GetMapping(value = "/login") @GetMapping(value = "")
public String loginPage() { public String loginPage() {
return "login"; return "login";
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 MiB

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Файлы</title>
<img src="img/gif.gif" alt=""/>
</head>
<body>
</body>
</html>