use of com.google.appengine.api.users.User in project iosched by google.
the class BaseServlet method checkUser.
protected boolean checkUser() {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String authDomain = user.getAuthDomain();
if (authDomain.contains("google.com")) {
return true;
} else {
return false;
}
}
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());
}
use of com.google.appengine.api.users.User in project java-docs-samples by GoogleCloudPlatform.
the class DocumentServlet method createDocument.
/**
* Code snippet for creating a Document.
* @return Document Created document.
*/
public Document createDocument() {
// [START create_document]
User currentUser = UserServiceFactory.getUserService().getCurrentUser();
String userEmail = currentUser == null ? "" : currentUser.getEmail();
String userDomain = currentUser == null ? "" : currentUser.getAuthDomain();
String myDocId = "PA6-5000";
Document doc = Document.newBuilder().setId(myDocId).addField(Field.newBuilder().setName("content").setText("the rain in spain")).addField(Field.newBuilder().setName("email").setText(userEmail)).addField(Field.newBuilder().setName("domain").setAtom(userDomain)).addField(Field.newBuilder().setName("published").setDate(new Date())).build();
// [END create_document]
return doc;
}
use of com.google.appengine.api.users.User in project java-docs-samples by GoogleCloudPlatform.
the class SignGuestbookServlet method doPost.
// Process the http POST of the form
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
Greeting greeting;
UserService userService = UserServiceFactory.getUserService();
// Find out who the user is.
User user = userService.getCurrentUser();
String guestbookName = req.getParameter("guestbookName");
String content = req.getParameter("content");
if (user != null) {
greeting = new Greeting(guestbookName, content, user.getUserId(), user.getEmail());
} else {
greeting = new Greeting(guestbookName, content);
}
// Use Objectify to save the greeting and now() is used to make the call synchronously as we
// will immediately get a new page using redirect and we want the data to be present.
ObjectifyService.ofy().save().entity(greeting).now();
resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName);
}
use of com.google.appengine.api.users.User in project java-docs-samples by GoogleCloudPlatform.
the class HelloServlet method doPost.
@Override
public void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
PrintWriter out = resp.getWriter();
final String scope = "https://www.googleapis.com/auth/userinfo.email";
OAuthService oauth = OAuthServiceFactory.getOAuthService();
User user = null;
try {
user = oauth.getCurrentUser(scope);
} catch (OAuthRequestException e) {
getServletContext().log("Oauth error", e);
out.print("auth error");
return;
}
out.print("Hello world, welcome to Oauth2: " + user.getEmail());
}
Aggregations