use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.
the class DownloadJsonServlet method doGet.
/* (non-Javadoc)
*
* @see com.willshex.gson.web.service.server.JsonServlet#doGet() */
@Override
protected void doGet() throws IOException {
String action = REQUEST.get().getParameter("action");
String request = REQUEST.get().getParameter("request");
if (request == null && "download".equals(action)) {
Session userSession = ServletHelper.session(REQUEST.get());
if (userSession != null) {
String idParam = REQUEST.get().getParameter(ENTITY_ID_KEY);
if (idParam != null) {
Long id = Long.valueOf(idParam);
GeneratedDownload generatedDownload = GeneratedDownloadServiceProvider.provide().getGeneratedDownload(id);
if (generatedDownload.userKey.getId() == userSession.userKey.getId()) {
Filter filter = Filter.fromStack(Stack.parse(generatedDownload.parameters));
String fileName = StringUtils.urldecode(generatedDownload.parameters).replace(Filter.QUERY + "/", "").replace("/", "_").replace("&", "_").replace(" ", "_") + "." + DownloadGeneratorProvider.extension(filter.type).get();
RESPONSE.get().setContentType(DownloadGeneratorProvider.contentType(filter.type).get());
RESPONSE.get().setHeader("content-disposition", "inline; filename=\"" + fileName + "\"");
RESPONSE.get().getOutputStream().write(GcsHelper.load(GeneratedDownloadHelper.path(generatedDownload, filter)));
} else {
RESPONSE.get().sendError(403, "Access denied, cannot download other user's file");
}
}
} else {
RESPONSE.get().sendError(403, "Access denied, cannot download file without logging in");
}
} else {
super.doGet();
}
}
use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.
the class SessionController method sessionForApiCall.
public Session sessionForApiCall() {
Session session = null;
if (this.session != null && this.session.id != null) {
session = new Session();
session.id = this.session.id;
} else {
String id = Cookies.getCookie(COOKIE_KEY_ID);
if (id != null) {
session = new Session();
session.id = Long.valueOf(id);
}
}
return session;
}
use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.
the class SessionValidator method lookup.
/**
* @param session
* @param name
* @return
* @throws InputValidationException
*/
public static Session lookup(Session session, String name) throws InputValidationException {
if (session == null)
throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
boolean isIdLookup = false;
if (session.id != null) {
isIdLookup = true;
}
if (!isIdLookup)
throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
Session lookupSession = null;
if (isIdLookup) {
lookupSession = SessionServiceProvider.provide().getSession(session.id);
}
if (lookupSession == null)
throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
return lookupSession;
}
use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.
the class SessionService method addSession.
/* (non-Javadoc)
*
* @see com.willshex.blogwt.server.services.session.ISessionService
* #addSession(com.willshex.blogwt.shared.api.datatypes.Session) */
@Override
public Session addSession(Session session) {
if (session.created == null) {
session.created = new Date();
}
session.userKey = Key.create(session.user);
if (session.longTerm == null) {
session.longTerm = Boolean.FALSE;
}
if (session.expires == null) {
session.expires = DateTimeHelper.millisFromNow(Boolean.TRUE.equals(session.longTerm) ? MILLIS_DAYS : MILLIS_MINUTES);
}
Key<Session> key = provide().save().entity(session).now();
session.id = keyToId(key);
return session;
}
use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.
the class Request method fromJson.
@Override
public void fromJson(JsonObject jsonObject) {
super.fromJson(jsonObject);
if (jsonObject.has("accessCode")) {
JsonElement jsonAccessCode = jsonObject.get("accessCode");
if (jsonAccessCode != null) {
accessCode = jsonAccessCode.getAsString();
}
}
if (jsonObject.has("session")) {
JsonElement jsonSession = jsonObject.get("session");
if (jsonSession != null) {
session = new Session();
session.fromJson(jsonSession.getAsJsonObject());
}
}
}
Aggregations