Search in sources :

Example 16 with User

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;
    }
}
Also used : User(com.google.appengine.api.users.User) UserService(com.google.appengine.api.users.UserService)

Example 17 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)

Example 18 with User

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;
}
Also used : User(com.google.appengine.api.users.User) Document(com.google.appengine.api.search.Document) Date(java.util.Date)

Example 19 with User

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);
}
Also used : User(com.google.appengine.api.users.User) UserService(com.google.appengine.api.users.UserService)

Example 20 with User

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());
}
Also used : OAuthService(com.google.appengine.api.oauth.OAuthService) User(com.google.appengine.api.users.User) OAuthRequestException(com.google.appengine.api.oauth.OAuthRequestException) PrintWriter(java.io.PrintWriter)

Aggregations

User (com.google.appengine.api.users.User)24 UserService (com.google.appengine.api.users.UserService)8 HashMap (java.util.HashMap)4 Date (java.util.Date)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Entity (com.google.appengine.api.datastore.Entity)2 Pusher (com.pusher.rest.Pusher)2 PresenceUser (com.pusher.rest.data.PresenceUser)2 Result (com.pusher.rest.data.Result)2 PrintWriter (java.io.PrintWriter)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 OAuthRequestException (com.google.appengine.api.oauth.OAuthRequestException)1 OAuthService (com.google.appengine.api.oauth.OAuthService)1 Document (com.google.appengine.api.search.Document)1 StringWriter (java.io.StringWriter)1