Search in sources :

Example 31 with UserInfo

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;
}
Also used : UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo)

Example 32 with UserInfo

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;
    }
}
Also used : DirContextAdapter(org.springframework.ldap.core.DirContextAdapter) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 33 with UserInfo

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;
    });
}
Also used : ArrayList(java.util.ArrayList) DirContextAdapter(org.springframework.ldap.core.DirContextAdapter) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) LdapName(javax.naming.ldap.LdapName)

Example 34 with UserInfo

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);
}
Also used : UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo)

Example 35 with UserInfo

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);
}
Also used : UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo)

Aggregations

UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)36 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)7 Test (org.junit.Test)7 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)6 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)3 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)3 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)3 App (com.ctrip.framework.apollo.common.entity.App)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Consumer (com.ctrip.framework.apollo.openapi.entity.Consumer)2 Role (com.ctrip.framework.apollo.portal.entity.po.Role)2 ItemDiffs (com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs)2 NamespaceIdentifier (com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier)2 Sets (com.google.common.collect.Sets)2 Collections (java.util.Collections)2 Set (java.util.Set)2 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)1