Проброс на контроллеры и сами контроллеры
parent
4443dc16ae
commit
774f1f9354
|
@ -1,7 +1,6 @@
|
|||
package ru.ldeloff.hedgehogcloud.config;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
@ -9,17 +8,11 @@ import javax.servlet.ServletException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
@Component
|
||||
public class AuthenticationSuccessUserHandler implements AuthenticationSuccessHandler {
|
||||
@Override
|
||||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
|
||||
Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities());
|
||||
if (roles.contains("ROLE_ADMIN")) {
|
||||
response.sendRedirect("/admin");
|
||||
} else {
|
||||
response.sendRedirect("/user");
|
||||
}
|
||||
response.sendRedirect("/files");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||
.antMatchers("/login").anonymous()
|
||||
.antMatchers("/").authenticated()
|
||||
// защищенные URL
|
||||
.antMatchers("/admin/**").access("hasAnyRole('ROLE_ADMIN')")
|
||||
.antMatchers("/user").permitAll()
|
||||
//.antMatchers("/admin/**").access("hasAnyRole('ROLE_ADMIN')")
|
||||
//.antMatchers("/files").permitAll()
|
||||
.and().formLogin();
|
||||
}
|
||||
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -2,11 +2,13 @@ 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("/login")
|
||||
public class LoginController {
|
||||
|
||||
@GetMapping(value = "/login")
|
||||
@GetMapping(value = "")
|
||||
public String loginPage() {
|
||||
return "login";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue