use of org.springframework.security.core.GrantedAuthority in project spring-boot by spring-projects.
the class UserInfoTokenServices method extractAuthentication.
private OAuth2Authentication extractAuthentication(Map<String, Object> map) {
Object principal = getPrincipal(map);
List<GrantedAuthority> authorities = this.authoritiesExtractor.extractAuthorities(map);
OAuth2Request request = new OAuth2Request(null, this.clientId, null, true, null, null, null, null, null);
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(principal, "N/A", authorities);
token.setDetails(map);
return new OAuth2Authentication(request, token);
}
use of org.springframework.security.core.GrantedAuthority in project coffeenet-starter by coffeenet.
the class CoffeeNetWebExtractorTest method extractApps.
@Test
public void extractApps() {
Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
apps.put("cna1", singletonList(coffeeNetApp));
CoffeeNetApp profileApp = new CoffeeNetApp("Profile", "profile.coffeenet", emptySet());
apps.put("profile", singletonList(profileApp));
sut.registerService(APP_SERVICE, coffeeNetAppServiceMock);
when(coffeeNetAppServiceMock.getApps(any())).thenReturn(apps);
// user
sut.registerService(USER_SERVICE, coffeeNetCurrentUserServiceMock);
List<GrantedAuthority> authorities = singletonList(new SimpleGrantedAuthority("ROLE_COFFEENET-ADMIN"));
Optional<CoffeeNetUserDetails> user = of(new HumanCoffeeNetUser("username", "email", authorities));
when(coffeeNetCurrentUserServiceMock.get()).thenReturn(user);
Optional<Map<String, List<CoffeeNetApp>>> extractedApps = sut.extractApps();
Map<String, List<CoffeeNetApp>> coffeeNetApps = extractedApps.get();
assertThat(coffeeNetApps).hasSize(2);
assertThat(coffeeNetApps.get("apps")).hasSize(1);
assertThat(coffeeNetApps.get("apps").get(0)).isSameAs(coffeeNetApp);
assertThat(coffeeNetApps.get("profile")).hasSize(1);
assertThat(coffeeNetApps.get("profile").get(0)).isSameAs(profileApp);
}
use of org.springframework.security.core.GrantedAuthority in project coffeenet-starter by coffeenet.
the class CoffeeNetWebExtractorTest method extractAppsNoProfile.
@Test
public void extractAppsNoProfile() {
Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
apps.put("apps", singletonList(coffeeNetApp));
sut.registerService(APP_SERVICE, coffeeNetAppServiceMock);
when(coffeeNetAppServiceMock.getApps(any())).thenReturn(apps);
// user
sut.registerService(USER_SERVICE, coffeeNetCurrentUserServiceMock);
List<GrantedAuthority> authorities = singletonList(new SimpleGrantedAuthority("ROLE_COFFEENET-ADMIN"));
Optional<CoffeeNetUserDetails> user = of(new HumanCoffeeNetUser("username", "email", authorities));
when(coffeeNetCurrentUserServiceMock.get()).thenReturn(user);
Optional<Map<String, List<CoffeeNetApp>>> extractedApps = sut.extractApps();
Map<String, List<CoffeeNetApp>> coffeeNetApps = extractedApps.get();
assertThat(coffeeNetApps).hasSize(1);
assertThat(coffeeNetApps.get("apps")).hasSize(1);
assertThat(coffeeNetApps.get("apps").get(0)).isSameAs(coffeeNetApp);
assertThat(coffeeNetApps.get("profile")).isNull();
}
use of org.springframework.security.core.GrantedAuthority in project coffeenet-starter by coffeenet.
the class CoffeeNetAuthoritiesExtractor method extractAuthoritiesOutOfPrincipal.
private static List<GrantedAuthority> extractAuthoritiesOutOfPrincipal(Map principal) {
List<GrantedAuthority> authoritiesList;
if (principal.containsKey(AUTHORITIES) && principal.get(AUTHORITIES) instanceof Collection) {
String authorities = collectionToCommaDelimitedString((Collection) principal.get(AUTHORITIES));
authoritiesList = AuthorityUtils.commaSeparatedStringToAuthorityList(authorities);
} else {
LOGGER.warn(ERROR_MSG);
authoritiesList = AuthorityUtils.commaSeparatedStringToAuthorityList(DEFAULT_AUTHORITY);
}
return authoritiesList;
}
use of org.springframework.security.core.GrantedAuthority in project coffeenet-starter by coffeenet.
the class HumanCoffeeNetUserTest method isAdminNotAndWrongAuthorities.
@Test
public void isAdminNotAndWrongAuthorities() {
List<GrantedAuthority> authorities = singletonList(new SimpleGrantedAuthority("ROLE_NO"));
HumanCoffeeNetUser sut = new HumanCoffeeNetUser("username", "email@coffeenet", authorities);
assertThat(sut.isCoffeeNetAdmin(), is(false));
}
Aggregations