diff options
author | 2018-02-06 14:36:37 +0300 | |
---|---|---|
committer | 2018-02-06 14:36:37 +0300 | |
commit | 19c8ed8a1d173ee16c5717d44b145ca365d2f6f5 (patch) | |
tree | 4a47347f2a98e2b65e62d89cea174e8e6af91fa3 /juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java | |
parent | 1d520f4d1bcfd78c21b7b542619cc828ff64dcb7 (diff) |
api server should authenticate in database for now
Diffstat (limited to 'juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java')
-rw-r--r-- | juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java b/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java deleted file mode 100644 index a2df26fc..00000000 --- a/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.juick.server.configuration; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.juick.server.component.JuickServerComponent; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Lazy; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.InterceptingClientHttpRequestFactory; -import org.springframework.http.client.support.BasicAuthorizationInterceptor; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.socket.client.WebSocketConnectionManager; -import org.springframework.web.socket.client.standard.StandardWebSocketClient; -import org.springframework.web.util.UriComponentsBuilder; - -import javax.inject.Inject; -import java.io.IOException; -import java.util.Collections; -import java.util.List; - -@Lazy -@Configuration -@EnableScheduling -public class JuickServerComponentConfiguration { - private static final Logger logger = LoggerFactory.getLogger(JuickServerComponentConfiguration.class); - @Value("${websocket_url:ws://localhost:8080/}") - private String baseUri; - @Value("${api_user:juick}") - private String serviceUser; - @Value("${api_password:secret}") - private String servicePassword; - @Inject - ObjectMapper jsonMapper; - @Inject - private JuickServerComponent juickServerComponent; - @Bean - public RestTemplate rest() { - RestTemplate rest = new RestTemplate(); - List<ClientHttpRequestInterceptor> interceptors = Collections.singletonList( - new BasicAuthorizationInterceptor(serviceUser, servicePassword)); - - rest.setRequestFactory(new InterceptingClientHttpRequestFactory(rest.getRequestFactory(), interceptors)); - return rest; - } - @Bean - public WebSocketConnectionManager connectionManager() { - String hash = StringUtils.EMPTY; - try { - ResponseEntity<String> response = rest().exchange("https://api.juick.com/auth", - HttpMethod.GET, null, String.class); - hash = jsonMapper.readValue(response.getBody(), String.class); - } catch (HttpClientErrorException | IOException e) { - logger.warn("service component is not authenticated", e); - } - String websocketURI = UriComponentsBuilder.fromUriString(baseUri) - .queryParam("hash", hash).build().toUriString(); - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), juickServerComponent, websocketURI); - manager.setAutoStartup(true); - return manager; - } - @Bean - public StandardWebSocketClient client() { - return new StandardWebSocketClient(); - } -} |