/
ZufarFaiz
/
SberProject
Обзор
Документация
Войти
/
ZufarFaiz
/
SberProject
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/main/java/com/example/JobExchange_app/handler/RoleAuthSuccessHandler.java
28 строк
1 KB
Семейный
Добавил обработчики,упростил логику в контроллерах
01 июн 2025, 23:33
01 июн 2025, 23:33
6559e91
Код
Авторство
О чём код?
package com.example.JobExchange_app.handler; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.stereotype.Component; import java.io.IOException; @Component public class RoleAuthSuccessHandler implements AuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { String redirectUrl = switch (authentication.getAuthorities() .iterator().next().getAuthority()) { case "ROLE_APPLICANT" -> "/applicant/profile/"; case "ROLE_RECRUITER" -> "/recruiter/profile/"; default -> throw new IllegalStateException("Неизвестная роль"); }; response.sendRedirect(redirectUrl); } }