Java Code Examples for org.springframework.social.connect.Connection#fetchUserProfile()

The following examples show how to use org.springframework.social.connect.Connection#fetchUserProfile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SocialAuthenticationUtils.java    From Spring-Security-Third-Edition with MIT License 6 votes vote down vote up
public static CalendarUser createCalendarUserFromProvider(Connection<?> connection){
    // TODO: FIXME: Need to put this into a Utility:
    UserProfile profile = connection.fetchUserProfile();

    CalendarUser user = new CalendarUser();

    if(profile.getEmail() != null){
        user.setEmail(profile.getEmail());
    }
    else if(profile.getUsername() != null){
        user.setEmail(profile.getUsername());
    }
    else {
        user.setEmail(connection.getDisplayName());
    }

    user.setFirstName(profile.getFirstName());
    user.setLastName(profile.getLastName());

    user.setPassword(randomAlphabetic(32));

    return user;

}
 
Example 2
Source File: OAuth2CloudstreetController.java    From cloudstreetmarket.com with GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping(value="/signup", method = RequestMethod.GET)
public String getForm(NativeWebRequest request,  @ModelAttribute User user) {
	String view = successView;

	// check if this is a new user signing in via Spring Social
    Connection<?> connection = providerSignInUtils.getConnectionFromSession(request);
    if (connection != null) {
        // populate new User from social connection user profile
        UserProfile userProfile = connection.fetchUserProfile();
        user.setId(userProfile.getUsername());

        // finish social signup/login
        providerSignInUtils.doPostSignUp(user.getUsername(), request);

        // sign the user in and send them to the user home page
        signInAdapter.signIn(user.getUsername(), connection, request);
		view += "?spi="+ user.getUsername();
    }
    
    return view;
}
 
Example 3
Source File: SpringSocialTokenServices.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Override
public OAuth2Authentication loadAuthentication(String accessToken)
		throws AuthenticationException, InvalidTokenException {
	AccessGrant accessGrant = new AccessGrant(accessToken);
	Connection<?> connection = this.connectionFactory.createConnection(accessGrant);
	UserProfile user = connection.fetchUserProfile();
	return extractAuthentication(user);
}
 
Example 4
Source File: SocialAuthenticationUtils.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
public static CalendarUser createCalendarUserFromProvider(Connection<?> connection){

        // TODO: There is a defect with Facebook:
        // org.springframework.social.UncategorizedApiException: (#12) bio field is
        // deprecated for versions v2.8 and higher:
//
//        Connection<Facebook> connection = facebookConnectionFactory.createConnection(accessGrant);
//        Facebook facebook = connection.getApi();
//        String [] fields = { "id", "email",  "first_name", "last_name" };
//        User userProfile = facebook.fetchObject("me", User.class, fields);
//
//        Object api = connection.getApi();
//        if(api instanceof FacebookTemplate){
//            System.out.println("Facebook");
//        }


        // Does not work with spring-social-facebook:2.0.3.RELEASE
        UserProfile profile = connection.fetchUserProfile();

        CalendarUser user = new CalendarUser();

        if(profile.getEmail() != null){
            user.setEmail(profile.getEmail());
        }
        else if(profile.getUsername() != null){
            user.setEmail(profile.getUsername());
        }
        else {
            user.setEmail(connection.getDisplayName());
        }

        user.setFirstName(profile.getFirstName());
        user.setLastName(profile.getLastName());

        user.setPassword(randomAlphabetic(32));

        return user;

    }
 
Example 5
Source File: _SocialService.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 5 votes vote down vote up
public void createSocialUser(Connection<?> connection, String langKey) {
    if (connection == null) {
        log.error("Cannot create social user because connection is null");
        throw new IllegalArgumentException("Connection cannot be null");
    }
    UserProfile userProfile = connection.fetchUserProfile();
    String providerId = connection.getKey().getProviderId();
    User user = createUserIfNotExist(userProfile, langKey, providerId);
    createSocialConnection(user.getLogin(), connection);
    mailService.sendSocialRegistrationValidationEmail(user, providerId);
}
 
Example 6
Source File: ApplicationConnectionSignUp.java    From pazuzu-registry with MIT License 5 votes vote down vote up
@Override
public String execute(Connection<?> connection) {
    UserProfile profile = connection.fetchUserProfile();
    String username = profile.getUsername();

    logger.info("Creating user with id: {}", username);
    User user = new User(username, "", Collections.emptyList());

    userDetailsManager.createUser(user);
    return username;
}
 
Example 7
Source File: AccountConnectionSignUpService.java    From blog-social-login-with-spring-social with Apache License 2.0 5 votes vote down vote up
public String execute(Connection<?> connection) {
    org.springframework.social.connect.UserProfile profile = connection.fetchUserProfile();
    String userId = UUID.randomUUID().toString();
    // TODO: Or simply use: r = new Random(); r.nextInt(); ???
    LOG.debug("Created user-id: " + userId);
    usersDao.createUser(userId, new UserProfile(userId, profile));
    return userId;
}
 
Example 8
Source File: SocialAuthenticationUtils.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
public static CalendarUser createCalendarUserFromProvider(Connection<?> connection){

        // TODO: There is a defect with Facebook:
//        Connection<Facebook> connection = facebookConnectionFactory.createConnection(accessGrant);
//        Facebook facebook = connection.getApi();
//        String [] fields = { "id", "email",  "first_name", "last_name" };
//        User userProfile = facebook.fetchObject("me", User.class, fields);

//        Object api = connection.getApi();
//        if(connection instanceof FacebookTemplate){
//            System.out.println("HERE");
//        }
        /*
            <form name='facebookSocialloginForm'
                  action="<c:url value='/auth/facebook' />" method='POST'>
                <input type="hidden" name="scope"
                    value="public_profile,email,user_about_me,user_birthday,user_likes"/>
                ...
            </form>
         */

        // FIXME: Does not work with Facebook:
        UserProfile profile = connection.fetchUserProfile();

        CalendarUser user = new CalendarUser();

        if(profile.getEmail() != null){
            user.setEmail(profile.getEmail());
        }
        else if(profile.getUsername() != null){
            user.setEmail(profile.getUsername());
        }
        else {
            user.setEmail(connection.getDisplayName());
        }

        user.setFirstName(profile.getFirstName());
        user.setLastName(profile.getLastName());

        user.setPassword(randomAlphabetic(32));

        return user;

    }