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