Search in sources :

Example 6 with AuthenticatedUser

use of org.activityinfo.legacy.shared.AuthenticatedUser in project activityinfo by bedatadriven.

the class FormLister method formList.

public Response formList(UriInfo uri, Optional<Integer> dbIdFilter) throws Exception {
    AuthenticatedUser user = authProvider.get();
    LOGGER.finer("ODK form list requested by " + user.getEmail() + " (" + user.getId() + ")");
    SchemaDTO schema = dispatcher.execute(new GetSchema());
    XFormList formList = new XFormList();
    for (UserDatabaseDTO db : schema.getDatabases()) {
        if (dbIdFilter.isPresent() && db.getId() != dbIdFilter.get()) {
            // skip
            continue;
        }
        if (db.isEditAllowed()) {
            for (ActivityDTO activity : db.getActivities()) {
                if (hasAdminLevelLocation(activity)) {
                    // Admin Level Locations are invalid for ODK forms - do not show
                    continue;
                }
                XFormListItem form = new XFormListItem();
                form.setName(db.getName() + " / " + activity.getName());
                form.setFormId("activityinfo.org:" + activity.getId());
                form.setVersion(getVersion());
                form.setDownloadUrl(uri.getBaseUriBuilder().path(XFormResources.class).path(Integer.toString(activity.getId())).path("xform").build());
                formList.getItems().add(form);
            }
        }
    }
    return OpenRosaResponse.build(formList);
}
Also used : XFormList(org.activityinfo.io.xform.formList.XFormList) XFormListItem(org.activityinfo.io.xform.formList.XFormListItem) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema)

Example 7 with AuthenticatedUser

use of org.activityinfo.legacy.shared.AuthenticatedUser in project activityinfo by bedatadriven.

the class OdkAuthProvider method get.

/**
 * Returns the currently authenticated user. During develop
 *
 * @return the currently authenticated user
 * @throws javax.ws.rs.WebApplicationException if the request is not authenticated
 */
@Override
public AuthenticatedUser get() {
    if (authProvider.get().isAnonymous()) {
        if (DeploymentEnvironment.isAppEngineDevelopment()) {
            // do we have a dummy user id configured?
            String odkDebugAuthorizationUserId = config.getProperty(DEBUG_USER_ID);
            if (odkDebugAuthorizationUserId != null) {
                int userId = Integer.parseInt(odkDebugAuthorizationUserId);
                if (userId > 0) {
                    // if so, we're assuming that user is authorized.
                    User user = em.get().find(User.class, userId);
                    if (user == null) {
                        throw new IllegalStateException("odk.debug.authorization.userid set, but user cannot be found");
                    }
                    authProvider.set(user);
                    return new AuthenticatedUser("", user.getId(), user.getEmail(), user.getLocale());
                }
            }
        }
        // form of digest authentication when running in development mode.
        if (DeploymentEnvironment.isAppEngineDevelopment()) {
            LOGGER.info("Requested digest authentication for ODK testing purposes.");
            throw new WebApplicationException(Response.status(401).header("WWW-Authenticate", "Digest realm=\"Activityinfo\" qop=\"auth\" nonce=\"XYZ\" opaque=\"opaque\"").build());
        } else {
            throw new WebApplicationException(Response.status(401).header("WWW-Authenticate", "Basic realm=\"Activityinfo\"").build());
        }
    } else {
        // authorized user, continue
        return authProvider.get();
    }
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) WebApplicationException(javax.ws.rs.WebApplicationException) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser)

Example 8 with AuthenticatedUser

use of org.activityinfo.legacy.shared.AuthenticatedUser in project activityinfo by bedatadriven.

the class PivotTestResource method getDatabase.

@GET
@Path("database")
@Produces(MediaType.APPLICATION_JSON)
public List<PivotSites.PivotResult> getDatabase(@QueryParam("databaseId") int databaseId, @QueryParam("userId") int userId, @QueryParam("targets") boolean targets, @QueryParam("partners") boolean partner, @QueryParam("projects") boolean project, @QueryParam("details") boolean details, @QueryParam("new") boolean newEngine) {
    assertRunningInLocalDevelopmentEnvironment();
    authProvider.set(new AuthenticatedUser("XYZ", userId, "user@user.org"));
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Database, databaseId);
    Set<Dimension> dimensions = Sets.newHashSet();
    dimensions.add(new Dimension(DimensionType.Activity));
    dimensions.add(new Dimension(DimensionType.Indicator));
    if (targets) {
        dimensions.add(new Dimension(DimensionType.Target));
    }
    if (partner) {
        dimensions.add(new Dimension(DimensionType.Partner));
    }
    if (project) {
        dimensions.add(new Dimension(DimensionType.Project));
    }
    if (details) {
        dimensions.add(new Dimension(DimensionType.Site));
    }
    PivotSites command = new PivotSites(dimensions, filter);
    if (!newEngine) {
        command = new OldPivotSites(command);
    }
    return Lists.newArrayList(command.isTooBroad() ? new PivotSites.PivotResult() : dispatcher.execute(command));
}
Also used : Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser)

Example 9 with AuthenticatedUser

use of org.activityinfo.legacy.shared.AuthenticatedUser in project activityinfo by bedatadriven.

the class GcsBlobFieldStorageServiceTest method uploadBlob.

@Before
public final void uploadBlob() throws IOException {
    localServiceTestHelper.setUp();
    ofy = ObjectifyService.begin();
    blobService = injector.getInstance(GcsBlobFieldStorageService.class);
    blobService.setTestBucketName();
    locator = new ResourceLocatorAdaptor(new ActivityInfoClientAsyncStub(injector.getProvider(EntityManager.class), blobService));
    AuthenticationModuleStub.setUserId(1);
    user = new AuthenticatedUser("x", 1, "user1@user.com");
    noAccessUser = new AuthenticatedUser("x", 3, "stefan@user.com");
    blobId = BlobId.generate();
    blobService.put(user, "attachment;filename=" + FILE_NAME, MimeTypeUtil.mimeTypeFromFileName(FILE_NAME), blobId, resourceId, GcsBlobFieldStorageServiceTest.class.getResourceAsStream("goabout.png"));
}
Also used : EntityManager(javax.persistence.EntityManager) ResourceLocatorAdaptor(org.activityinfo.ui.client.dispatch.ResourceLocatorAdaptor) ActivityInfoClientAsyncStub(org.activityinfo.legacy.shared.adapter.ActivityInfoClientAsyncStub) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) Before(org.junit.Before)

Example 10 with AuthenticatedUser

use of org.activityinfo.legacy.shared.AuthenticatedUser in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method setUp.

@Before
public void setUp() {
    service = createMock("remoteService", RemoteCommandServiceAsync.class);
    proxy = createMock("proxy", CommandCache.class);
    AuthenticatedUser auth = new AuthenticatedUser(AUTH_TOKEN, 1, "alex@alex.com");
    BackOff backOff = new ExponentialBackOff.Builder().setInitialIntervalMillis(MergingDispatcher.ADVISORY_GET_LOCK_TIMEOUT).setMultiplier(// increase in 2 times
    2).setNanoClock(new NanoClock() {

        @Override
        public long nanoTime() {
            return System.nanoTime();
        }
    }).build();
    dispatcher = new CachingDispatcher(proxyManager, new MergingDispatcher(new RemoteDispatcher(auth, service, "en"), scheduler, backOff));
}
Also used : RemoteCommandServiceAsync(org.activityinfo.legacy.shared.command.RemoteCommandServiceAsync) CommandCache(org.activityinfo.ui.client.dispatch.CommandCache) CachingDispatcher(org.activityinfo.ui.client.dispatch.remote.cache.CachingDispatcher) NanoClock(org.activityinfo.legacy.shared.util.NanoClock) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) BackOff(org.activityinfo.legacy.shared.util.BackOff) ExponentialBackOff(org.activityinfo.legacy.shared.util.ExponentialBackOff) Before(org.junit.Before)

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