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