Search in sources :

Example 1 with AuthenticatedUser

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

the class ClientSideAuthProvider method persistAuthentication.

/**
 * unless the user requests to stay logged in, the authToken is set to expire at the end of the user's session,
 * which means that it won't be available if the user opens the app via the appcache later on. Since
 * BootstrapScriptServlet relies on the token to select the appropriate locale, without the cookie set, trying to
 * retrieve the latest manifest will fail
 */
public static void persistAuthentication() {
    AuthenticatedUser user = new ClientSideAuthProvider().get();
    Cookies.setCookie(AuthenticatedUser.AUTH_TOKEN_COOKIE, user.getAuthToken(), oneYearLater());
    Cookies.setCookie(AuthenticatedUser.USER_ID_COOKIE, Integer.toString(user.getUserId()), oneYearLater());
    Cookies.setCookie(AuthenticatedUser.EMAIL_COOKIE, user.getEmail(), oneYearLater());
}
Also used : AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser)

Example 2 with AuthenticatedUser

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

the class AuthenticationFilter method queryAuthToken.

private AuthenticatedUser queryAuthToken(String authToken) {
    Authentication entity = entityManager.get().find(Authentication.class, authToken);
    if (entity == null) {
        // try as basic authentication
        entity = basicAuthenticator.tryAuthenticate(authToken);
    }
    if (entity == null) {
        throw new IllegalArgumentException();
    }
    AuthenticatedUser authenticatedUser = new AuthenticatedUser(authToken, entity.getUser().getId(), entity.getUser().getEmail());
    authenticatedUser.setUserLocale(entity.getUser().getLocale());
    return authenticatedUser;
}
Also used : Authentication(org.activityinfo.server.database.hibernate.entity.Authentication) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser)

Example 3 with AuthenticatedUser

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

the class BasicAuthentication method doAuthentication.

public User doAuthentication(String auth) throws IOException {
    User user = authenticate(auth);
    if (user == null) {
        return null;
    }
    authProvider.set(new AuthenticatedUser("", user.getId(), user.getEmail()));
    return user;
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser)

Example 4 with AuthenticatedUser

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

the class PermissionOracle method isViewAllowed.

public boolean isViewAllowed(ResourceId databaseId, AuthenticatedUser authenticatedUser) {
    if (databaseId.getDomain() != DATABASE_DOMAIN) {
        return false;
    }
    Database database = em.get().find(Database.class, CuidAdapter.getLegacyIdFromCuid(databaseId));
    User user = em.get().find(User.class, authenticatedUser.getId());
    return isViewAllowed(database, user);
}
Also used : AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser)

Example 5 with AuthenticatedUser

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

the class XFormResources method form.

@GET
@Path("{id}/xform")
@Produces(MediaType.TEXT_XML)
public Response form(@PathParam("id") int id) {
    AuthenticatedUser user = authProvider.get();
    LOGGER.finer("ODK activity form " + id + " requested by " + user.getEmail() + " (" + user.getId() + ")");
    FormClass formClass = fetchFormClass(id);
    String authenticationToken = authenticationTokenService.createAuthenticationToken(user.getId(), formClass.getId());
    XForm xForm = new XFormBuilder(factory).setUserId(authenticationToken).build(formClass);
    return Response.ok(xForm).build();
}
Also used : XForm(org.activityinfo.io.xform.form.XForm) FormClass(org.activityinfo.model.form.FormClass) XFormBuilder(org.activityinfo.server.endpoint.odk.build.XFormBuilder) 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