本文整理汇总了Java中org.springframework.social.connect.UserProfile.getUsername方法的典型用法代码示例。如果您正苦于以下问题:Java UserProfile.getUsername方法的具体用法?Java UserProfile.getUsername怎么用?Java UserProfile.getUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.social.connect.UserProfile
的用法示例。
在下文中一共展示了UserProfile.getUsername方法的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: execute
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
@Override
public String execute(Connection<?> connection) {
final UserProfile profile = connection.fetchUserProfile();
final User user = new User();
user.setEmail(profile.getEmail());
if ((profile.getUsername() == null) ||
(profile.getUsername().length() < 2) ||
(profile.getUsername().length() > MAX_NAME_LENGTH)) {
user.setUserData(new UserData(user, profile.getFirstName(), profile.getFirstName(),
profile.getLastName(), connection.getImageUrl(), "", false));
} else {
user.setUserData(new UserData(user, profile.getUsername(), profile.getFirstName(),
profile.getLastName(), connection.getImageUrl(), "", false));
}
user.setPassword(KeyGenerators.string().generateKey());
if (userService.getByEmail(user.getEmail()) == null) {
userService.save(user);
publisher.publishEvent(mails.welcomeMail(user));
}
return user.getEmail();
}
示例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: extractAuthentication
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
private OAuth2Authentication extractAuthentication(UserProfile user) {
String principal = user.getUsername();
List<GrantedAuthority> authorities = AuthorityUtils
.commaSeparatedStringToAuthorityList("ROLE_USER");
OAuth2Request request = new OAuth2Request(null, this.clientId, null, true, null,
null, null, null, null);
return new OAuth2Authentication(request,
new UsernamePasswordAuthenticationToken(principal, "N/A", authorities));
}
示例5: 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);
}
示例6: 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();
}
}
示例7: 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
示例8: 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);
}
示例9: 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();
}
}
示例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: 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);
}
示例12: execute
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
@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;
}
示例13: extractProviderUserId
import org.springframework.social.connect.UserProfile; //导入方法依赖的package包/类
@Override
protected String extractProviderUserId(AccessGrant accessGrant) {
Google api = ((GoogleConfigurableServiceProvider)getServiceProvider())
.getApi(accessGrant.getAccessToken());
UserProfile userProfile = getApiAdapter().fetchUserProfile(api);
return userProfile.getUsername();
}
示例14: 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);
}
示例15: 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();
}
}