use of org.apache.openmeetings.db.dto.user.OAuthUser in project openmeetings by apache.
the class MobileService method loginGoogle.
public Map<String, Object> loginGoogle(Map<String, String> umap) {
Map<String, Object> result = getResult();
try {
if (cfgDao.getBool(CONFIG_REGISTER_OAUTH, false)) {
// TODO hardcoded
User u = userManager.loginOAuth(new OAuthUser(umap), 2);
result = login(u, result);
}
} catch (Exception e) {
log.error("[loginGoogle]", e);
}
return result;
}
use of org.apache.openmeetings.db.dto.user.OAuthUser in project openmeetings by apache.
the class SignInPage method getAuthParams.
private OAuthUser getAuthParams(String token, String code, OAuthServer server) throws IOException {
// prepare url
String requestInfoUrl = server.getRequestInfoUrl();
requestInfoUrl = prepareUrlParams(requestInfoUrl, server.getClientId(), getRedirectUri(server), server.getClientSecret(), token, code);
// send request
URLConnection connection = new URL(requestInfoUrl).openConnection();
prepareConnection(connection);
String sourceResponse = IOUtils.toString(connection.getInputStream(), UTF_8);
// parse json result
return new OAuthUser(sourceResponse, server);
}
use of org.apache.openmeetings.db.dto.user.OAuthUser in project openmeetings by apache.
the class UserManager method loginOAuth.
@Override
public User loginOAuth(OAuthUser user, long serverId) throws IOException, NoSuchAlgorithmException {
if (!userDao.validLogin(user.getUid())) {
log.error("Invalid login, please check parameters");
return null;
}
User u = userDao.getByLogin(user.getUid(), Type.oauth, serverId);
if (!userDao.checkEmail(user.getEmail(), Type.oauth, serverId, u == null ? null : u.getId())) {
log.error("Another user with the same email exists");
return null;
}
// generate random password
SecureRandom rnd = new SecureRandom();
byte[] rawPass = new byte[25];
rnd.nextBytes(rawPass);
String pass = Base64.encodeBase64String(rawPass);
// check if the user already exists and register new one if it's needed
if (u == null) {
u = userDao.getNewUserInstance(null);
u.setType(Type.oauth);
u.getRights().remove(Right.Login);
u.setDomainId(serverId);
u.getGroupUsers().add(new GroupUser(groupDao.get(cfgDao.getLong(CONFIG_DEFAULT_GROUP_ID, null)), u));
u.setLogin(user.getUid());
u.setShowContactDataToContacts(true);
u.setLastname(user.getLastName());
u.setFirstname(user.getFirstName());
u.getAddress().setEmail(user.getEmail());
String picture = user.getPicture();
if (picture != null) {
u.setPictureuri(picture);
}
String locale = user.getLocale();
if (locale != null) {
Locale loc = Locale.forLanguageTag(locale);
if (loc != null) {
u.setLanguageId(getLanguage(loc));
u.getAddress().setCountry(loc.getCountry());
}
}
}
u.setLastlogin(new Date());
u = userDao.update(u, pass, Long.valueOf(-1));
return u;
}
Aggregations