Search in sources :

Example 1 with OAuthUser

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;
}
Also used : User(org.apache.openmeetings.db.entity.user.User) OAuthUser(org.apache.openmeetings.db.dto.user.OAuthUser) OAuthUser(org.apache.openmeetings.db.dto.user.OAuthUser) OmException(org.apache.openmeetings.util.OmException)

Example 2 with OAuthUser

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);
}
Also used : OAuthUser(org.apache.openmeetings.db.dto.user.OAuthUser) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) URL(java.net.URL)

Example 3 with OAuthUser

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;
}
Also used : Locale(java.util.Locale) User(org.apache.openmeetings.db.entity.user.User) OAuthUser(org.apache.openmeetings.db.dto.user.OAuthUser) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) SecureRandom(java.security.SecureRandom) Date(java.util.Date)

Aggregations

OAuthUser (org.apache.openmeetings.db.dto.user.OAuthUser)3 User (org.apache.openmeetings.db.entity.user.User)2 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 SecureRandom (java.security.SecureRandom)1 Date (java.util.Date)1 Locale (java.util.Locale)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1 GroupUser (org.apache.openmeetings.db.entity.user.GroupUser)1 OmException (org.apache.openmeetings.util.OmException)1