Search in sources :

Example 11 with Userinfo

use of com.google.api.services.oauth2.model.Userinfo in project hale by halestudio.

the class HaleConnectServiceImpl method getUserInfo.

/**
 * @see eu.esdihumboldt.hale.io.haleconnect.HaleConnectService#getUserInfo(java.lang.String)
 */
@Override
public HaleConnectUserInfo getUserInfo(String userId) throws HaleConnectException {
    if (!this.isLoggedIn()) {
        return null;
    }
    if (!userInfoCache.containsKey(userId)) {
        UsersApi api = UserServiceHelper.getUsersApi(this, this.getSession().getToken());
        try {
            UserInfo info = api.getProfile(userId);
            userInfoCache.put(info.getId(), new HaleConnectUserInfo(info.getId(), info.getScreenName(), info.getFullName()));
        } catch (ApiException e) {
            throw new HaleConnectException(e.getMessage(), e);
        }
    }
    return userInfoCache.get(userId);
}
Also used : UsersApi(com.haleconnect.api.user.v1.api.UsersApi) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) UserInfo(com.haleconnect.api.user.v1.model.UserInfo) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) ApiException(com.haleconnect.api.user.v1.ApiException)

Example 12 with Userinfo

use of com.google.api.services.oauth2.model.Userinfo in project be5 by DevelopmentOnTheEdge.

the class LoginServiceImpl method saveUser.

@Override
public void saveUser(String username, Request req) {
    List<String> availableRoles = selectAvailableRoles(username);
    if (ModuleLoader2.getDevRoles().size() > 0) {
        availableRoles.addAll(ModuleLoader2.getDevRoles());
    }
    String savedRoles = coreUtils.getUserSetting(username, DatabaseConstants.CURRENT_ROLE_LIST);
    List<String> currentRoles;
    if (savedRoles != null) {
        currentRoles = parseRoles(savedRoles);
    } else {
        currentRoles = availableRoles;
    }
    UserInfo ui = userHelper.saveUser(username, availableRoles, currentRoles, req.getLocale(), req.getRemoteAddr(), req.getSession());
    Session session = req.getSession();
    session.set("remoteAddr", req.getRemoteAddr());
    session.set(SessionConstants.USER_INFO, ui);
    session.set(SessionConstants.CURRENT_USER, ui.getUserName());
    log.fine("Login user: " + username);
}
Also used : UserInfo(com.developmentontheedge.be5.model.UserInfo) Session(com.developmentontheedge.be5.api.Session)

Example 13 with Userinfo

use of com.google.api.services.oauth2.model.Userinfo in project be5 by DevelopmentOnTheEdge.

the class UserHelper method saveUser.

public UserInfo saveUser(String userName, List<String> availableRoles, List<String> currentRoles, Locale locale, String remoteAddr, Session session) {
    UserInfo ui = new UserInfo(userName, availableRoles, currentRoles, session);
    ui.setRemoteAddr(remoteAddr);
    ui.setLocale(meta.getLocale(locale));
    UserInfoHolder.setUserInfo(ui);
    return ui;
}
Also used : UserInfo(com.developmentontheedge.be5.model.UserInfo)

Example 14 with Userinfo

use of com.google.api.services.oauth2.model.Userinfo in project google-cloud-intellij by GoogleCloudPlatform.

the class GoogleLoginUtils method getUserInfo.

/**
 * Sets the user info on the callback.
 */
@SuppressWarnings("FutureReturnValueIgnored")
public static void getUserInfo(@NotNull final Credential credential, final IUserPropertyCallback<Userinfoplus> callback) {
    final Oauth2 userInfoService = new Oauth2.Builder(new NetHttpTransport(), new JacksonFactory(), credential).setApplicationName(ServiceManager.getService(PluginInfoService.class).getUserAgent()).build();
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        Userinfoplus userInfo = null;
        try {
            userInfo = userInfoService.userinfo().get().execute();
        } catch (IOException ex) {
            // The core IDE functionality still works, so this does
            // not affect anything right now. The user will receive
            // error messages when they attempt to do something that
            // requires a logged in state.
            LOG.warn("Error retrieving user information.", ex);
        }
        if (userInfo != null && userInfo.getId() != null) {
            callback.setProperty(userInfo);
        } else {
            callback.setProperty(null);
        }
    });
}
Also used : Userinfoplus(com.google.api.services.oauth2.model.Userinfoplus) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) Oauth2(com.google.api.services.oauth2.Oauth2) PluginInfoService(com.google.cloud.tools.intellij.service.PluginInfoService) IOException(java.io.IOException) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory)

Example 15 with Userinfo

use of com.google.api.services.oauth2.model.Userinfo in project workbench by all-of-us.

the class AuthInterceptorTest method preHandleGet_noUserRecord.

@Test
public void preHandleGet_noUserRecord() throws Exception {
    when(handler.getMethod()).thenReturn(getProfileApiMethod("getBillingProjects"));
    when(request.getMethod()).thenReturn(HttpMethods.GET);
    when(request.getHeader(HttpHeaders.AUTHORIZATION)).thenReturn("Bearer foo");
    Userinfoplus userInfo = new Userinfoplus();
    userInfo.setGivenName("Bob");
    userInfo.setFamilyName("Jones");
    userInfo.setEmail("bob@fake-domain.org");
    when(userInfoService.getUserInfo("foo")).thenReturn(userInfo);
    when(userDao.findUserByEmail("bob@fake-domain.org")).thenReturn(null);
    when(userService.createUser("Bob", "Jones", "bob@fake-domain.org", null)).thenReturn(user);
    assertThat(interceptor.preHandle(request, response, handler)).isTrue();
}
Also used : Userinfoplus(com.google.api.services.oauth2.model.Userinfoplus) Test(org.junit.Test)

Aggregations

Userinfo (com.google.api.services.oauth2.model.Userinfo)10 Oauth2 (com.google.api.services.oauth2.Oauth2)8 Userinfoplus (com.google.api.services.oauth2.model.Userinfoplus)6 IOException (java.io.IOException)5 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)4 UserInfo (com.developmentontheedge.be5.model.UserInfo)3 Credential (com.google.api.client.auth.oauth2.Credential)3 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)3 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)3 UserInfo (org.alfresco.repo.event.v1.model.UserInfo)3 JsonObject (com.google.gson.JsonObject)2 CustomWebApplicationException (io.dockstore.webservice.CustomWebApplicationException)2 Test (org.junit.jupiter.api.Test)2 FirecloudMe (org.pmiops.workbench.firecloud.model.FirecloudMe)2 FirecloudUserInfo (org.pmiops.workbench.firecloud.model.FirecloudUserInfo)2 Timed (com.codahale.metrics.annotation.Timed)1 Session (com.developmentontheedge.be5.api.Session)1 JsonView (com.fasterxml.jackson.annotation.JsonView)1 ForIntent (com.google.actions.api.ForIntent)1 TransactionDecision (com.google.actions.api.response.helperintent.transactions.v3.TransactionDecision)1