.
This commit is contained in:
parent
3e5ca28b21
commit
f968c21992
7 changed files with 165 additions and 4 deletions
|
|
@ -4,9 +4,9 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>backend-api</artifactId>
|
<artifactId>backend-api</artifactId>
|
||||||
<name>Clearing Frontend API</name>
|
<name>Clearing Backend API</name>
|
||||||
<description>Clearing frontend API module</description>
|
<description>Clearing backend API module</description>
|
||||||
<packaging>war</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>clearing-parent</artifactId>
|
<artifactId>clearing-parent</artifactId>
|
||||||
|
|
@ -55,8 +55,13 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
|
<addClasspath>true</addClasspath>
|
||||||
|
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||||
<mainClass>ru.spcex.clearing.backendapi.BackendApiApplication</mainClass>
|
<mainClass>ru.spcex.clearing.backendapi.BackendApiApplication</mainClass>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
<manifestEntries>
|
||||||
|
<Built-By>Maven</Built-By>
|
||||||
|
</manifestEntries>
|
||||||
</archive>
|
</archive>
|
||||||
<webResources>
|
<webResources>
|
||||||
<resource>
|
<resource>
|
||||||
|
|
@ -82,6 +87,26 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<!-- <execution>-->
|
||||||
|
<!-- <id>gather-build-info-web</id>-->
|
||||||
|
<!-- <goals>-->
|
||||||
|
<!-- <goal>build-info</goal>-->
|
||||||
|
<!-- </goals>-->
|
||||||
|
<!-- </execution>-->
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package ru.spcex.clearing.backendapi.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RestTemplateConfig {
|
||||||
|
private final RestTemplateBuilder builder;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public RestTemplateConfig(RestTemplateBuilder builder) {
|
||||||
|
this.builder = builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* В настоящий момент используется для выгрузки AFS данных
|
||||||
|
*/
|
||||||
|
@Bean("clearing-rest")
|
||||||
|
public RestTemplate restTemplate() {
|
||||||
|
return builder
|
||||||
|
.setConnectTimeout(Duration.ofMillis(10000))
|
||||||
|
.setReadTimeout(Duration.ofMillis(40000))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package ru.spcex.clearing.backendapi.controller;
|
||||||
|
|
||||||
|
import org.keycloak.KeycloakSecurityContext;
|
||||||
|
import org.keycloak.adapters.RefreshableKeycloakSecurityContext;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import ru.spcex.clearing.backendapi.security.TokenRequest;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/backend-api-login")
|
||||||
|
public class LoginController {
|
||||||
|
private final RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public LoginController(@Qualifier("clearing-rest") RestTemplate restTemplate) {
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/perform-login", method = RequestMethod.POST)
|
||||||
|
public ResponseEntity<Map<String, Object>> refreshToken(HttpServletRequest httpServletRequest,
|
||||||
|
HttpServletResponse httpServletResponse) {
|
||||||
|
RefreshableKeycloakSecurityContext session = (RefreshableKeycloakSecurityContext) httpServletRequest.getSession().getAttribute(KeycloakSecurityContext.class.getName());
|
||||||
|
String login = httpServletRequest.getHeader("clearing-login");
|
||||||
|
String password = httpServletRequest.getHeader("clearing-password");
|
||||||
|
HttpEntity<MultiValueMap<String, String>> request =
|
||||||
|
new TokenRequest.Builder()
|
||||||
|
.username(login)
|
||||||
|
.password(password)
|
||||||
|
.build();
|
||||||
|
ResponseEntity<String> response = restTemplate.postForEntity(
|
||||||
|
"http://10.200.200.147:8080/realms/master/protocol/openid-connect/token",
|
||||||
|
request, String.class);
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package ru.spcex.clearing.backendapi.security;
|
||||||
|
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SimpleUserDetailService
|
||||||
|
// implements UserDetailsService
|
||||||
|
{
|
||||||
|
// @Override
|
||||||
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package ru.spcex.clearing.backendapi.security;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
public class TokenRequest {
|
||||||
|
public static class Builder{
|
||||||
|
MultiValueMap<String, String> data;
|
||||||
|
public Builder(){
|
||||||
|
data = new LinkedMultiValueMap<>();
|
||||||
|
data.put("client_id", Collections.singletonList("clearing"));
|
||||||
|
data.put("grant_type", Collections.singletonList("password"));
|
||||||
|
data.put("client_secret", Collections.singletonList("WnOVCxcAmrUYc8IjiFHOuRif5Oesoyfr"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Builder username(String username){
|
||||||
|
data.put("username", Collections.singletonList(username));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public Builder password(String password){
|
||||||
|
data.put("password", Collections.singletonList(password));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public HttpEntity<MultiValueMap<String, String>> build(){
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
return new HttpEntity<>(data, headers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private TokenRequest(){
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -44,10 +44,15 @@ public class WebSecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
super.configure(http);
|
super.configure(http);
|
||||||
http
|
http
|
||||||
|
// .formLogin()
|
||||||
|
// .loginProcessingUrl("/backend-api-login/perform-login")
|
||||||
|
// .and()
|
||||||
|
.csrf().disable()
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.antMatchers("/anonymous/**").permitAll()
|
.antMatchers("/anonymous/**").permitAll()
|
||||||
.antMatchers("/sso/login").permitAll()
|
.antMatchers("/sso/login").permitAll()
|
||||||
.antMatchers("/error").permitAll()
|
.antMatchers("/error").permitAll()
|
||||||
|
.antMatchers("/backend-api-login/**").permitAll()
|
||||||
.anyRequest().hasAnyRole("admin");
|
.anyRequest().hasAnyRole("admin");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
"cors-max-age" : 1000,
|
"cors-max-age" : 1000,
|
||||||
"cors-allowed-methods" : "POST, PUT, DELETE, GET",
|
"cors-allowed-methods" : "POST, PUT, DELETE, GET",
|
||||||
"cors-exposed-headers" : "WWW-Authenticate, My-custom-exposed-Header",
|
"cors-exposed-headers" : "WWW-Authenticate, My-custom-exposed-Header",
|
||||||
"bearer-only" : false,
|
"bearer-only" : true,
|
||||||
"enable-basic-auth" : false,
|
"enable-basic-auth" : false,
|
||||||
"expose-token" : false,
|
"expose-token" : false,
|
||||||
"verify-token-audience" : true,
|
"verify-token-audience" : true,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue