This commit is contained in:
Phillip Webb 2015-10-09 17:08:28 -07:00
parent 13d9601799
commit 877e6e034c
6 changed files with 16 additions and 13 deletions

View File

@ -32,7 +32,6 @@ public interface AuthoritiesExtractor {
/**
* Extract the authorities from the resource server's response.
*
* @param map the response
* @return the extracted authorities
*/

View File

@ -41,19 +41,19 @@ public class FixedAuthoritiesExtractor implements AuthoritiesExtractor {
public List<GrantedAuthority> extractAuthorities(Map<String, Object> map) {
String authorities = "ROLE_USER";
if (map.containsKey(AUTHORITIES)) {
Object object = map.get(AUTHORITIES);
if (object instanceof Collection) {
authorities = StringUtils
.collectionToCommaDelimitedString((Collection<?>) object);
}
else if (ObjectUtils.isArray(object)) {
authorities = StringUtils.arrayToCommaDelimitedString((Object[]) object);
}
else if (object != null) {
authorities = object.toString();
}
authorities = asAuthorities(map.get(AUTHORITIES));
}
return AuthorityUtils.commaSeparatedStringToAuthorityList(authorities);
}
private String asAuthorities(Object object) {
if (object instanceof Collection) {
return StringUtils.collectionToCommaDelimitedString((Collection<?>) object);
}
if (ObjectUtils.isArray(object)) {
return StringUtils.arrayToCommaDelimitedString((Object[]) object);
}
return object.toString();
}
}

View File

@ -25,6 +25,8 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Tests for {@link FixedAuthoritiesExtractor}.
*
* @author Dave Syer
*/
public class FixedAuthoritiesExtractorTests {

View File

@ -204,8 +204,10 @@ public class ResourceServerTokenServicesConfigurationTests {
return AuthorityUtils
.commaSeparatedStringToAuthorityList("ROLE_ADMIN");
}
};
}
}
@Import({ OAuth2RestOperationsConfiguration.class })

View File

@ -96,7 +96,6 @@ public abstract class LoggingSystem {
* Returns a {@link Runnable} that can handle shutdown of this logging system when the
* JVM exits. The default implementation returns {@code null}, indicating that no
* shutdown is required.
*
* @return the shutdown handler, or {@code null}
*/
public Runnable getShutdownHandler() {

View File

@ -414,4 +414,5 @@ public class LoggingApplicationListenerTests {
}
}
}