Search in sources :

Example 1 with AuthenticationService

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;
    }
}
Also used : KapuaException(org.eclipse.kapua.KapuaException) UsernamePasswordTokenFactory(org.eclipse.kapua.service.authentication.UsernamePasswordTokenFactory) AuthenticationService(org.eclipse.kapua.service.authentication.AuthenticationService) Before(org.junit.Before)

Example 2 with AuthenticationService

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();
    }
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaException(org.eclipse.kapua.KapuaException) AuthenticationService(org.eclipse.kapua.service.authentication.AuthenticationService) AfterClass(org.junit.AfterClass)

Example 3 with AuthenticationService

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

Example 4 with AuthenticationService

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();
    }
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaException(org.eclipse.kapua.KapuaException) AuthenticationService(org.eclipse.kapua.service.authentication.AuthenticationService)

Example 5 with AuthenticationService

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();
    }
}
Also used : AccountCreator(org.eclipse.kapua.service.account.AccountCreator) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) AccountFactory(org.eclipse.kapua.service.account.AccountFactory) KapuaException(org.eclipse.kapua.KapuaException) UsernamePasswordTokenFactory(org.eclipse.kapua.service.authentication.UsernamePasswordTokenFactory) AuthenticationService(org.eclipse.kapua.service.authentication.AuthenticationService) AccountService(org.eclipse.kapua.service.account.AccountService) Date(java.util.Date)

Aggregations

AuthenticationService (org.eclipse.kapua.service.authentication.AuthenticationService)7 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)6 KapuaException (org.eclipse.kapua.KapuaException)4 UsernamePasswordTokenFactory (org.eclipse.kapua.service.authentication.UsernamePasswordTokenFactory)4 Date (java.util.Date)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Subject (org.apache.shiro.subject.Subject)1 GwtSession (org.eclipse.kapua.app.console.shared.model.GwtSession)1 AccountCreator (org.eclipse.kapua.service.account.AccountCreator)1 AccountFactory (org.eclipse.kapua.service.account.AccountFactory)1 AccountService (org.eclipse.kapua.service.account.AccountService)1 AuthenticationCredentials (org.eclipse.kapua.service.authentication.AuthenticationCredentials)1 UsernamePasswordToken (org.eclipse.kapua.service.authentication.UsernamePasswordToken)1 AfterClass (org.junit.AfterClass)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1