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());
}
Aggregations