Package com.google.appengine.api.users

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


   */
  private static final long serialVersionUID = -4322706551142570325L;

  protected User getUsuario(){
   
    UserService userService = UserServiceFactory.getUserService();
   
    return userService.getCurrentUser();
   
  }
View Full Code Here


    /** Test constructor, getters and setters. */
    @Test public void testConstructor() {
        GaeUserService service = new GaeUserService();
        assertNull(service.getUserService());

        UserService userService = mock(UserService.class);
        service.setUserService(userService);
        assertSame(userService, service.getUserService());

        SpringContextService springContextService = mock(SpringContextService.class);
        service.setSpringContextService(springContextService);
View Full Code Here

    }

    /** Test the afterPropertiesSet() method. */
    @Test public void testAfterPropertiesSet() throws Exception {
        GaeUserService service = new GaeUserService();
        UserService userService = mock(UserService.class);
        SpringContextService springContextService = mock(SpringContextService.class);

        try {
            service.setUserService(userService);
            service.setSpringContextService(null);
View Full Code Here

        String expected = loginUrl;         // we won't do any translation

        String providerUrl = GaeUserService.deriveOpenIdProviderUrl(OpenIdProvider.MYOPENID);
        Set<String> attributes = new HashSet<String>();

        UserService userService = mock(UserService.class);
        SpringContextService springContextService = mock(SpringContextService.class);
        GaeUserService service = new GaeUserService();
        service.setUserService(userService);
        service.setSpringContextService(springContextService);
        service.afterPropertiesSet();

        when(userService.createLoginURL(destinationUrl, null, providerUrl, attributes)).thenReturn(loginUrl);
        assertEquals(expected, service.getLoginUrl(OpenIdProvider.MYOPENID, destinationUrl));
    }
View Full Code Here

        String expected = loginUrl;                       // but we can't fix it for this provider

        String providerUrl = GaeUserService.deriveOpenIdProviderUrl(OpenIdProvider.MYOPENID);
        Set<String> attributes = new HashSet<String>();

        UserService userService = mock(UserService.class);
        SpringContextService springContextService = mock(SpringContextService.class);
        GaeUserService service = new GaeUserService();
        service.setUserService(userService);
        service.setSpringContextService(springContextService);
        service.afterPropertiesSet();

        when(userService.createLoginURL(destinationUrl, null, providerUrl, attributes)).thenReturn(loginUrl);
        assertEquals(expected, service.getLoginUrl(OpenIdProvider.MYOPENID, destinationUrl));
    }
View Full Code Here

    /** Test getLogoutUrl(). */
    @Test public void testGetLogoutUrl() {
        String logoutUrl = "logoutUrl";
        String destinationUrl = "destinationUrl";

        UserService userService = mock(UserService.class);
        SpringContextService springContextService = mock(SpringContextService.class);
        GaeUserService service = new GaeUserService();
        service.setUserService(userService);
        service.setSpringContextService(springContextService);
        service.afterPropertiesSet();

        when(userService.createLogoutURL(destinationUrl)).thenReturn(logoutUrl);
        assertEquals(logoutUrl, service.getLogoutUrl(destinationUrl));
    }
View Full Code Here

        assertEquals(logoutUrl, service.getLogoutUrl(destinationUrl));
    }

    /** Test isUserLoggedIn(). */
    @Test public void testIsUserLoggedIn() {
        UserService userService = mock(UserService.class);
        SpringContextService springContextService = mock(SpringContextService.class);
        GaeUserService service = new GaeUserService();
        service.setUserService(userService);
        service.setSpringContextService(springContextService);
        service.afterPropertiesSet();

        when(userService.isUserLoggedIn()).thenReturn(true);
        assertTrue(service.isUserLoggedIn());

        when(userService.isUserLoggedIn()).thenReturn(false);
        assertFalse(service.isUserLoggedIn());
    }
View Full Code Here

        assertFalse(service.isUserLoggedIn());
    }

    /** Test isUserAdmin(). */
    @Test public void testIsUserAdmin() {
        UserService userService = mock(UserService.class);
        SpringContextService springContextService = mock(SpringContextService.class);
        GaeUserService service = new GaeUserService();
        service.setUserService(userService);
        service.setSpringContextService(springContextService);
        service.afterPropertiesSet();

        when(userService.isUserAdmin()).thenReturn(true);
        assertTrue(service.isUserAdmin());

        when(userService.isUserAdmin()).thenReturn(false);
        assertFalse(service.isUserAdmin());
    }
View Full Code Here

    }

    /** Test getCurrentUser(). */
    @Test public void testGetCurrentUser() {
        User user = new User("email", "google.com", "userId", "federatedIdentity");
        UserService userService = mock(UserService.class);
        SpringContextService springContextService = mock(SpringContextService.class);
        GaeUserService service = new GaeUserService();
        service.setUserService(userService);
        service.setSpringContextService(springContextService);
        service.afterPropertiesSet();

        when(userService.isUserLoggedIn()).thenReturn(false);
        FederatedUser currentUser = service.getCurrentUser();
        assertNull(currentUser);

        when(userService.isUserLoggedIn()).thenReturn(true);
        when(userService.getCurrentUser()).thenReturn(user);
        when(userService.isUserAdmin()).thenReturn(true);

        currentUser = service.getCurrentUser();
        assertEquals(user.getEmail(), currentUser.getEmailAddress());
        assertEquals(user.getAuthDomain(), currentUser.getAuthenticationDomain());
        assertEquals(OpenIdProvider.GOOGLE, currentUser.getOpenIdProvider())// because auth domain is "google.com"
        assertEquals(user.getUserId(), currentUser.getUserId());
        assertEquals(user.getFederatedIdentity(), currentUser.getFederatedIdentity());
        assertTrue(currentUser.isAdmin());

        when(userService.isUserLoggedIn()).thenReturn(true);
        when(userService.getCurrentUser()).thenReturn(user);
        when(userService.isUserAdmin()).thenReturn(false);

        currentUser = service.getCurrentUser();
        assertEquals(user.getEmail(), currentUser.getEmailAddress());
        assertEquals(user.getAuthDomain(), currentUser.getAuthenticationDomain());
        assertEquals(OpenIdProvider.GOOGLE, currentUser.getOpenIdProvider())// because auth domain is "google.com"
View Full Code Here

  /* (non-Javadoc)
   * @see com.google.gwt.maeglin89273.game.ashinyballonthecross.shared.PlayerService#getLoginInfo(java.lang.String)
   */
  @Override
  public CheckLoginResponse checkLogin(CheckLoginRequest request) {
    UserService svc=getUserService();
    User user=svc.getCurrentUser();
    LoginInfo loginInfo;
    CheckLoginResponse response;
   
    if(user!=null){
      loginInfo=new LoginInfo(LoginInfo.Status.LOGGED_IN,svc.createLogoutURL(request.getRquestUrl()),new GoogleAccount(user.getEmail(),user.getNickname()));
      DatastoreService datastore=getDatastoreService();
      TransportablePlayer localPlayer=request.getLocalPlayer();
      Key key=KeyFactory.createKey(Player.class.getSimpleName(), user.getEmail());
      String keyString=KeyFactory.keyToString(key);
     
      try{
        Entity player=datastore.get(key);
       
        if(localPlayer.getID().equals(player.getProperty(TransportablePlayer.ID_PROPERTY))){
          //the achievement has changed
          if(!player.getProperty(TransportablePlayer.ACHIEVEMENT_PROPERTY).equals(localPlayer.getEncryptedAchievements())){
            //if the date is greater than client timestamp, do download. Else, do upload
            if(localPlayer.getTimestamp()!=null&&((Date)player.getProperty(TransportablePlayer.DATE_PROPERTY)).compareTo(localPlayer.getTimestamp())>0){
              //do download
              response=doDownload(player,loginInfo,keyString);
            }else{
              //do upload
              response=doUpload(datastore, player, loginInfo, keyString, localPlayer);
            }
          }else{
            //local player patch
            if(localPlayer.getTimestamp()==null){
              localPlayer.setTimestamp((Date)player.getProperty(TransportablePlayer.DATE_PROPERTY));
            }
            localPlayer.setKey(keyString);
            response=new CheckLoginResponse(Status.UPLOAD,loginInfo,localPlayer);
          }
        }else{
          //do download
          response=doDownload(player,loginInfo,keyString);
        }
      }catch(EntityNotFoundException e){
        //request to create a new player
        response=requestNewPlayer(keyString, loginInfo, localPlayer);
      }
     
    }else{
      loginInfo=new LoginInfo(LoginInfo.Status.LOGGED_OUT, svc.createLoginURL(request.getRquestUrl()));
      response=new CheckLoginResponse(Status.NOT_LOGGED_IN,loginInfo,null);
    }
    return response;
  }
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.