Search in sources :

Example 1 with HumanCoffeeNetUser

use of rocks.coffeenet.autoconfigure.security.service.HumanCoffeeNetUser in project coffeenet-starter by coffeenet.

the class CoffeeNetNavigationDataExtractorTest 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(CoffeeNetNavigationDataExtractor.CoffeeNetServices.APP_SERVICE, coffeeNetAppServiceMock);
    when(coffeeNetAppServiceMock.getApps(any())).thenReturn(apps);
    // user
    sut.registerService(CoffeeNetNavigationDataExtractor.CoffeeNetServices.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();
}
Also used : HashMap(java.util.HashMap) HumanCoffeeNetUser(rocks.coffeenet.autoconfigure.security.service.HumanCoffeeNetUser) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) CoffeeNetUserDetails(rocks.coffeenet.autoconfigure.security.service.CoffeeNetUserDetails) CoffeeNetApp(rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetApp) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Collections.emptyList(java.util.Collections.emptyList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with HumanCoffeeNetUser

use of rocks.coffeenet.autoconfigure.security.service.HumanCoffeeNetUser in project coffeenet-starter by coffeenet.

the class CoffeeNetNavigationDataExtractorTest 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(CoffeeNetNavigationDataExtractor.CoffeeNetServices.APP_SERVICE, coffeeNetAppServiceMock);
    when(coffeeNetAppServiceMock.getApps(any())).thenReturn(apps);
    // user
    sut.registerService(CoffeeNetNavigationDataExtractor.CoffeeNetServices.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);
}
Also used : HashMap(java.util.HashMap) HumanCoffeeNetUser(rocks.coffeenet.autoconfigure.security.service.HumanCoffeeNetUser) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) CoffeeNetUserDetails(rocks.coffeenet.autoconfigure.security.service.CoffeeNetUserDetails) CoffeeNetApp(rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetApp) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Collections.emptyList(java.util.Collections.emptyList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with HumanCoffeeNetUser

use of rocks.coffeenet.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));
}
Also used : HumanCoffeeNetUser(rocks.coffeenet.autoconfigure.security.service.HumanCoffeeNetUser) Test(org.junit.Test)

Example 4 with HumanCoffeeNetUser

use of rocks.coffeenet.autoconfigure.security.service.HumanCoffeeNetUser in project coffeenet-starter by coffeenet.

the class CoffeeNetPrincipalExtractorTest method extractPrincipalReturnsUnknownHumanCoffeeUserIfMapDoesNotContainPrincipalKey.

@Test
public void extractPrincipalReturnsUnknownHumanCoffeeUserIfMapDoesNotContainPrincipalKey() {
    userInfoHashMap.remove("principal");
    Object principal = sut.extractPrincipal(userInfoHashMap);
    assertThat(principal, instanceOf(HumanCoffeeNetUser.class));
    HumanCoffeeNetUser humanCoffeeUser = (HumanCoffeeNetUser) principal;
    assertThat(humanCoffeeUser.getEmail(), is("UNKNOWN"));
    assertThat(humanCoffeeUser.getUsername(), is("UNKNOWN"));
    assertThat(humanCoffeeUser.getAuthorities().size(), is(1));
}
Also used : HumanCoffeeNetUser(rocks.coffeenet.autoconfigure.security.service.HumanCoffeeNetUser) Test(org.junit.Test)

Example 5 with HumanCoffeeNetUser

use of rocks.coffeenet.autoconfigure.security.service.HumanCoffeeNetUser in project coffeenet-starter by coffeenet.

the class CoffeeNetPrincipalExtractorTest method extractPrincipalReturnsHumanCoffeeUserWithUnknownMailIfPrincipalDoesNotContainMailKey.

@Test
public void extractPrincipalReturnsHumanCoffeeUserWithUnknownMailIfPrincipalDoesNotContainMailKey() {
    testPrincipal.remove("mail");
    Object principal = sut.extractPrincipal(userInfoHashMap);
    assertThat(principal, instanceOf(HumanCoffeeNetUser.class));
    HumanCoffeeNetUser humanCoffeeUser = (HumanCoffeeNetUser) principal;
    assertThat(humanCoffeeUser.getEmail(), is("UNKNOWN"));
    assertThat(humanCoffeeUser.getUsername(), is("coffy"));
    assertThat(humanCoffeeUser.getAuthorities().size(), is(1));
}
Also used : HumanCoffeeNetUser(rocks.coffeenet.autoconfigure.security.service.HumanCoffeeNetUser) Test(org.junit.Test)

Aggregations

HumanCoffeeNetUser (rocks.coffeenet.autoconfigure.security.service.HumanCoffeeNetUser)12 Test (org.junit.Test)11 Map (java.util.Map)3 CoffeeNetUserDetails (rocks.coffeenet.autoconfigure.security.service.CoffeeNetUserDetails)3 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 GrantedAuthority (org.springframework.security.core.GrantedAuthority)2 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2 CoffeeNetApp (rocks.coffeenet.autoconfigure.discovery.service.CoffeeNetApp)2