use of org.eclipse.kapua.service.authentication.UsernamePasswordTokenFactory 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.UsernamePasswordTokenFactory 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.UsernamePasswordTokenFactory 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();
}
}
use of org.eclipse.kapua.service.authentication.UsernamePasswordTokenFactory in project kapua by eclipse.
the class GwtAuthorizationServiceImpl method login.
/**
* Login call in response to the login dialog.
*/
public GwtSession login(GwtUser tmpUser) throws GwtKapuaException {
// VIP
// keep this here to make sure we initialize the logger.
// Without the following, console logger may not log anything when deployed into tomcat.
s_logger.info(">>> THIS IS INFO <<<");
s_logger.warn(">>> THIS IS WARN <<<");
s_logger.debug(">>> THIS IS DEBUG <<<");
GwtSession gwtSession = null;
try {
// Get the user
KapuaLocator locator = KapuaLocator.getInstance();
AuthenticationService authenticationService = locator.getService(AuthenticationService.class);
UsernamePasswordTokenFactory credentialsFactory = locator.getFactory(UsernamePasswordTokenFactory.class);
AuthenticationCredentials credentials = credentialsFactory.newInstance(tmpUser.getUsername(), tmpUser.getPassword().toCharArray());
// Login
authenticationService.login(credentials);
// Get the session infos
gwtSession = establishSession();
} catch (Throwable t) {
logout();
KapuaExceptionHandler.handle(t);
}
return gwtSession;
}
Aggregations