use of org.eclipse.kapua.service.authentication.AuthenticationService in project kapua by eclipse.
the class KapuaTest method setUp.
@Before
public void setUp() {
LOG.debug("Setting up test...");
if (!isInitialized) {
LOG.debug("Kapua test context is not initialized. Initializing...");
try {
//
// Login
String username = "kapua-sys";
String password = "kapua-password";
AuthenticationService authenticationService = locator.getService(AuthenticationService.class);
UsernamePasswordTokenFactory credentialsFactory = locator.getFactory(UsernamePasswordTokenFactory.class);
authenticationService.login(credentialsFactory.newInstance(username, password.toCharArray()));
//
// Get current user Id
adminUserId = KapuaSecurityUtils.getSession().getUserId();
adminScopeId = KapuaSecurityUtils.getSession().getScopeId();
} catch (KapuaException exc) {
exc.printStackTrace();
}
isInitialized = true;
}
}
use of org.eclipse.kapua.service.authentication.AuthenticationService in project kapua by eclipse.
the class KapuaTest method tearDown.
@AfterClass
public static void tearDown() {
LOG.debug("Stopping Kapua test context.");
isInitialized = false;
try {
KapuaLocator locator = KapuaLocator.getInstance();
AuthenticationService authenticationService = locator.getService(AuthenticationService.class);
authenticationService.logout();
} catch (KapuaException exc) {
exc.printStackTrace();
}
}
use of org.eclipse.kapua.service.authentication.AuthenticationService 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());
}
use of org.eclipse.kapua.service.authentication.AuthenticationService in project kapua by eclipse.
the class DeviceCommandManagementServiceTest method tearDownClass.
// @AfterClass
public static void tearDownClass() {
try {
KapuaLocator locator = KapuaLocator.getInstance();
AuthenticationService authenticationService = locator.getService(AuthenticationService.class);
authenticationService.logout();
} catch (KapuaException exc) {
exc.printStackTrace();
}
}
use of org.eclipse.kapua.service.authentication.AuthenticationService in project kapua by eclipse.
the class DeviceCommandManagementServiceTest method setUpClass.
// @BeforeClass
public static void setUpClass() {
try {
//
// Login
String username = "kapua-sys";
String password = "kapua-password";
AuthenticationService authenticationService = locator.getService(AuthenticationService.class);
UsernamePasswordTokenFactory credentialsFactory = locator.getFactory(UsernamePasswordTokenFactory.class);
authenticationService.login(credentialsFactory.newInstance(username, password.toCharArray()));
//
// Get current user Id
adminUserId = KapuaSecurityUtils.getSession().getUserId();
adminScopeId = KapuaSecurityUtils.getSession().getScopeId();
//
// Create test account
KapuaLocator locator = KapuaLocator.getInstance();
//
// Account creation
String accountName = String.format("test-acct-%d", (new Date()).getTime());
AccountService accountService = locator.getService(AccountService.class);
AccountFactory accountFactory = locator.getFactory(AccountFactory.class);
AccountCreator accountCreator = accountFactory.newAccountCreator(adminScopeId, accountName);
accountCreator.setAccountPassword("!bV0123456789");
accountCreator.setOrganizationName(accountName);
accountCreator.setOrganizationEmail(accountName + "@m.com");
account = accountService.create(accountCreator);
} catch (KapuaException exc) {
exc.printStackTrace();
}
}
Aggregations