Search in sources :

Example 6 with KapuaEid

use of org.eclipse.kapua.commons.model.id.KapuaEid in project kapua by eclipse.

the class KapuaSessionAuthFilter method executeChain.

protected void executeChain(ServletRequest request, ServletResponse response, FilterChain origChain) throws IOException, ServletException {
    // bind kapua session
    // TODO workaround to fix the null kapua session on webconsole requests.
    // to be removed and substitute with getToken or another solution?
    KapuaSession kapuaSession = null;
    Subject shiroSubject = SecurityUtils.getSubject();
    if (shiroSubject != null && shiroSubject.isAuthenticated()) {
        Session s = shiroSubject.getSession();
        KapuaEid scopeId = (KapuaEid) s.getAttribute("scopeId");
        KapuaEid userScopeId = (KapuaEid) s.getAttribute("userScopeId");
        KapuaEid userId = (KapuaEid) s.getAttribute("userId");
        // create the access token
        String generatedTokenKey = UUID.randomUUID().toString();
        AccessToken accessToken = new AccessTokenImpl(userId, scopeId, userScopeId, generatedTokenKey);
        kapuaSession = new KapuaSession(accessToken, scopeId, userScopeId, userId, "");
    }
    try {
        KapuaSecurityUtils.setSession(kapuaSession);
        super.executeChain(request, response, origChain);
    } finally {
        // unbind kapua session
        KapuaSecurityUtils.clearSession();
    }
}
Also used : KapuaSession(org.eclipse.kapua.commons.security.KapuaSession) AccessToken(org.eclipse.kapua.service.authentication.AccessToken) AccessTokenImpl(org.eclipse.kapua.service.authentication.AccessTokenImpl) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) Subject(org.apache.shiro.subject.Subject) Session(org.apache.shiro.session.Session) KapuaSession(org.eclipse.kapua.commons.security.KapuaSession)

Example 7 with KapuaEid

use of org.eclipse.kapua.commons.model.id.KapuaEid in project kapua by eclipse.

the class KapuaEidTest method test.

@Test
public void test() {
    KapuaEid kid = new KapuaEid(eid);
    String sid = kid.getShortId();
    System.out.println(eid + "=" + sid);
    assertEquals(eid, kid.getId());
    assertEquals(eid.toString(), kid.toString());
    KapuaEid kid1 = KapuaEid.parseShortId(sid);
    assertEquals(eid, kid1.getId());
    assertEquals(kid.toString(), kid1.toString());
    assertEquals(kid.getShortId(), kid1.getShortId());
}
Also used : KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) Test(org.junit.Test)

Example 8 with KapuaEid

use of org.eclipse.kapua.commons.model.id.KapuaEid in project kapua by eclipse.

the class AbstractKapuaEntity method prePersistsAction.

@PrePersist
protected void prePersistsAction() throws KapuaException {
    KapuaLocator locator = KapuaLocator.getInstance();
    IdGeneratorService idGenerator = locator.getService(IdGeneratorService.class);
    this.id = new KapuaEid(idGenerator.generate().getId());
    this.createdBy = new KapuaEid(KapuaSecurityUtils.getSession().getUserId().getId());
    this.createdOn = new Date();
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) IdGeneratorService(org.eclipse.kapua.service.generator.id.IdGeneratorService) Date(java.util.Date) PrePersist(javax.persistence.PrePersist)

Example 9 with KapuaEid

use of org.eclipse.kapua.commons.model.id.KapuaEid in project kapua by eclipse.

the class DeviceValidationTest method shouldValidateNullClientIdInCreator.

@Test
public void shouldValidateNullClientIdInCreator() throws KapuaException {
    DeviceCreator deviceCreator = new TestDeviceCreator(new KapuaEid(ONE));
    try {
        deviceValidation.validateCreatePreconditions(deviceCreator);
    } catch (KapuaIllegalNullArgumentException e) {
        if (e.getMessage().contains("clientId")) {
            return;
        }
    }
    fail();
}
Also used : DeviceCreator(org.eclipse.kapua.service.device.registry.DeviceCreator) KapuaIllegalNullArgumentException(org.eclipse.kapua.KapuaIllegalNullArgumentException) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) Test(org.junit.Test)

Example 10 with KapuaEid

use of org.eclipse.kapua.commons.model.id.KapuaEid in project kapua by eclipse.

the class AccountServiceTest method testDelete.

@Test
public void testDelete() throws Exception {
    // KapuaPeid accountPeid = KapuaEidGenerator.generate();//
    KapuaId scopeId = new KapuaEid(BigInteger.valueOf(1));
    KapuaLocator locator = KapuaLocator.getInstance();
    long accountSerial = (new Date()).getTime();
    AccountCreator accountCreator = this.getTestAccountCreator(scopeId, accountSerial);
    AccountService accountService = locator.getService(AccountService.class);
    Account account = accountService.create(accountCreator);
    accountService.delete(scopeId, account.getId());
    try {
        account = accountService.find(account.getScopeId(), account.getId());
    } catch (KapuaEntityNotFoundException ex) {
        account = null;
    }
    assertTrue(account == null);
}
Also used : AccountCreator(org.eclipse.kapua.service.account.AccountCreator) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) KapuaId(org.eclipse.kapua.model.id.KapuaId) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) AccountService(org.eclipse.kapua.service.account.AccountService) Date(java.util.Date) KapuaEntityNotFoundException(org.eclipse.kapua.KapuaEntityNotFoundException) Test(org.junit.Test)

Aggregations

KapuaEid (org.eclipse.kapua.commons.model.id.KapuaEid)16 Test (org.junit.Test)10 KapuaId (org.eclipse.kapua.model.id.KapuaId)7 Date (java.util.Date)6 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)6 AccountCreator (org.eclipse.kapua.service.account.AccountCreator)5 AccountService (org.eclipse.kapua.service.account.AccountService)5 Account (org.eclipse.kapua.service.account.Account)4 BigInteger (java.math.BigInteger)3 DeviceCreator (org.eclipse.kapua.service.device.registry.DeviceCreator)3 Session (org.apache.shiro.session.Session)2 Subject (org.apache.shiro.subject.Subject)2 KapuaException (org.eclipse.kapua.KapuaException)2 KapuaSession (org.eclipse.kapua.commons.security.KapuaSession)2 AccessToken (org.eclipse.kapua.service.authentication.AccessToken)2 AccessTokenImpl (org.eclipse.kapua.service.authentication.AccessTokenImpl)2 HashMap (java.util.HashMap)1 StringTokenizer (java.util.StringTokenizer)1 PrePersist (javax.persistence.PrePersist)1 Query (javax.persistence.Query)1