DefaultOAuth2User is Serializable

Fixes gh-4917
This commit is contained in:
Joe Grandja 2017-12-19 09:07:17 -05:00
parent 9f6af4f3b8
commit 268a1dc06e
2 changed files with 10 additions and 1 deletions

View File

@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
@ -58,7 +59,7 @@ public class DefaultOAuth2User implements OAuth2User, Serializable {
if (!attributes.containsKey(nameAttributeKey)) {
throw new IllegalArgumentException("Missing attribute '" + nameAttributeKey + "' in attributes");
}
this.authorities = Collections.unmodifiableSet(this.sortAuthorities(authorities));
this.authorities = Collections.unmodifiableSet(new LinkedHashSet<>(this.sortAuthorities(authorities)));
this.attributes = Collections.unmodifiableMap(new LinkedHashMap<>(attributes));
this.nameAttributeKey = nameAttributeKey;
}

View File

@ -19,6 +19,7 @@ package org.springframework.security.oauth2.core.user;
import org.junit.Test;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.util.SerializationUtils;
import java.util.Collections;
import java.util.Map;
@ -79,4 +80,11 @@ public class DefaultOAuth2UserTests {
assertThat(user.getAuthorities().iterator().next()).isEqualTo(AUTHORITY);
assertThat(user.getAttributes()).containsOnlyKeys(ATTRIBUTE_NAME_KEY);
}
// gh-4917
@Test
public void constructorWhenCreatedThenIsSerializable() {
DefaultOAuth2User user = new DefaultOAuth2User(AUTHORITIES, ATTRIBUTES, ATTRIBUTE_NAME_KEY);
SerializationUtils.serialize(user);
}
}