Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make WebAuthenticationDetails constructor public #10830

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,24 @@ public class WebAuthenticationDetails implements Serializable {
* @param request that the authentication request was received from
*/
public WebAuthenticationDetails(HttpServletRequest request) {
this.remoteAddress = request.getRemoteAddr();
HttpSession session = request.getSession(false);
this.sessionId = (session != null) ? session.getId() : null;
this(request.getRemoteAddr(), extractSessionId(request));
}

/**
* Constructor to add Jackson2 serialize/deserialize support
* @param remoteAddress remote address of current request
* @param sessionId session id
*/
private WebAuthenticationDetails(final String remoteAddress, final String sessionId) {
public WebAuthenticationDetails(String remoteAddress, String sessionId) {
this.remoteAddress = remoteAddress;
this.sessionId = sessionId;
}

private static String extractSessionId(HttpServletRequest request) {
HttpSession session = request.getSession(false);
return (session != null) ? session.getId() : null;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof WebAuthenticationDetails) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ public void webAuthenticationDetailsSerializeTest() throws JsonProcessingExcepti
JSONAssert.assertEquals(AUTHENTICATION_DETAILS_JSON, actualJson, true);
}

@Test
public void webAuthenticationDetailsJackson2SerializeTest() throws JsonProcessingException, JSONException {
WebAuthenticationDetails details = new WebAuthenticationDetails("/localhost", "1");
String actualJson = this.mapper.writeValueAsString(details);
JSONAssert.assertEquals(AUTHENTICATION_DETAILS_JSON, actualJson, true);
}

@Test
public void webAuthenticationDetailsDeserializeTest() throws IOException {
WebAuthenticationDetails details = this.mapper.readValue(AUTHENTICATION_DETAILS_JSON,
Expand Down