use of org.activityinfo.legacy.shared.AuthenticatedUser in project activityinfo by bedatadriven.
the class GcsBlobServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
BlobId blobId = new BlobId(request.getParameter("blobId"));
ResourceId resourceId = ResourceId.valueOf(request.getParameter("resourceId"));
Preconditions.checkState(!Strings.isNullOrEmpty(blobId.asString()));
Preconditions.checkState(!Strings.isNullOrEmpty(resourceId.asString()));
AuthenticatedUser user = authProvider.get();
service.assertNotAnonymousUser(user);
service.assertHasAccess(user, blobId, resourceId);
service.assertBlobExists(blobId);
GcsFileMetadata metadata = GcsServiceFactory.createGcsService().getMetadata(new GcsFilename(service.getBucketName(), blobId.asString()));
response.setHeader("Content-Disposition", metadata.getOptions().getContentDisposition());
response.setContentType(metadata.getOptions().getMimeType());
BlobstoreServiceFactory.getBlobstoreService().serve(service.blobKey(blobId), response);
} catch (WebApplicationException e) {
sendError(response, e);
}
}
use of org.activityinfo.legacy.shared.AuthenticatedUser in project activityinfo by bedatadriven.
the class UserProfilePage method bindProfile.
private void bindProfile() {
userProfile = new UserProfileDTO();
AuthenticatedUser user = new ClientSideAuthProvider().get();
dispatcher.execute(new GetUserProfile(user.getUserId()), new AsyncCallback<UserProfileDTO>() {
@Override
public void onFailure(Throwable caught) {
Log.error("error binding profile", caught);
MessageBox.alert(I18N.CONSTANTS.serverError(), caught.getMessage(), null);
}
@Override
public void onSuccess(UserProfileDTO userProfileDTO) {
userProfile = userProfileDTO;
binding.bind(userProfile);
UserProfilePage.this.show();
maybeShowSwitchLocaleLink();
}
});
}
use of org.activityinfo.legacy.shared.AuthenticatedUser in project activityinfo by bedatadriven.
the class PermissionOracle method assertDesignPrivileges.
public void assertDesignPrivileges(int databaseId, AuthenticatedUser authenticatedUser) {
Database database = em.get().find(Database.class, databaseId);
User user = em.get().find(User.class, authenticatedUser.getId());
assertDesignPrivileges(database, user);
}
use of org.activityinfo.legacy.shared.AuthenticatedUser in project activityinfo by bedatadriven.
the class ExportSitesTask method doPost.
@Override
@Timed(name = "export", kind = "sites")
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String exportId = req.getParameter("exportId");
String locale = req.getParameter("locale");
if (Strings.isNullOrEmpty(locale)) {
locale = Locale.ENGLISH.toLanguageTag();
}
// authenticate this task
authProvider.set(new AuthenticatedUser("", Integer.parseInt(req.getParameter("userId")), req.getParameter("userEmail")));
ThreadLocalLocaleProvider.pushLocale(Locale.forLanguageTag(locale));
try {
// create the workbook
Filter filter = FilterUrlSerializer.fromQueryParameter(req.getParameter("filter"));
TaskContext context = new TaskContext(dispatcher.get(), storageProvider, exportId);
SiteExporter export = new SiteExporter(context).buildExcelWorkbook(filter);
// Save to Export storage
GeneratedResource storage = storageProvider.get(exportId);
try (OutputStream out = storage.openOutputStream()) {
export.getBook().write(out);
}
} finally {
ThreadLocalLocaleProvider.popLocale();
}
}
use of org.activityinfo.legacy.shared.AuthenticatedUser in project activityinfo by bedatadriven.
the class AuthenticationTokenServiceImpl method authenticate.
@Override
public AuthenticatedUser authenticate(String authenticationToken) {
Entity authEntity = null;
try {
authEntity = datastoreService.get(key(authenticationToken));
} catch (EntityNotFoundException e) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
long userId = (Long) authEntity.getProperty("userId");
AuthenticatedUser user = new AuthenticatedUser("", (int) userId, "@");
authProvider.set(user);
return user;
}
Aggregations