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. * Extract the authorities from the resource server's response.
*
* @param map the response * @param map the response
* @return the extracted authorities * @return the extracted authorities
*/ */

View File

@ -41,19 +41,19 @@ public class FixedAuthoritiesExtractor implements AuthoritiesExtractor {
public List<GrantedAuthority> extractAuthorities(Map<String, Object> map) { public List<GrantedAuthority> extractAuthorities(Map<String, Object> map) {
String authorities = "ROLE_USER"; String authorities = "ROLE_USER";
if (map.containsKey(AUTHORITIES)) { if (map.containsKey(AUTHORITIES)) {
Object object = map.get(AUTHORITIES); authorities = asAuthorities(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();
}
} }
return AuthorityUtils.commaSeparatedStringToAuthorityList(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; import static org.junit.Assert.assertEquals;
/** /**
* Tests for {@link FixedAuthoritiesExtractor}.
*
* @author Dave Syer * @author Dave Syer
*/ */
public class FixedAuthoritiesExtractorTests { public class FixedAuthoritiesExtractorTests {

View File

@ -204,8 +204,10 @@ public class ResourceServerTokenServicesConfigurationTests {
return AuthorityUtils return AuthorityUtils
.commaSeparatedStringToAuthorityList("ROLE_ADMIN"); .commaSeparatedStringToAuthorityList("ROLE_ADMIN");
} }
}; };
} }
} }
@Import({ OAuth2RestOperationsConfiguration.class }) @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 * 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 * JVM exits. The default implementation returns {@code null}, indicating that no
* shutdown is required. * shutdown is required.
*
* @return the shutdown handler, or {@code null} * @return the shutdown handler, or {@code null}
*/ */
public Runnable getShutdownHandler() { public Runnable getShutdownHandler() {

View File

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