Package com.google.appengine.api.users

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


        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

        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

        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

        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

        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

        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

        assertFalse(gaeUser.isAdmin());
    }

    /** Test doFilter() when the user is logged in and is an admin user. */
    @Test public void testDoFilterAdmin() 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(true);         // user is 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

        assertTrue(gaeUser.isAdmin());
    }

    /** Test doFilter() when the user is logged in and is an admin user, with client roles. */
    @Test public void testDoFilterAdminWithClientRoles() 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(true);         // user is 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

    private TwitterService service = new TwitterService();

    @Override
    public Navigation run() throws Exception {
        // check login
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        if (!userService.isUserLoggedIn()) { // not login
            return redirect(userService.createLoginURL(request.getRequestURI()));
        } else {
            List<Tweet> tweetList = service.getTweetList();
            requestScope("tweetList", tweetList);
            requestScope("myEmail", user.getEmail());
            requestScope("myNickname", user.getNickname());
            requestScope("myIsAdmin", userService.isUserAdmin());
            return forward("index.jsp");
        }
    }
View Full Code Here

TOP

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

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.