diff options
Diffstat (limited to 'juick-api/src')
-rw-r--r-- | juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java | 10 | ||||
-rw-r--r-- | juick-api/src/test/java/com/juick/api/tests/MessagesTests.java | 19 |
2 files changed, 18 insertions, 11 deletions
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 9f937c98..99731d2a 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 @@ -3,7 +3,8 @@ package com.juick.api.configuration; import com.juick.server.security.JuickAuthenticationEntryPoint; import com.juick.service.UserService; import com.juick.service.security.JuickUserDetailsService; -import com.juick.service.security.SimpleRememberMeServices; +import com.juick.service.security.deprecated.CookieSimpleHashRememberMeServices; +import com.juick.service.security.deprecated.RequestParamHashRememberMeServices; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; @@ -21,6 +22,7 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import javax.inject.Inject; import java.util.Arrays; +import java.util.Collections; import java.util.concurrent.TimeUnit; /** @@ -77,7 +79,7 @@ public class ApiSecurityConfig extends WebSecurityConfigurerAdapter { @Bean public RememberMeServices rememberMeServices() throws Exception { - return new SimpleRememberMeServices(env.getProperty("auth_remember_me_key"), userService, env); + return new RequestParamHashRememberMeServices(env.getProperty("auth_remember_me_key"), userService); } @Bean @@ -89,9 +91,9 @@ public class ApiSecurityConfig extends WebSecurityConfigurerAdapter { public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(Arrays.asList("*")); + configuration.setAllowedOrigins(Collections.singletonList("*")); configuration.setAllowedMethods(Arrays.asList("POST", "GET", "PUT", "OPTIONS", "DELETE")); - configuration.setAllowedHeaders(Arrays.asList("*")); + configuration.setAllowedHeaders(Collections.singletonList("*")); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); diff --git a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java index 33704fc5..05744a61 100644 --- a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java +++ b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java @@ -19,7 +19,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Primary; import org.springframework.http.MediaType; -import org.springframework.security.crypto.codec.Base64; import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -29,7 +28,6 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; import javax.inject.Inject; -import javax.servlet.http.Cookie; import java.util.*; import static org.hamcrest.Matchers.hasSize; @@ -158,6 +156,8 @@ public class MessagesTests { User user = getUser(1, ugnichName, uginchPassword); Message msg = getMessage(user, msgText); + when(userService.getUIDbyName(ugnichName)) + .thenReturn(1); when(userService.getUserByName(ugnichName)) .thenReturn(user); when(userService.getUserByUID(1)) @@ -171,12 +171,17 @@ public class MessagesTests { when(userService.getUIDbyHash(hash)) .thenReturn(1); - Cookie cookie = new Cookie("hash", new String(Base64.encode(hash.getBytes()))); - cookie.setDomain("juick.com"); - cookie.setMaxAge(100); - mockMvc.perform( - get("/home").cookie(cookie)) + get("/home") + .with(httpBasic(ugnichName, uginchPassword))) + .andExpect(status().isOk()) + .andReturn(); + + when(userService.getUserByHash(hash)) + .thenReturn(user); + + mockMvc.perform(get("/home") + .param("hash", hash)) .andExpect(status().isOk()); } |