JHipster, Spring Social & Principal

夙愿已清 提交于 2019-12-11 09:05:45

问题


Dears,

I have generated an app thanks to jHipster. However, in order to be sure that I map social profiles with local accounts, I want users to sign up their social accounts once connected only. Social Connection must be optional (users' convenience).

In brief, I want to use JWT tokens to sign up social profiles and either JWT or oAuth to signin when activated.

Technically, I thought I just had to enhance the code of both SocialUser and SocialService to match ProfileInfo (from social authentication response) to the local user login info.

Unfortunately, the social service doesn't return any authentication info (from Spring Security)and I cannot retrieve Principal.

Any idea which may help?

Sample code:

// Find user within the social repository thanks to his userId
    if (StringUtils.isBlank(email) && !StringUtils.isBlank(usrId)) {
        Optional<SocialUser> sUser = suDao.findOneByUsrId(usrId);
        if (sUser.isPresent()) {
            // Retrieve corresponding user
            return Optional.of(sUser.get().getUser());
        } else {
            // Create Social User
            Optional<User> oUsr = uDao.findOneByUsername(SecurityUtils.getCurrentUserLogin());
            if (oUsr.isPresent()) {
                User u = oUsr.get();
                SocialUser su = new  SocialUser(u.getExternalId(), usrId, providerId, u);
                suDao.save(su);
                log.debug("Creating social user for: {}", u);
            } 
        }
    }

来源:https://stackoverflow.com/questions/45757438/jhipster-spring-social-principal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!