Search in sources :

Example 16 with AuthenticatedUser

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ResourceId(org.activityinfo.model.resource.ResourceId) BlobId(org.activityinfo.store.spi.BlobId) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) GcsFileMetadata(com.google.appengine.tools.cloudstorage.GcsFileMetadata) GcsFilename(com.google.appengine.tools.cloudstorage.GcsFilename)

Example 17 with AuthenticatedUser

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();
        }
    });
}
Also used : ClientSideAuthProvider(org.activityinfo.ui.client.inject.ClientSideAuthProvider) GetUserProfile(org.activityinfo.legacy.shared.command.GetUserProfile) UserProfileDTO(org.activityinfo.legacy.shared.model.UserProfileDTO) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser)

Example 18 with AuthenticatedUser

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);
}
Also used : AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser)

Example 19 with AuthenticatedUser

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();
    }
}
Also used : Filter(org.activityinfo.legacy.shared.command.Filter) OutputStream(java.io.OutputStream) GeneratedResource(org.activityinfo.server.generated.GeneratedResource) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) Timed(org.activityinfo.server.util.monitoring.Timed)

Example 20 with AuthenticatedUser

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;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser)

Aggregations

AuthenticatedUser (org.activityinfo.legacy.shared.AuthenticatedUser)22 WebApplicationException (javax.ws.rs.WebApplicationException)3 Before (org.junit.Before)3 EntityManager (javax.persistence.EntityManager)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Response (javax.ws.rs.core.Response)2 FormClass (org.activityinfo.model.form.FormClass)2 ResourceId (org.activityinfo.model.resource.ResourceId)2 User (org.activityinfo.server.database.hibernate.entity.User)2 Test (org.junit.Test)2 Queue (com.google.appengine.api.taskqueue.Queue)1 GcsFileMetadata (com.google.appengine.tools.cloudstorage.GcsFileMetadata)1 GcsFilename (com.google.appengine.tools.cloudstorage.GcsFilename)1 Optional (com.google.common.base.Optional)1 VoidWork (com.googlecode.objectify.VoidWork)1 Viewable (com.sun.jersey.api.view.Viewable)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Properties (java.util.Properties)1 XForm (org.activityinfo.io.xform.form.XForm)1