Search in sources :

Example 6 with HumanCoffeeNetUser

use of coffee.synyx.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(coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser) Test(org.junit.Test)

Example 7 with HumanCoffeeNetUser

use of coffee.synyx.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(coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser) Test(org.junit.Test)

Example 8 with HumanCoffeeNetUser

use of coffee.synyx.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(coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser) Test(org.junit.Test)

Example 9 with HumanCoffeeNetUser

use of coffee.synyx.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(coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser) Test(org.junit.Test)

Example 10 with HumanCoffeeNetUser

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

the class CoffeeNetWebExtractorTest method extractUser.

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

Aggregations

HumanCoffeeNetUser (coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser)12 Test (org.junit.Test)11 CoffeeNetUserDetails (coffee.synyx.autoconfigure.security.service.CoffeeNetUserDetails)3 Map (java.util.Map)3 CoffeeNetApp (coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp)2 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