This commit is contained in:
Vedran Pavic
2019-07-02 19:23:00 +02:00
parent 1ca9daccb4
commit 8cb85618c2
8 changed files with 18 additions and 27 deletions

View File

@@ -56,8 +56,6 @@ public class SpringSessionRememberMeServices implements RememberMeServices, Logo
private int validitySeconds = THIRTY_DAYS_SECONDS;
private String sessionAttrToDeleteOnLoginFail = HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY;
@Override
public final Authentication autoLogin(HttpServletRequest request, HttpServletResponse response) {
return null;
@@ -131,7 +129,7 @@ public class SpringSessionRememberMeServices implements RememberMeServices, Logo
logger.debug("Interactive login attempt was unsuccessful.");
HttpSession session = request.getSession(false);
if (session != null) {
session.removeAttribute(this.sessionAttrToDeleteOnLoginFail);
session.removeAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
}
}

View File

@@ -210,7 +210,7 @@ public class DefaultCookieSerializer implements CookieSerializer {
for (int i = start; i < end; i++) {
char c = chars[i];
if (c < 0x21 || c == 0x22 || c == 0x2c || c == 0x3b || c == 0x5c || c == 0x7f) {
throw new IllegalArgumentException("Invalid character in cookie value: " + Integer.toString(c));
throw new IllegalArgumentException("Invalid character in cookie value: " + c);
}
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.session.web.http;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import javax.servlet.ServletOutputStream;
@@ -811,7 +812,7 @@ class OnCommittedResponseWrapperTests {
@Test
void contentLengthPrintWriterPrintlnStringCommits() throws Exception {
String x = "1";
this.response.setContentLength(String.valueOf(x).length());
this.response.setContentLength(x.length());
this.response.getWriter().println(x);
@@ -831,7 +832,7 @@ class OnCommittedResponseWrapperTests {
@Test
void contentLengthPrintWriterAppendCharSequenceCommits() throws Exception {
String x = "a";
this.response.setContentLength(String.valueOf(x).length());
this.response.setContentLength(x.length());
this.response.getWriter().append(x);
@@ -906,7 +907,7 @@ class OnCommittedResponseWrapperTests {
assertThat(this.committed).isFalse();
this.response.getOutputStream().write("1".getBytes("UTF-8"));
this.response.getOutputStream().write("1".getBytes(StandardCharsets.UTF_8));
assertThat(this.committed).isTrue();
}
@@ -1053,7 +1054,7 @@ class OnCommittedResponseWrapperTests {
@Test
void contentLengthOutputStreamPrintlnStringCommits() throws Exception {
String x = "1";
this.response.setContentLength(String.valueOf(x).length());
this.response.setContentLength(x.length());
this.response.getOutputStream().println(x);

View File

@@ -65,7 +65,7 @@ class RedisListenerContainerTaskExecutorITests extends AbstractRedisITests {
static class SessionTaskExecutor implements TaskExecutor {
private Object lock = new Object();
private final Object lock = new Object();
private final Executor executor;

View File

@@ -17,8 +17,8 @@
package sample.websocket;
import java.security.Principal;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import sample.data.ActiveWebSocketUser;
import sample.data.ActiveWebSocketUserRepository;
@@ -51,7 +51,7 @@ public class WebSocketConnectHandler<S> implements ApplicationListener<SessionCo
}
String id = SimpMessageHeaderAccessor.getSessionId(headers);
this.repository.save(new ActiveWebSocketUser(id, user.getName(), Calendar.getInstance()));
this.messagingTemplate.convertAndSend("/topic/friends/signin", Arrays.asList(user.getName()));
this.messagingTemplate.convertAndSend("/topic/friends/signin", Collections.singletonList(user.getName()));
}
}

View File

@@ -16,7 +16,7 @@
package sample.websocket;
import java.util.Arrays;
import java.util.Collections;
import sample.data.ActiveWebSocketUserRepository;
@@ -45,7 +45,8 @@ public class WebSocketDisconnectHandler<S> implements ApplicationListener<Sessio
}
this.repository.findById(id).ifPresent((user) -> {
this.repository.deleteById(id);
this.messagingTemplate.convertAndSend("/topic/friends/signout", Arrays.asList(user.getUsername()));
this.messagingTemplate.convertAndSend("/topic/friends/signout",
Collections.singletonList(user.getUsername()));
});
}

View File

@@ -16,8 +16,8 @@
package sample;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -58,7 +58,7 @@ class RestTests {
@Test
void unauthenticatedUserSentToLogInPage() {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
assertThatExceptionOfType(HttpClientErrorException.class)
.isThrownBy(() -> getForUser(this.baseUrl + "/", headers, String.class))
.satisfies((e) -> assertThat(e.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED));
@@ -85,7 +85,7 @@ class RestTests {
String token = entity.getHeaders().getFirst(X_AUTH_TOKEN);
HttpHeaders authTokenHeader = new HttpHeaders();
authTokenHeader.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
authTokenHeader.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
authTokenHeader.set(X_AUTH_TOKEN, token);
ResponseEntity<User> authTokenResponse = getForUser(this.baseUrl + "/", authTokenHeader, User.class);
assertThat(authTokenResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
@@ -113,7 +113,7 @@ class RestTests {
private HttpHeaders getHttpHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
return headers;
}

View File

@@ -71,21 +71,12 @@ public class Initializer implements ServletContextListener {
}
private static int getAvailablePort() {
ServerSocket socket = null;
try {
socket = new ServerSocket(0);
try (ServerSocket socket = new ServerSocket(0)) {
return socket.getLocalPort();
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
finally {
try {
socket.close();
}
catch (IOException ex) {
}
}
}
}