Search in sources :

Example 6 with User

use of com.google.appengine.api.users.User in project appengine-angular-guestbook-java by googlearchive.

the class Greeting method fromEntity.

public static Greeting fromEntity(Entity greetingEntity) {
    String author;
    User user = (User) greetingEntity.getProperty("user");
    if (user == null) {
        author = "an anonymous user";
    } else {
        author = user.getEmail();
    }
    return new Greeting((String) greetingEntity.getProperty("content"), (Date) greetingEntity.getProperty("date"), author);
}
Also used : User(com.google.appengine.api.users.User)

Example 7 with User

use of com.google.appengine.api.users.User in project appengine-guestbook-java by googlearchive.

the class SignGuestbookServletTest method testDoPost.

@Test
public void testDoPost() throws IOException, EntityNotFoundException {
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    String guestbookName = "TestGuestbook";
    String testContent = "Test Content";
    when(request.getParameter("guestbookName")).thenReturn(guestbookName);
    when(request.getParameter("content")).thenReturn(testContent);
    Date priorToRequest = new Date();
    signGuestbookServlet.doPost(request, response);
    Date afterRequest = new Date();
    verify(response).sendRedirect("/guestbook.jsp?guestbookName=TestGuestbook");
    User currentUser = UserServiceFactory.getUserService().getCurrentUser();
    Entity greeting = DatastoreServiceFactory.getDatastoreService().prepare(new Query()).asSingleEntity();
    assertEquals(guestbookName, greeting.getKey().getParent().getName());
    assertEquals(testContent, greeting.getProperty("content"));
    assertEquals(currentUser, greeting.getProperty("user"));
    Date date = (Date) greeting.getProperty("date");
    assertTrue("The date in the entity [" + date + "] is prior to the request being performed", priorToRequest.before(date) || priorToRequest.equals(date));
    assertTrue("The date in the entity [" + date + "] is after to the request completed", afterRequest.after(date) || afterRequest.equals(date));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Entity(com.google.appengine.api.datastore.Entity) User(com.google.appengine.api.users.User) Query(com.google.appengine.api.datastore.Query) HttpServletResponse(javax.servlet.http.HttpServletResponse) Date(java.util.Date) Test(org.junit.Test)

Example 8 with User

use of com.google.appengine.api.users.User in project spring-security by spring-projects.

the class GoogleAccountsAuthenticationProvider method authenticate.

public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    User googleUser = (User) authentication.getPrincipal();
    GaeUser user = userRegistry.findUser(googleUser.getUserId());
    if (user == null) {
        // User not in registry. Needs to register
        user = new GaeUser(googleUser.getUserId(), googleUser.getNickname(), googleUser.getEmail());
    }
    if (!user.isEnabled()) {
        throw new DisabledException("Account is disabled");
    }
    return new GaeUserAuthentication(user, authentication.getDetails());
}
Also used : GaeUser(samples.gae.users.GaeUser) User(com.google.appengine.api.users.User) DisabledException(org.springframework.security.authentication.DisabledException) GaeUser(samples.gae.users.GaeUser)

Aggregations

User (com.google.appengine.api.users.User)8 UserService (com.google.appengine.api.users.UserService)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Entity (com.google.appengine.api.datastore.Entity)2 Date (java.util.Date)2 Test (org.junit.Test)2 GaeUser (samples.gae.users.GaeUser)2 DatastoreService (com.google.appengine.api.datastore.DatastoreService)1 Key (com.google.appengine.api.datastore.Key)1 Query (com.google.appengine.api.datastore.Query)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Properties (java.util.Properties)1 DisabledException (org.springframework.security.authentication.DisabledException)1 Authentication (org.springframework.security.core.Authentication)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)1