本文整理汇总了Java中org.springframework.social.connect.UserProfile.getEmail方法的典型用法代码示例。如果您正苦于以下问题:Java UserProfile.getEmail方法的具体用法?Java UserProfile.getEmail怎么用?Java UserProfile.getEmail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.social.connect.UserProfile
的用法示例。
在下文中一共展示了UserProfile.getEmail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCalendarUserFromProvider
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
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;
}
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:25,代码来源:SocialAuthenticationUtils.java
示例2: retreiveSocialAsUser
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
private User retreiveSocialAsUser(Connection<?> con) {
if (con == null) throw new IllegalStateException("No connection to social api");
// build a new User from the external provider's version of the User
UserProfile profile = con.fetchUserProfile();
String firstName = profile.getFirstName();
String lastName = profile.getLastName();
String email = profile.getEmail();
// build the UserAccountExternal from the ConnectionKey
String externalAccountProviderName = con.getKey().getProviderId();
ExternalProvider externalProvider = ExternalProvider.caseInsensitiveValueOf(externalAccountProviderName);
String externalUserId = con.getKey().getProviderUserId();
// check that we got the information we needed
if (StringUtils.isBlank(email))
throw new ApiException(externalAccountProviderName, "provider failed to return email");
User socialUser = new User(firstName, lastName, email, externalProvider, externalUserId);
log.debug("Retrieved details from {} for user '{}'", externalAccountProviderName, externalUserId);
return socialUser;
}
示例3: addProviderProfileInfo
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
/**
* Adds the info from the provider profile to the specified profile.
*
* @param profile the target profile
* @param providerProfile the provider profile where to get the info
*/
public static void addProviderProfileInfo(Profile profile, UserProfile providerProfile) {
String email = providerProfile.getEmail();
if (StringUtils.isEmpty(email)) {
throw new IllegalStateException("No email included in provider profile");
}
String username = providerProfile.getUsername();
if (StringUtils.isEmpty(username)) {
username = email;
}
String firstName = providerProfile.getFirstName();
String lastName = providerProfile.getLastName();
profile.setUsername(username);
profile.setEmail(email);
profile.setAttribute(FIRST_NAME_ATTRIBUTE_NAME, firstName);
profile.setAttribute(LAST_NAME_ATTRIBUTE_NAME, lastName);
}
示例4: userForm
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
@ModelAttribute("userForm")
public UserForm userForm(final WebRequest webRequest) {
final Connection<?> connection = ProviderSignInUtils.getConnection(webRequest);
if (connection == null) {
return new UserForm();
}
final UserProfile userProfile = connection.fetchUserProfile();
return userProfile == null
? new UserForm()
: new UserForm(userProfile.getEmail(),
userProfile.getFirstName(),
userProfile.getLastName());
}
示例5: createUserIfNotExist
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
private User createUserIfNotExist(UserProfile userProfile, String langKey, String imageUrl) {
String email = userProfile.getEmail();
if (StringUtils.isBlank(email)) {
log.error("Cannot create social user because email is null");
throw new IllegalArgumentException("Email cannot be null");
} else {
Optional<UserLogin> user = userLoginRepository.findOneByLoginIgnoreCase(email);
if (user.isPresent()) {
log.info("User already exist associate the connection to this account");
return user.get().getUser();
}
}
String encryptedPassword = passwordEncoder.encode(RandomStringUtils.random(10));
Set<Authority> authorities = new HashSet<>(1);
authorities.add(authorityRepository.findOne("ROLE_USER"));
User newUser = new User();
newUser.setUserKey(UUID.randomUUID().toString());
newUser.setPassword(encryptedPassword);
newUser.setFirstName(userProfile.getFirstName());
newUser.setLastName(userProfile.getLastName());
newUser.setActivated(true);
newUser.setAuthorities(authorities);
newUser.setLangKey(langKey);
newUser.setImageUrl(imageUrl);
UserLogin userLogin = new UserLogin();
userLogin.setUser(newUser);
userLogin.setTypeKey(UserLoginType.EMAIL.getValue());
userLogin.setLogin(email);
newUser.getLogins().add(userLogin);
return userRepository.save(newUser);
}
示例6: createUserIfNotExist
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
private User createUserIfNotExist(UserProfile userProfile, String langKey, String providerId, String imageUrl) {
String email = userProfile.getEmail();
String userName = userProfile.getUsername();
if (!StringUtils.isBlank(userName)) {
userName = userName.toLowerCase(Locale.ENGLISH);
}
if (StringUtils.isBlank(email) && StringUtils.isBlank(userName)) {
log.error("Cannot create social user because email and login are null");
throw new IllegalArgumentException("Email and login cannot be null");
}
if (StringUtils.isBlank(email) && userRepository.findOneByLogin(userName).isPresent()) {
log.error("Cannot create social user because email is null and login already exist, login -> {}", userName);
throw new IllegalArgumentException("Email cannot be null with an existing login");
}
if (!StringUtils.isBlank(email)) {
Optional<User> user = userRepository.findOneByEmail(email);
if (user.isPresent()) {
log.info("User already exist associate the connection to this account");
return user.get();
}
}
String login = getLoginDependingOnProviderId(userProfile, providerId);
String encryptedPassword = passwordEncoder.encode(RandomStringUtils.random(10));
Set<Authority> authorities = new HashSet<>(1);
authorities.add(authorityRepository.findOne("ROLE_USER"));
User newUser = new User();
newUser.setLogin(login);
newUser.setPassword(encryptedPassword);
newUser.setFirstName(userProfile.getFirstName());
newUser.setLastName(userProfile.getLastName());
newUser.setEmail(email);
newUser.setActivated(true);
newUser.setAuthorities(authorities);
newUser.setLangKey(langKey);
newUser.setImageUrl(imageUrl);
return userRepository.save(newUser);
}
示例7: getLoginDependingOnProviderId
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
/**
* @return login if provider manage a login like Twitter or Github otherwise email address.
* Because provider like Google or Facebook didn't provide login or login like "12099388847393"
*/
private String getLoginDependingOnProviderId(UserProfile userProfile, String providerId) {
switch (providerId) {
case "twitter":
return userProfile.getUsername().toLowerCase();
default:
return userProfile.getEmail();
}
}
示例8: getLoginDependingOnProviderId
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
/**
* @return login if provider manage a login like Twitter or Github otherwise email address.
* Because provider like Google or Facebook didn't provide login or login like "12099388847393"
*/
private String getLoginDependingOnProviderId(UserProfile userProfile, String providerId) {
switch (providerId) {
case "discord":
case "twitter":
// username is actually the user's snowflake id
return userProfile.getUsername();
default:
return userProfile.getEmail();
}
}
示例9: createCalendarUserFromProvider
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
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;
}
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:41,代码来源:SocialAuthenticationUtils.java
示例10: createUserIfNotExist
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
private User createUserIfNotExist(UserProfile userProfile, String langKey, String providerId) {
String email = userProfile.getEmail();
String userName = userProfile.getUsername();
if (StringUtils.isBlank(email) && StringUtils.isBlank(userName)) {
log.error("Cannot create social user because email and login are null");
throw new IllegalArgumentException("Email and login cannot be null");
}
if (StringUtils.isBlank(email) && userRepository.findOneByLogin(userName).isPresent()) {
log.error("Cannot create social user because email is null and login already exist, login -> {}", userName);
throw new IllegalArgumentException("Email cannot be null with an existing login");
}
Optional<User> user = userRepository.findOneByEmail(email);
if (user.isPresent()) {
log.info("User already exist associate the connection to this account");
return user.get();
}
String login = getLoginDependingOnProviderId(userProfile, providerId);
String encryptedPassword = passwordEncoder.encode(RandomStringUtils.random(10));
Set<Authority> authorities = new HashSet<>(1);
authorities.add(authorityRepository.findOne("ROLE_USER"));
User newUser = new User();
newUser.setLogin(login);
newUser.setPassword(encryptedPassword);
newUser.setFirstName(userProfile.getFirstName());
newUser.setLastName(userProfile.getLastName());
newUser.setEmail(email);
newUser.setActivated(true);
newUser.setAuthorities(authorities);
newUser.setLangKey(langKey);
return userRepository.save(newUser);
}
示例11: getLoginDependingOnProviderId
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
/**
* @return login if provider manage a login like Twitter or Github otherwise email address.
* Because provider like Google or Facebook didn't provide login or login like "12099388847393"
*/
private String getLoginDependingOnProviderId(UserProfile userProfile, String providerId) {
switch (providerId) {
case "twitter":
return userProfile.getUsername();
default:
return userProfile.getEmail();
}
}
示例12: createUserIfNotExist
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
private User createUserIfNotExist(UserProfile userProfile, String langKey, String providerId) {
String email = userProfile.getEmail();
String userName = userProfile.getUsername();
if (StringUtils.isBlank(email) && StringUtils.isBlank(userName)) {
log.error("Cannot create social user because email and login are null");
throw new IllegalArgumentException("Email and login cannot be null");
}
if (StringUtils.isBlank(email) && userRepository.findOneByLogin(userName).isPresent()) {
log.error("Cannot create social user because email is null and login already exist, login -> {}", userName);
throw new IllegalArgumentException("Email cannot be null with an existing login");
}
Optional<User> user = userRepository.findOneByEmail(email);
if (user.isPresent()) {
log.info("User already exist associate the connection to this account");
return user.get();
}
String login = getLoginDependingOnProviderId(userProfile, providerId);
String encryptedPassword = passwordEncoder.encode(RandomStringUtils.random(10));
Set<Authority> authorities = new HashSet<>(1);
authorities.add(authorityRepository.findOne("ROLE_USER"));
User newUser = new User();
newUser.setLogin(login);
newUser.setPassword(encryptedPassword);
newUser.setFirstName(userProfile.getFirstName());
newUser.setLastName(userProfile.getLastName());
newUser.setEmail(email);
newUser.setActivated(true);
newUser.setAuthorities(authorities);
newUser.setLangKey(langKey);
return userRepository.save(newUser);
}
示例13: createUserIfNotExist
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
private User createUserIfNotExist(UserProfile userProfile, String langKey, String providerId) {
String email = userProfile.getEmail();
String userName = userProfile.getUsername();
if (!StringUtils.isBlank(userName)) {
userName = userName.toLowerCase(Locale.ENGLISH);
}
if (StringUtils.isBlank(email) && StringUtils.isBlank(userName)) {
log.error("Cannot create social user because email and login are null");
throw new IllegalArgumentException("Email and login cannot be null");
}
if (StringUtils.isBlank(email) && userRepository.findOneByLogin(userName).isPresent()) {
log.error("Cannot create social user because email is null and login already exist, login -> {}", userName);
throw new IllegalArgumentException("Email cannot be null with an existing login");
}
Optional<User> user = userRepository.findOneByEmail(email);
if (user.isPresent()) {
log.info("User already exist associate the connection to this account");
return user.get();
}
String login = getLoginDependingOnProviderId(userProfile, providerId);
String encryptedPassword = passwordEncoder.encode(RandomStringUtils.random(10));
Set<Authority> authorities = new HashSet<>(1);
authorities.add(authorityRepository.findOne("ROLE_USER"));
User newUser = new User();
newUser.setLogin(login);
newUser.setPassword(encryptedPassword);
newUser.setFirstName(userProfile.getFirstName());
newUser.setLastName(userProfile.getLastName());
newUser.setEmail(email);
newUser.setActivated(true);
newUser.setAuthorities(authorities);
newUser.setLangKey(langKey);
return userRepository.save(newUser);
}
示例14: getLoginDependingOnProviderId
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
/**
* @return login if provider manage a login like Twitter or Github otherwise email address.
* Because provider like Google or Facebook didn't provide login or login like "12099388847393"
*/
private String getLoginDependingOnProviderId(UserProfile userProfile, String providerId) {
switch (providerId) {
case "twitter":
return userProfile.getUsername().toLowerCase();
default:
return userProfile.getEmail();
}
}
示例15: createUserIfNotExist
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
private User createUserIfNotExist(UserProfile userProfile, String langKey, String providerId, String imageUrl) {
String email = userProfile.getEmail();
String userName = userProfile.getUsername();
if (StringUtils.isBlank(email) && StringUtils.isBlank(userName)) {
log.error("Cannot create social user because email and login are null");
throw new IllegalArgumentException("Email and login cannot be null");
}
if (StringUtils.isBlank(email) && userRepository.findOneByLogin(userName).isPresent()) {
log.error("Cannot create social user because email is null and login already exist, login -> {}", userName);
throw new IllegalArgumentException("Email cannot be null with an existing login");
}
Optional<User> user = userRepository.findOneByEmail(email);
if (user.isPresent()) {
log.info("User already exist associate the connection to this account");
return user.get();
}
String login = getLoginDependingOnProviderId(userProfile, providerId);
String encryptedPassword = passwordEncoder.encode(RandomStringUtils.random(10));
Set<Authority> authorities = new HashSet<>(1);
authorities.add(authorityRepository.findOne("ROLE_USER"));
User newUser = new User();
newUser.setLogin(login);
newUser.setPassword(encryptedPassword);
newUser.setFirstName(userProfile.getFirstName());
newUser.setLastName(userProfile.getLastName());
newUser.setEmail(email);
newUser.setActivated(true);
newUser.setAuthorities(authorities);
newUser.setLangKey(langKey);
byte[] image = getImageFromUrl(imageUrl);
if (image != null) {
newUser.setPicture(image);
newUser.setPictureContentType("image/jpeg");
}
return userRepository.save(newUser);
}