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);
}
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));
}
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());
}
Aggregations