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