Search in sources :

Example 1 with AccountUserDetails

use of net.nemerosa.ontrack.model.security.AccountUserDetails in project ontrack by nemerosa.

the class PasswordAuthenticationProviderIT method admin.

@Test
public void admin() {
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("admin", "admin");
    // Retrieval
    UserDetails userDetails = provider.retrieveUser("admin", token);
    // Password check
    provider.additionalAuthenticationChecks(userDetails, token);
    // Checks
    assertNotNull(userDetails);
    assertNull(userDetails.getPassword());
    assertEquals("admin", userDetails.getUsername());
    assertTrue(userDetails instanceof AccountUserDetails);
    AccountUserDetails accountUserDetails = (AccountUserDetails) userDetails;
    Account account = accountUserDetails.getAccount();
    Entity.isEntityDefined(account, "Account must be defined");
    assertEquals("admin", account.getName());
    assertEquals(SecurityRole.ADMINISTRATOR, account.getRole());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) AccountUserDetails(net.nemerosa.ontrack.model.security.AccountUserDetails) UserDetails(org.springframework.security.core.userdetails.UserDetails) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) AccountUserDetails(net.nemerosa.ontrack.model.security.AccountUserDetails) Test(org.junit.Test)

Aggregations

Account (net.nemerosa.ontrack.model.security.Account)1 AccountUserDetails (net.nemerosa.ontrack.model.security.AccountUserDetails)1 Test (org.junit.Test)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1