diff options
Diffstat (limited to 'juick-api/src/main/java/com/juick/api/configuration')
5 files changed, 55 insertions, 20 deletions
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java index 382b3df5..e987893d 100644 --- a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java +++ b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java @@ -3,7 +3,9 @@ package com.juick.api.configuration; import com.juick.api.ApiServer; import com.juick.api.MessengerBot; import com.juick.api.TGBot; +import com.pengrad.telegrambot.TelegramBot; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; @@ -22,30 +24,18 @@ import javax.inject.Inject; @PropertySource("classpath:juick.conf") public class ApiAppConfiguration { @Inject - private Environment env; + TGBot tgBot; @Bean public ApiServer apiServer() { - return new ApiServer(env); - } - - @Bean - public TGBot tgBot() { - return new TGBot(env.getProperty("telegram_token", StringUtils.EMPTY)); - } - - @Bean - public MessengerBot fbBot() { - MessengerBot bot = new MessengerBot(); - bot.setVerifyToken(env.getProperty("fb_verify_token", StringUtils.EMPTY)); - return bot; + return new ApiServer(); } private static final String WS_URI = "wss://ws.juick.com/"; @Bean public WebSocketConnectionManager connectionManager() { - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), tgBot(), WS_URI); + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), tgBot, WS_URI); manager.setAutoStartup(true); return manager; } diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java index 41fe8b2d..bc97d587 100644 --- a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java +++ b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java @@ -14,7 +14,10 @@ public class ApiInitializer extends AbstractAnnotationConfigDispatcherServletIni @Override protected Class<?>[] getRootConfigClasses() { - return new Class<?>[]{ApiAppConfiguration.class, ApiSecurityConfig.class, DataConfiguration.class}; + return new Class<?>[]{ + ApiAppConfiguration.class, ApiSecurityConfig.class, DataConfiguration.class, + TelegramConfiguration.class, MessengerConfiguration.class + }; } @Override diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java b/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java index cb50ddab..f1dcf30a 100644 --- a/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java +++ b/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java @@ -4,6 +4,7 @@ import com.juick.server.security.NotAuthorizedAuthenticationEntryPoint; import com.juick.service.UserService; import com.juick.service.security.JuickUserDetailsService; import com.juick.service.security.deprecated.RequestParamHashRememberMeServices; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; @@ -31,8 +32,8 @@ import java.util.concurrent.TimeUnit; @EnableWebSecurity @PropertySource("classpath:juick.conf") public class ApiSecurityConfig extends WebSecurityConfigurerAdapter { - @Inject - private Environment env; + @Value("${auth_remember_me_key}") + private String rememberMeKey; @Inject private UserService userService; @@ -58,7 +59,7 @@ public class ApiSecurityConfig extends WebSecurityConfigurerAdapter { .alwaysRemember(true) .tokenValiditySeconds((int) TimeUnit.DAYS.toSeconds(6 * 30)) .rememberMeServices(rememberMeServices()) - .key(env.getProperty("auth_remember_me_key")) + .key(rememberMeKey) .and().authenticationProvider(authenticationProvider()) .headers().defaultsDisabled().cacheControl(); } @@ -79,7 +80,7 @@ public class ApiSecurityConfig extends WebSecurityConfigurerAdapter { @Bean public RememberMeServices rememberMeServices() throws Exception { - return new RequestParamHashRememberMeServices(env.getProperty("auth_remember_me_key"), userService); + return new RequestParamHashRememberMeServices(rememberMeKey, userService); } @Bean diff --git a/juick-api/src/main/java/com/juick/api/configuration/MessengerConfiguration.java b/juick-api/src/main/java/com/juick/api/configuration/MessengerConfiguration.java new file mode 100644 index 00000000..c3c8f3e6 --- /dev/null +++ b/juick-api/src/main/java/com/juick/api/configuration/MessengerConfiguration.java @@ -0,0 +1,22 @@ +package com.juick.api.configuration; + +import com.juick.api.MessengerBot; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Created by vital on 28.03.2017. + */ +@Configuration +public class MessengerConfiguration { + @Value("${fb_verify_token}") + private String messengerBotVerifyToken; + + @Bean + public MessengerBot fbBot() { + MessengerBot bot = new MessengerBot(); + bot.setVerifyToken(messengerBotVerifyToken); + return bot; + } +} diff --git a/juick-api/src/main/java/com/juick/api/configuration/TelegramConfiguration.java b/juick-api/src/main/java/com/juick/api/configuration/TelegramConfiguration.java new file mode 100644 index 00000000..03dec4e9 --- /dev/null +++ b/juick-api/src/main/java/com/juick/api/configuration/TelegramConfiguration.java @@ -0,0 +1,19 @@ +package com.juick.api.configuration; + +import com.juick.api.TGBot; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Created by vital on 28.03.2017. + */ +@Configuration +public class TelegramConfiguration { + @Value("${telegram_token}") + private String telegramToken; + @Bean + public TGBot tgBot() { + return new TGBot(telegramToken); + } +} |