use of io.divide.shared.transitory.query.Query in project divide by HiddenStage.
the class SecurityFilter method authenticate.
private UserContext authenticate(ContainerRequestContext request) {
// Extract authentication credentials
String authentication = request.getHeaderString(ContainerRequest.AUTHORIZATION);
System.out.println("HeaderCount: " + request.getHeaders().keySet().size());
System.out.println(request.getHeaders().keySet());
System.out.println(request.getPropertyNames());
System.out.println(request.getCookies().keySet());
if (authentication == null) {
return abort(request, "Authentication credentials are required");
}
if (!authentication.startsWith("CUSTOM ")) {
return abort(request, "Only CUSTOM authentication is supported: " + authentication);
}
authentication = authentication.substring("CUSTOM ".length());
String token = authentication;
if (token == null) {
return abort(request, "Missing token");
}
// TODO verify
try {
AuthTokenUtils.AuthToken authToken = new AuthTokenUtils.AuthToken(securityManager.getSymmetricKey(), token);
if (authToken.isExpired()) {
return abort(request, "Auth Token Expired: " + System.currentTimeMillis() + " : " + authToken.expirationDate);
}
} catch (AuthTokenUtils.AuthenticationException e) {
return abort(request, "Auth Token Expired: " + e.getMessage());
}
// Validate the extracted credentials
synchronized (dao) {
Query q = new QueryBuilder().select().from(Credentials.class).where(Credentials.AUTH_TOKEN_KEY, OPERAND.EQ, token).build();
try {
TransientObject temp = ObjectUtils.get1stOrNull(dao.query(q));
if (temp != null) {
ServerCredentials creds = new ServerCredentials(temp);
// creds.setAuthToken(AuthTokenUtils.getNewToken(securityManager.getSymmetricKey(),creds)); // assign new token
return new UserContext(request.getUriInfo(), new ServerCredentials(creds));
} else {
// System.err.println("IN DB: " + dao.query(new QueryBuilder().select().from(Credentials.class).build()));
request.abortWith(notAuthReponse("Invalid authentication token"));
return abort(request, "Invalid authentication token");
}
} catch (ServerDAO.DAOException e) {
log.severe("Authentication Failed(" + e.getStatusCode() + ") " + e.getMessage());
e.printStackTrace();
return abort(request, "Invalid authentication token");
}
}
}
use of io.divide.shared.transitory.query.Query in project divide by HiddenStage.
the class AuthServerLogic method getUserFromAuthToken.
public Credentials getUserFromAuthToken(String token) throws DAOException {
AuthTokenUtils.AuthToken authToken;
try {
authToken = new AuthTokenUtils.AuthToken(keyManager.getSymmetricKey(), token);
} catch (AuthenticationException e) {
throw new DAOException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "internal error");
}
if (authToken.isExpired())
throw new DAOException(HttpStatus.SC_UNAUTHORIZED, "Expired");
Query q = new QueryBuilder().select().from(Credentials.class).where(Credentials.AUTH_TOKEN_KEY, OPERAND.EQ, token).build();
TransientObject to = ObjectUtils.get1stOrNull(dao.query(q));
if (to != null) {
return new ServerCredentials(to);
} else {
throw new DAOException(HttpStatus.SC_BAD_REQUEST, "invalid auth token");
}
}
use of io.divide.shared.transitory.query.Query in project divide by HiddenStage.
the class DaoUtils method getUserByEmail.
/**
* Convience method to do a Credentials query against an email address
* @param serverDao dao object to query against.
* @param email email address used in query.
* @return Credentials object found or null.
* @throws io.divide.shared.server.DAO.DAOException
*/
public static Credentials getUserByEmail(DAO serverDao, String email) throws DAO.DAOException {
Query query = new QueryBuilder().select().from(Credentials.class).where(Credentials.EMAIL_KEY, OPERAND.EQ, email).build();
TransientObject to = (TransientObject) ObjectUtils.get1stOrNull(serverDao.query(query));
if (to == null) {
return null;
} else {
return to(Credentials.class, to);
}
}
use of io.divide.shared.transitory.query.Query in project divide by HiddenStage.
the class MyActivity method getObjects.
@OnClick(R.id.getObjects)
public void getObjects() {
final Query q = new QueryBuilder().select().from(BackendObject.class).limit(10).build();
BackendServices.remote().query(BackendObject.class, q).subscribe(new Action1<Collection<BackendObject>>() {
@Override
public void call(Collection<BackendObject> objects) {
objectList.clear();
objectList.addAll(objects);
adapter.notifyDataSetChanged();
// BackendServices.local().save((BackendObject[]) objects.toArray());
// List<BackendObject> col = BackendServices.local().query(q);
// for (BackendObject o : col) logger.debug(o);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
logger.debug("", throwable);
}
});
}
use of io.divide.shared.transitory.query.Query in project divide by HiddenStage.
the class DAOTest method testDelete.
@Test
public void testDelete() throws Exception {
rawSave(object1, object2, object3, object4);
dao.delete(testObject1);
dao.delete(testObject4);
Collection<TransientObject> results = dao.get(testObject1Table, testObject1.getObjectKey(), testObject2.getObjectKey());
assertNotEquals(null, results);
assertEquals(1, results.size());
assertEquals(ObjectUtils.get1stOrNull(results).getObjectKey(), testObject2.getObjectKey());
Query q = new QueryBuilder().select().from(TestObject1.class).build();
results = dao.query(q);
assertNotEquals("Select All", null, results);
assertEquals("Select All", 2, results.size());
q = new QueryBuilder().select().from(TestObject2.class).build();
results = dao.query(q);
assertNotEquals("Select All", null, results);
assertEquals("Select All", 0, results.size());
}
Aggregations