Package com.google.appengine.api.users

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


  public void ajaxUnsubscribe(HttpServletRequest req,
      HttpServletResponse resp, long id) throws Exception {
    System.out.println(id);

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    if (user != null) {

      UserManager serv = new UserManager();
      serv.removeUserSubscription(user.getEmail(), id);
      resp.getWriter().write("OK");

    } else {
      throw new Exception("no user");
    }
View Full Code Here


    email = req.getParameter("jid");
   
    if (email == null){
   
      UserService userService = UserServiceFactory.getUserService();
      User user = userService.getCurrentUser();
     
      if (user != null) {
        email = user.getEmail();
        method = "gtalk";
      } else {
        //redirection
        resp.sendRedirect(userService.createLoginURL("/inviteme.htm"));
        return null;
View Full Code Here

    private static User getCurrentUser() {
        return UserServiceFactory.getUserService().getCurrentUser();
    }
   
    public static String getUserId() {
        User user = getCurrentUser();
        return user == null ? null : user.getUserId();
    }
View Full Code Here

        User user = getCurrentUser();
        return user == null ? null : user.getUserId();
    }
   
    public static String getUserEmail() {
        User user = getCurrentUser();
        return user == null ? null : user.getEmail();
    }
View Full Code Here

      return new EvaluationResult(null).withWarning(ErrorCode.W120);
    } else if (this.ops.size() == 1) {
      EvaluationResult r = this.ops.get(0).evaluate(record);
      if (r.getPayload() instanceof String) {         
        return new EvaluationResult(
            new User((String) r.getPayload(), SharedConstants.User.DEFAULT_AUTH_DOMAIN), r);
      } else {
        return r.withWarning(ErrorCode.W121);
      }
    } else if (this.ops.size() == 2) {
      EvaluationResult r0 = this.ops.get(0).evaluate(record);
      EvaluationResult r1 = this.ops.get(1).evaluate(record);
      if (r0.getPayload() instanceof String && r1.getPayload() instanceof String) {
        String email = (String)r0.getPayload();
        String authDomain = (String)r1.getPayload();
        return new EvaluationResult(new User(email, authDomain), r0, r1);
      } else {
        return r1.withWarning(ErrorCode.W121);
      }
    } else {
      return this.ops.get(0).evaluate(record).withWarning(ErrorCode.W120);
View Full Code Here

   * Retrieves the currently signed on user.
   */
  @Override
  public DocumentUser getUser() {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null){
      String email = user.getEmail();
      AuthenticationToken at = AuthenticationToken.getUserToken(email);
      if (at != null) {
        DocumentUser docUser = new DocumentUser();
        docUser.setToken(at.getPublicToken());
        docUser.setName(user.getNickname());
        docUser.setEmail(user.getEmail());
        docUser.setId(user.getUserId());
        return docUser;
      }
    }
    return null;
  }
View Full Code Here

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        // Always get the current user from the GAE back-end regardless of our existing context
        GaeUser gaeUser = new GaeUser(); // anonymous by default
        if (this.userService.isUserLoggedIn()) {
            User user = this.userService.getCurrentUser();
            boolean admin = this.userService.isUserAdmin();
            String[] clientRoles = this.getSessionAttribute(request, CLIENT_ROLES_ATTRIBUTE);
            gaeUser.initializeCredentials(user, admin, clientRoles);
        }
View Full Code Here

        assertFalse(gaeUser.isAdmin());
    }

    /** Test initializeCredentials(). */
    @Test public void testInitializeCredentials() {
        User user = new User("email", "authDomain", "userId", "federatedIdentity");

        GaeUser gaeUser = new GaeUser();
        gaeUser.initializeCredentials(user, false, null);
        assertNotNull(gaeUser);
        assertEquals(user.getAuthDomain(), gaeUser.getAuthDomain());
        assertEquals(user.getFederatedIdentity(), gaeUser.getFederatedIdentity());
        assertEquals(user.getEmail(), gaeUser.getEmail());
        assertEquals(user.getUserId(), gaeUser.getUserId());
        assertEquals(2, gaeUser.getRoles().size());
        assertTrue(gaeUser.getRoles().contains(GaeRole.ROLE_ANONYMOUS));
        assertTrue(gaeUser.getRoles().contains(GaeRole.ROLE_USER));
        assertEquals(2, gaeUser.getAuthorities().length);
        assertContains(GaeRole.ROLE_ANONYMOUS, gaeUser.getAuthorities());
        assertContains(GaeRole.ROLE_USER, gaeUser.getAuthorities());
        assertNotNull(gaeUser.toString());
        assertFalse(gaeUser.isAnonymous());
        assertFalse(gaeUser.isAdmin());

        gaeUser = new GaeUser();
        gaeUser.initializeCredentials(user, true, null);
        assertNotNull(gaeUser);
        assertEquals(user.getAuthDomain(), gaeUser.getAuthDomain());
        assertEquals(user.getFederatedIdentity(), gaeUser.getFederatedIdentity());
        assertEquals(user.getEmail(), gaeUser.getEmail());
        assertEquals(user.getUserId(), gaeUser.getUserId());
        assertEquals(3, gaeUser.getRoles().size());
        assertTrue(gaeUser.getRoles().contains(GaeRole.ROLE_ANONYMOUS));
        assertTrue(gaeUser.getRoles().contains(GaeRole.ROLE_USER));
        assertTrue(gaeUser.getRoles().contains(GaeRole.ROLE_ADMIN));
        assertEquals(3, gaeUser.getAuthorities().length);
        assertContains(GaeRole.ROLE_ANONYMOUS, gaeUser.getAuthorities());
        assertContains(GaeRole.ROLE_USER, gaeUser.getAuthorities());
        assertContains(GaeRole.ROLE_ADMIN, gaeUser.getAuthorities());
        assertNotNull(gaeUser.toString());
        assertFalse(gaeUser.isAnonymous());
        assertTrue(gaeUser.isAdmin());

        gaeUser = new GaeUser();
        gaeUser.initializeCredentials(user, true, new String[] { "ONE", "TWO", });
        assertNotNull(gaeUser);
        assertEquals(user.getAuthDomain(), gaeUser.getAuthDomain());
        assertEquals(user.getFederatedIdentity(), gaeUser.getFederatedIdentity());
        assertEquals(user.getEmail(), gaeUser.getEmail());
        assertEquals(user.getUserId(), gaeUser.getUserId());
        assertEquals(5, gaeUser.getRoles().size());
        assertTrue(gaeUser.getRoles().contains(GaeRole.ROLE_ANONYMOUS));
        assertTrue(gaeUser.getRoles().contains(GaeRole.ROLE_USER));
        assertTrue(gaeUser.getRoles().contains(GaeRole.ROLE_ADMIN));
        assertTrue(gaeUser.getRoles().contains(new GaeRole("ONE")));
View Full Code Here

        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());
        assertEquals(user.getUserId(), gaeUser.getUserId());
        assertTrue(gaeUser.getRoles().contains(GaeRole.ROLE_ANONYMOUS));
        assertTrue(gaeUser.getRoles().contains(GaeRole.ROLE_USER));
        assertFalse(gaeUser.getRoles().contains(GaeRole.ROLE_ADMIN));
        assertFalse(gaeUser.isAnonymous());
        assertFalse(gaeUser.isAdmin());
View Full Code Here

        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());
        assertEquals(user.getUserId(), gaeUser.getUserId());
        assertTrue(gaeUser.getRoles().contains(GaeRole.ROLE_ANONYMOUS));
        assertTrue(gaeUser.getRoles().contains(GaeRole.ROLE_USER));
        assertFalse(gaeUser.getRoles().contains(GaeRole.ROLE_ADMIN));
        assertTrue(gaeUser.getRoles().contains(new GaeRole("ONE")));
        assertFalse(gaeUser.isAnonymous());
View Full Code Here

TOP

Related Classes of com.google.appengine.api.users.User

Copyright © 2018 www.massapicom. 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.