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

Fix IllegalArgumentException when scope is a String instead of a collect... #266

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -68,7 +68,7 @@ private Collection<? extends GrantedAuthority> getAuthorities(Map<String, ?> map
}
Object authorities = map.get(AUTHORITIES);
if (authorities instanceof String) {
AuthorityUtils.commaSeparatedStringToAuthorityList((String) authorities);
return AuthorityUtils.commaSeparatedStringToAuthorityList((String) authorities);
}
if (authorities instanceof Collection) {
return AuthorityUtils.commaSeparatedStringToAuthorityList(StringUtils
Expand Down
@@ -0,0 +1,51 @@
package org.springframework.security.oauth2.provider.token;

import org.junit.Test;
import org.springframework.security.core.Authentication;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

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

/**
* Created with IntelliJ IDEA.
* User: saket
* Date: 29/09/2014
* Time: 16:25
* To change this template use File | Settings | File Templates.
*/

public class DefaultUserAuthenticationConverterTests {
private UserAuthenticationConverter converter = new DefaultUserAuthenticationConverter();

@Test
public void shouldExtractAuthenticationWhenAuthoritiesIsCollection() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put(UserAuthenticationConverter.USERNAME, "test_user");
ArrayList<String> lists = new ArrayList<String>();
lists.add("a1");
lists.add("a2");
map.put(UserAuthenticationConverter.AUTHORITIES, lists);

Authentication authentication = converter.extractAuthentication(map);

assertNotEquals(authentication.getAuthorities(), null);
assertEquals(authentication.getAuthorities().size(), 2);
}

@Test
public void shouldExtractAuthenticationWhenAuthoritiesIsString() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put(UserAuthenticationConverter.USERNAME, "test_user");
map.put(UserAuthenticationConverter.AUTHORITIES, "a1,a2");

Authentication authentication = converter.extractAuthentication(map);

assertNotEquals(authentication.getAuthorities(), null);
assertEquals(authentication.getAuthorities().size(), 2);
}
}