use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class NamespaceServiceTest method createUser.
private UserInfo createUser(String userId) {
UserInfo instance = new UserInfo();
instance.setUserId(userId);
return instance;
}
use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class LdapUserService method searchUserById.
private UserInfo searchUserById(String userId) {
try {
return ldapTemplate.searchForObject(query().where(loginIdAttrName).is(userId), ctx -> {
UserInfo userInfo = new UserInfo();
DirContextAdapter contextAdapter = (DirContextAdapter) ctx;
userInfo.setEmail(contextAdapter.getStringAttribute(emailAttrName));
userInfo.setName(contextAdapter.getStringAttribute(userDisplayNameAttrName));
userInfo.setUserId(contextAdapter.getStringAttribute(loginIdAttrName));
return userInfo;
});
} catch (EmptyResultDataAccessException ex) {
// EmptyResultDataAccessException means no record found
return null;
}
}
use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class LdapUserService method searchUserInfoByGroup.
/**
* 按照group搜索用户
*
* @param groupBase group search base
* @param groupSearch group filter
* @param keyword user search keywords
* @param userIds user id list
*/
private List<UserInfo> searchUserInfoByGroup(String groupBase, String groupSearch, String keyword, List<String> userIds) {
return ldapTemplate.searchForObject(groupBase, groupSearch, ctx -> {
List<UserInfo> userInfos = new ArrayList<>();
if (!MEMBER_UID_ATTR_NAME.equals(groupMembershipAttrName)) {
String[] members = ((DirContextAdapter) ctx).getStringAttributes(groupMembershipAttrName);
for (String item : members) {
LdapName ldapName = LdapUtils.newLdapName(item);
LdapName memberRdn = LdapUtils.removeFirst(ldapName, LdapUtils.newLdapName(base));
if (keyword != null) {
String rdnValue = LdapUtils.getValue(memberRdn, rdnKey).toString();
if (rdnValue.toLowerCase().contains(keyword.toLowerCase())) {
UserInfo userInfo = lookupUser(memberRdn.toString(), userIds);
userInfos.add(userInfo);
}
} else {
UserInfo userInfo = lookupUser(memberRdn.toString(), userIds);
if (userInfo != null) {
userInfos.add(userInfo);
}
}
}
return userInfos;
}
Set<String> memberUids = Sets.newHashSet(((DirContextAdapter) ctx).getStringAttributes(groupMembershipAttrName));
if (!CollectionUtils.isEmpty(userIds)) {
memberUids = Sets.intersection(memberUids, Sets.newHashSet(userIds));
}
for (String memberUid : memberUids) {
UserInfo userInfo = searchUserById(memberUid);
if (userInfo != null) {
if (keyword != null) {
if (userInfo.getUserId().toLowerCase().contains(keyword.toLowerCase())) {
userInfos.add(userInfo);
}
} else {
userInfos.add(userInfo);
}
}
}
return userInfos;
});
}
use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class OidcAuthenticationSuccessEventListener method oidcUserLogin.
private void oidcUserLogin(OidcUser oidcUser) {
UserInfo newUserInfo = new UserInfo();
newUserInfo.setUserId(oidcUser.getSubject());
newUserInfo.setName(oidcUser.getPreferredUsername());
newUserInfo.setEmail(oidcUser.getEmail());
if (this.contains(oidcUser.getSubject())) {
this.oidcLocalUserService.updateUserInfo(newUserInfo);
return;
}
this.oidcLocalUserService.createLocalUser(newUserInfo);
}
use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.
the class OidcAuthenticationSuccessEventListener method jwtLogin.
private void jwtLogin(Jwt jwt) {
if (this.contains(jwt.getSubject())) {
return;
}
UserInfo newUserInfo = new UserInfo();
newUserInfo.setUserId(jwt.getSubject());
this.oidcLocalUserService.createLocalUser(newUserInfo);
}
Aggregations