Search in sources :

Example 1 with AuthenticatedUser

use of org.activityinfo.shared.auth.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.shared.auth.AuthenticatedUser)

Example 2 with AuthenticatedUser

use of org.activityinfo.shared.auth.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.shared.auth.AuthenticatedUser) AuthenticatedUser(org.activityinfo.shared.auth.AuthenticatedUser)

Example 3 with AuthenticatedUser

use of org.activityinfo.shared.auth.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.shared.auth.AuthenticatedUser)

Example 4 with AuthenticatedUser

use of org.activityinfo.shared.auth.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");
    dispatcher = new CachingDispatcher(proxyManager, new MergingDispatcher(new RemoteDispatcher(new MockEventBus(), auth, service), scheduler));
}
Also used : RemoteCommandServiceAsync(org.activityinfo.shared.command.RemoteCommandServiceAsync) CommandCache(org.activityinfo.client.dispatch.CommandCache) CachingDispatcher(org.activityinfo.client.dispatch.remote.cache.CachingDispatcher) MockEventBus(org.activityinfo.client.MockEventBus) AuthenticatedUser(org.activityinfo.shared.auth.AuthenticatedUser) Before(org.junit.Before)

Example 5 with AuthenticatedUser

use of org.activityinfo.shared.auth.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();
        }
    });
}
Also used : ClientSideAuthProvider(org.activityinfo.client.authentication.ClientSideAuthProvider) GetUserProfile(org.activityinfo.shared.command.GetUserProfile) UserProfileDTO(org.activityinfo.shared.dto.UserProfileDTO) AuthenticatedUser(org.activityinfo.shared.auth.AuthenticatedUser)

Aggregations

AuthenticatedUser (org.activityinfo.shared.auth.AuthenticatedUser)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 User (org.activityinfo.server.database.hibernate.entity.User)2 Viewable (com.sun.jersey.api.view.Viewable)1 IOException (java.io.IOException)1 Date (java.util.Date)1 EntityManager (javax.persistence.EntityManager)1 ServletException (javax.servlet.ServletException)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1 MockEventBus (org.activityinfo.client.MockEventBus)1 ClientSideAuthProvider (org.activityinfo.client.authentication.ClientSideAuthProvider)1 CommandCache (org.activityinfo.client.dispatch.CommandCache)1 CachingDispatcher (org.activityinfo.client.dispatch.remote.cache.CachingDispatcher)1 AdminEntity (org.activityinfo.server.database.hibernate.entity.AdminEntity)1 AdminLevel (org.activityinfo.server.database.hibernate.entity.AdminLevel)1 AdminLevelVersion (org.activityinfo.server.database.hibernate.entity.AdminLevelVersion)1 Authentication (org.activityinfo.server.database.hibernate.entity.Authentication)1