Search in sources :

Example 6 with HumanCoffeeNetUser

use of rocks.coffeenet.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(ERROR_MSG_TEMPLATE, PRINCIPAL_KEY, humanCoffeeUser);
    }
    return humanCoffeeUser;
}
Also used : HumanCoffeeNetUser(rocks.coffeenet.autoconfigure.security.service.HumanCoffeeNetUser) Map(java.util.Map)

Example 7 with HumanCoffeeNetUser

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

the class CoffeeNetNavigationDataExtractorTest method extractUser.

@Test
public void extractUser() {
    sut.registerService(CoffeeNetNavigationDataExtractor.CoffeeNetServices.USER_SERVICE, coffeeNetCurrentUserServiceMock);
    Optional<CoffeeNetUserDetails> user = of(new HumanCoffeeNetUser("username", "email", emptyList()));
    when(coffeeNetCurrentUserServiceMock.get()).thenReturn(user);
    Optional<CurrentCoffeeNetUser> coffeeNetWebUser = sut.extractUser();
    assertThat(coffeeNetWebUser.get().getEmail()).isSameAs("email");
    assertThat(coffeeNetWebUser.get().getUsername()).isSameAs("username");
}
Also used : HumanCoffeeNetUser(rocks.coffeenet.autoconfigure.security.service.HumanCoffeeNetUser) CoffeeNetUserDetails(rocks.coffeenet.autoconfigure.security.service.CoffeeNetUserDetails) Test(org.junit.Test)

Example 8 with HumanCoffeeNetUser

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

the class CoffeeNetPrincipalExtractorTest method extractPrincipalReturnsHumanCoffeeUserWithUnknownMailIfMailIsNotOfTypeString.

@Test
public void extractPrincipalReturnsHumanCoffeeUserWithUnknownMailIfMailIsNotOfTypeString() {
    testPrincipal.put("mail", true);
    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)

Example 9 with HumanCoffeeNetUser

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

the class CoffeeNetPrincipalExtractorTest method extractPrincipalReturnsUnknownHumanCoffeeUserIfPrincipalIsNotOfTypeMap.

@Test
public void extractPrincipalReturnsUnknownHumanCoffeeUserIfPrincipalIsNotOfTypeMap() {
    userInfoHashMap.put("principal", "someThingElse");
    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 10 with HumanCoffeeNetUser

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

the class CoffeeNetPrincipalExtractorTest method extractPrincipalReturnHumanCoffeeUser.

@Test
public void extractPrincipalReturnHumanCoffeeUser() {
    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));
}
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