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);
}
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();
}
}
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));
}
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"));
}
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));
}
Aggregations