Search in sources :

Example 1 with UsernamePasswordToken

use of org.eclipse.kapua.service.authentication.UsernamePasswordToken in project kapua by eclipse.

the class AuthenticationServiceTest method testLoginAndLogout.

/**
 * We should ignore this test until schema loading feature is provided.
 */
@Ignore
@Test
public void testLoginAndLogout() throws Exception {
    String username = "kapua-sys";
    char[] password = "kapua-password".toCharArray();
    KapuaLocator locator = KapuaLocator.getInstance();
    UsernamePasswordTokenFactory usernamePasswordTokenFactory = locator.getFactory(UsernamePasswordTokenFactory.class);
    UsernamePasswordToken credentialsToken = usernamePasswordTokenFactory.newInstance(username, password);
    AuthenticationService authenticationService = locator.getService(AuthenticationService.class);
    authenticationService.login(credentialsToken);
    Subject currentSubject = SecurityUtils.getSubject();
    assertTrue(currentSubject.isAuthenticated());
    assertEquals(username, currentSubject.getPrincipal());
    authenticationService.logout();
    assertFalse(currentSubject.isAuthenticated());
    assertNull(currentSubject.getPrincipal());
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) UsernamePasswordTokenFactory(org.eclipse.kapua.service.authentication.UsernamePasswordTokenFactory) AuthenticationService(org.eclipse.kapua.service.authentication.AuthenticationService) Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.eclipse.kapua.service.authentication.UsernamePasswordToken) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Subject (org.apache.shiro.subject.Subject)1 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 AuthenticationService (org.eclipse.kapua.service.authentication.AuthenticationService)1 UsernamePasswordToken (org.eclipse.kapua.service.authentication.UsernamePasswordToken)1 UsernamePasswordTokenFactory (org.eclipse.kapua.service.authentication.UsernamePasswordTokenFactory)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1