Examples of UserService


Examples of com.google.appengine.api.users.UserService

          AuthSubUtil.revokeToken(token.getToken(), AuthenticationKey.getAuthSubKey());
      } catch (Exception x) {
        x.printStackTrace();
      }
        AuthenticationToken.clearUserToken(token.getEmail());
        UserService userService = UserServiceFactory.getUserService();
        URI url = new URI(this.getThreadLocalRequest().getRequestURL().toString());
        return userService.createLogoutURL("http://" + url.getAuthority() + LOGOUT_RETURN_RELATIVE_PATH);
      } catch (Exception e) {
        e.printStackTrace();
        throw new DocumentServiceException(e.getMessage());
      }
    }
View Full Code Here

Examples of com.google.appengine.api.users.UserService

   * The current user is authenticated if:
   * 1. The user has logged in via the Google User service.
   * 2. The user has a valid AuthSub token in the data store.
   */
  public boolean isAuthenticated() {
    UserService userService = UserServiceFactory.getUserService();
    if (userService.getCurrentUser() != null) {
      String userEmail = userService.getCurrentUser().getEmail();
      AuthenticationToken authToken = store.getUserToken(userEmail);
      if (authToken != null) {
        return true;
      }
    }
View Full Code Here

Examples of com.google.appengine.api.users.UserService

   * @throws AuthenticationException
   * @throws Base64DecoderException
   */
  public AuthenticationToken autoPilot(HttpServletRequest req, HttpServletResponse resp, boolean passive)
      throws IOException, AuthenticationException, GeneralSecurityException, Base64DecoderException {
    UserService userService = UserServiceFactory.getUserService();
    if (userService.getCurrentUser() != null) {
      String userEmail = userService.getCurrentUser().getEmail();
      AuthenticationToken authToken = store.getUserToken(userEmail);
      //check token age and clear if token is too old
      if (authToken != null && authToken.isExpired()) {
      try {
        AuthSubUtil.revokeToken(authToken.getToken(), key);
      } catch (Exception x) { }
      store.clearUserToken(authToken.getEmail());
      authToken = null;
      }
      //check token validity to ensure that the token is still valid
      if (authToken != null) {
      try {
        Map<String, String> info = AuthSubUtil.getTokenInfo(authToken.getToken(), key);
        if (info == null || info.size() == 0) {
        store.clearUserToken(authToken.getEmail());
        authToken = null;
        }
      } catch (Exception x) {
        store.clearUserToken(authToken.getEmail());
        authToken = null;
      }
      }
      if (authToken != null) {
      authToken.setActivity(new Date());
        return authToken;
      } else {
        String token = null, qs = req.getQueryString();
        if (qs != null) {
          token = AuthSubUtil.getTokenFromReply(qs);
        }
        if (token != null && !token.equals("")) {
          token = URLDecoder.decode(token, "UTF-8");
          token = AuthSubUtil.exchangeForSessionToken(token, key);
          store.setUserToken(req.getUserPrincipal().getName(), token);
          resp.sendRedirect(getFullUrl(req));
        } else {
          if (!passive) {
            String authUrl = AuthSubUtil.getRequestUrl(
                getFullUrl(req),
                DocumentServiceImpl.AUTH_SCOPES, true, true);
            resp.sendRedirect(authUrl);
          }
        }
      }
    } else {
      if (!passive) {
        String authUrl = userService.createLoginURL(getFullUrl(req));
        resp.sendRedirect(authUrl);
      }
    }
    return null;
  }
View Full Code Here

Examples of com.google.appengine.api.users.UserService

   * Retrieves the authentication token for the currently logged on user.
   *
   * @return the authentication token for the currently logged on user
   */
  public AuthenticationToken getUserToken() {
    UserService userService = UserServiceFactory.getUserService();
    if (userService.getCurrentUser() != null) {
      String email = userService.getCurrentUser().getEmail();
      return AuthenticationToken.getUserToken(email);
    }
    return null;
  }
View Full Code Here

Examples of com.google.appengine.api.users.UserService

        assertNull(filter.getFilterConfig());
    }

    /** Test the getters and setters. */
    @Test public void testGettersSetters() {
        UserService userService = mock(UserService.class);
        AuthenticationManager authenticationManager = mock(AuthenticationManager.class);
        GaeAuthenticationFilter filter = new GaeAuthenticationFilter();

        filter.setUserService(userService);
        assertSame(userService, filter.getUserService());
View Full Code Here

Examples of com.google.appengine.api.users.UserService

        assertSame(authenticationManager, filter.getAuthenticationManager());
    }

    /** Test afterPropertiesSet(). */
    @Test public void testAfterPropertiesSet() {
        UserService userService = mock(UserService.class);
        AuthenticationManager authenticationManager = mock(AuthenticationManager.class);
        GaeAuthenticationFilter filter = new GaeAuthenticationFilter();

        try {
            filter.setUserService(null);
View Full Code Here

Examples of com.google.appengine.api.users.UserService

        filter.afterPropertiesSet();
    }

    /** Test doFilter() when the user is not logged in. */
    @Test public void testDoFilterAnonymous() throws Exception {
        UserService userService = mock(UserService.class);
        AuthenticationManager authenticationManager = mock(AuthenticationManager.class);
        StubbedGaeAuthenticationFilter filter = new StubbedGaeAuthenticationFilter();

        filter.setUserService(userService);
        filter.setAuthenticationManager(authenticationManager);
        filter.afterPropertiesSet();

        when(authenticationManager.authenticate(isA(GaeUserAuthenticationToken.class))).thenAnswer(new AuthenticationAnswer());
        when(userService.isUserLoggedIn()).thenReturn(false);     // user is not logged in

        GaeUser gaeUser = callDoFilter(filter)// no client roles
        assertEquals("", gaeUser.getAuthDomain());
        assertEquals("", gaeUser.getFederatedIdentity());
        assertEquals("", gaeUser.getEmail());
View Full Code Here

Examples of com.google.appengine.api.users.UserService

        assertFalse(gaeUser.isAdmin());
    }

    /** Test doFilter() when the user is not logged in, with client roles set. */
    @Test public void testDoFilterAnonymousWithClientRoles() throws Exception {
        UserService userService = mock(UserService.class);
        AuthenticationManager authenticationManager = mock(AuthenticationManager.class);
        StubbedGaeAuthenticationFilter filter = new StubbedGaeAuthenticationFilter();

        filter.setUserService(userService);
        filter.setAuthenticationManager(authenticationManager);
        filter.afterPropertiesSet();

        when(authenticationManager.authenticate(isA(GaeUserAuthenticationToken.class))).thenAnswer(new AuthenticationAnswer());
        when(userService.isUserLoggedIn()).thenReturn(false);     // user is not logged in

        GaeUser gaeUser = callDoFilter(filter, "ONE");
        assertEquals("", gaeUser.getAuthDomain());
        assertEquals("", gaeUser.getFederatedIdentity());
        assertEquals("", gaeUser.getEmail());
View Full Code Here

Examples of com.google.appengine.api.users.UserService

        assertFalse(gaeUser.isAdmin());
    }

    /** Test doFilter() when the user is logged in and is not an admin user. */
    @Test public void testDoFilterLoggedIn() throws Exception {
        UserService userService = mock(UserService.class);
        AuthenticationManager authenticationManager = mock(AuthenticationManager.class);
        StubbedGaeAuthenticationFilter filter = new StubbedGaeAuthenticationFilter();

        filter.setUserService(userService);
        filter.setAuthenticationManager(authenticationManager);
        filter.afterPropertiesSet();

        User user = new User("email", "authDomain", "userId", "federatedIdentity");
        when(authenticationManager.authenticate(isA(GaeUserAuthenticationToken.class))).thenAnswer(new AuthenticationAnswer());
        when(userService.isUserLoggedIn()).thenReturn(true);      // user is logged in
        when(userService.isUserAdmin()).thenReturn(false);        // user is not an admin
        when(userService.getCurrentUser()).thenReturn(user);      // this is the logged in user

        GaeUser gaeUser = callDoFilter(filter)// no client roles
        assertEquals(user.getAuthDomain(), gaeUser.getAuthDomain());
        assertEquals(user.getFederatedIdentity(), gaeUser.getFederatedIdentity());
        assertEquals(user.getEmail(), gaeUser.getEmail());
View Full Code Here

Examples of com.google.appengine.api.users.UserService

        assertFalse(gaeUser.isAdmin());
    }

    /** Test doFilter() when the user is logged in and is not an admin user, with client roles. */
    @Test public void testDoFilterLoggedInWithClientRoles() throws Exception {
        UserService userService = mock(UserService.class);
        AuthenticationManager authenticationManager = mock(AuthenticationManager.class);
        StubbedGaeAuthenticationFilter filter = new StubbedGaeAuthenticationFilter();

        filter.setUserService(userService);
        filter.setAuthenticationManager(authenticationManager);
        filter.afterPropertiesSet();

        User user = new User("email", "authDomain", "userId", "federatedIdentity");
        when(authenticationManager.authenticate(isA(GaeUserAuthenticationToken.class))).thenAnswer(new AuthenticationAnswer());
        when(userService.isUserLoggedIn()).thenReturn(true);      // user is logged in
        when(userService.isUserAdmin()).thenReturn(false);        // user is not an admin
        when(userService.getCurrentUser()).thenReturn(user);      // this is the logged in user

        GaeUser gaeUser = callDoFilter(filter, "ONE");
        assertEquals(user.getAuthDomain(), gaeUser.getAuthDomain());
        assertEquals(user.getFederatedIdentity(), gaeUser.getFederatedIdentity());
        assertEquals(user.getEmail(), gaeUser.getEmail());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.