use of coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser 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 coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser 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 coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser in project coffeenet-starter by coffeenet.
the class CoffeeNetPrincipalExtractor method extractUserDetails.
private CoffeeNetUserDetails extractUserDetails(Map<String, Object> map) {
HumanCoffeeNetUser humanCoffeeUser;
if (map.containsKey(PRINCIPAL_KEY) && map.get(PRINCIPAL_KEY) instanceof Map) {
Map principal = (Map) map.get(PRINCIPAL_KEY);
humanCoffeeUser = new HumanCoffeeNetUser(extractUsername(principal), extractMail(principal), this.authoritiesExtractor.extractAuthorities(map));
} else {
humanCoffeeUser = new HumanCoffeeNetUser(UNKNOWN_VALUE, UNKNOWN_VALUE, authoritiesExtractor.extractAuthorities(map));
LOGGER.warn(String.format(ERROR_MSG_TEMPLATE, PRINCIPAL_KEY, humanCoffeeUser.toString()));
}
return humanCoffeeUser;
}
use of coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser in project coffeenet-starter by coffeenet.
the class CoffeeNetPrincipalExtractorTest method extractPrincipalReturnsHumanCoffeeUserWithUnknownNameIfPrincipalDoesNotContainUsernameKey.
@Test
public void extractPrincipalReturnsHumanCoffeeUserWithUnknownNameIfPrincipalDoesNotContainUsernameKey() {
testPrincipal.remove("username");
Object principal = sut.extractPrincipal(userInfoHashMap);
assertThat(principal, instanceOf(HumanCoffeeNetUser.class));
HumanCoffeeNetUser humanCoffeeUser = (HumanCoffeeNetUser) principal;
assertThat(humanCoffeeUser.getEmail(), is("coffy@coffeenet"));
assertThat(humanCoffeeUser.getUsername(), is("UNKNOWN"));
assertThat(humanCoffeeUser.getAuthorities().size(), is(1));
}
use of coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser in project coffeenet-starter by coffeenet.
the class CoffeeNetPrincipalExtractorTest method extractPrincipalReturnHumanCoffeeUserIfClientOnlyKeyIsMissing.
@Test
public void extractPrincipalReturnHumanCoffeeUserIfClientOnlyKeyIsMissing() {
userInfoHashMap.remove("clientOnly");
Object principal = sut.extractPrincipal(userInfoHashMap);
assertThat(principal, instanceOf(HumanCoffeeNetUser.class));
HumanCoffeeNetUser humanCoffeeUser = (HumanCoffeeNetUser) principal;
assertThat(humanCoffeeUser.getEmail(), is("coffy@coffeenet"));
assertThat(humanCoffeeUser.getUsername(), is("coffy"));
assertThat(humanCoffeeUser.getAuthorities().size(), is(1));
}
Aggregations