SUPPORT-8427: Fix

This commit is contained in:
Eduard Tihomirov 2024-09-04 17:50:49 +03:00
parent dd6f0f618b
commit 48c4dee0ee
2 changed files with 15 additions and 0 deletions

View file

@ -27,6 +27,8 @@ import esia.model.EsiaTokenResponse;
import esia.model.OrganizationModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.stereotype.Service;
import ru.micord.security.JwtTokenServiceImpl;
import ru.micord.security.Token;
@ -51,6 +53,9 @@ public class EsiaAuthService {
@Autowired
private JwtTokenServiceImpl jwtTokenService;
@Autowired
private AuthenticationManager authenticationManager;
public String generateAuthCodeUrl() {
try {
String clientId = esiaConfig.getClientId();
@ -197,6 +202,7 @@ public class EsiaAuthService {
Cookie isAuthToken = new Cookie("auth_token", token.getValue());
isAuthToken.setPath("/");
response.addCookie(isAuthToken);
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(esiaAccessToken.getSbj_id(), null));
return true;
}
catch (Exception e) {
@ -278,6 +284,7 @@ public class EsiaAuthService {
Cookie isAuthToken = new Cookie("auth_token", token.getValue());
isAuthToken.setPath("/");
response.addCookie(isAuthToken);
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(esiaAccessToken.getSbj_id(), null));
}
catch (Exception e) {
throw new RuntimeException(e);

View file

@ -1,7 +1,9 @@
package ru.micord.security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
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;
@ -36,4 +38,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
public AuthenticationEntryPoint entryPoint() {
return new UnauthorizedEntryPoint();
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}