Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

Commit

Permalink
Reset state for client authorization request
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrandja committed Apr 21, 2022
1 parent ad62bd5 commit 3379a36
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.springframework.security.oauth2.client;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.security.oauth2.client.token.AccessTokenRequest;
import org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest;
Expand All @@ -25,7 +25,7 @@ public class DefaultOAuth2ClientContext implements OAuth2ClientContext, Serializ

private AccessTokenRequest accessTokenRequest;

private Map<String, Object> state = new HashMap<String, Object>();
private Map<String, Object> state = new ConcurrentHashMap<String, Object>();

public DefaultOAuth2ClientContext() {
this(new DefaultAccessTokenRequest());
Expand Down Expand Up @@ -54,6 +54,7 @@ public AccessTokenRequest getAccessTokenRequest() {
}

public void setPreservedState(String stateKey, Object preservedState) {
state.clear();
state.put(stateKey, preservedState);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.springframework.security.oauth2.client;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

public class DefaultOAuth2ClientContextTests {

@Test
public void resetsState() {
DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext();
clientContext.setPreservedState("state1", "some-state-1");
clientContext.setPreservedState("state2", "some-state-2");
clientContext.setPreservedState("state3", "some-state-3");
assertNull(clientContext.removePreservedState("state1"));
assertNull(clientContext.removePreservedState("state2"));
assertEquals("some-state-3", clientContext.removePreservedState("state3"));
}

}

0 comments on commit 3379a36

Please sign in to comment.