Search in sources :

Example 11 with UserInfo

use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.

the class PermissionController method getAppRoles.

@GetMapping("/apps/{appId}/role_users")
public AppRolesAssignedUsers getAppRoles(@PathVariable String appId) {
    AppRolesAssignedUsers users = new AppRolesAssignedUsers();
    users.setAppId(appId);
    Set<UserInfo> masterUsers = rolePermissionService.queryUsersWithRole(RoleUtils.buildAppMasterRoleName(appId));
    users.setMasterUsers(masterUsers);
    return users;
}
Also used : UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) AppRolesAssignedUsers(com.ctrip.framework.apollo.portal.entity.vo.AppRolesAssignedUsers)

Example 12 with UserInfo

use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.

the class AppService method createAppInLocal.

@Transactional
public App createAppInLocal(App app) {
    String appId = app.getAppId();
    App managedApp = appRepository.findByAppId(appId);
    if (managedApp != null) {
        throw new BadRequestException(String.format("App already exists. AppId = %s", appId));
    }
    UserInfo owner = userService.findByUserId(app.getOwnerName());
    if (owner == null) {
        throw new BadRequestException("Application's owner not exist.");
    }
    app.setOwnerEmail(owner.getEmail());
    String operator = userInfoHolder.getUser().getUserId();
    app.setDataChangeCreatedBy(operator);
    app.setDataChangeLastModifiedBy(operator);
    App createdApp = appRepository.save(app);
    appNamespaceService.createDefaultAppNamespace(appId);
    roleInitializationService.initAppRoles(createdApp);
    Tracer.logEvent(TracerEventType.CREATE_APP, appId);
    return createdApp;
}
Also used : App(com.ctrip.framework.apollo.common.entity.App) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with UserInfo

use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.

the class LdapUserService method searchUsers.

@Override
public List<UserInfo> searchUsers(String keyword, int offset, int limit) {
    List<UserInfo> users = new ArrayList<>();
    if (StringUtils.isNotBlank(groupSearch)) {
        List<UserInfo> userListByGroup = searchUserInfoByGroup(groupBase, groupSearch, keyword, null);
        users.addAll(userListByGroup);
        return users.stream().collect(collectingAndThen(toCollection(() -> new TreeSet<>((o1, o2) -> {
            if (o1.getUserId().equals(o2.getUserId())) {
                return 0;
            }
            return -1;
        })), ArrayList::new));
    }
    ContainerCriteria criteria = ldapQueryCriteria();
    if (!Strings.isNullOrEmpty(keyword)) {
        criteria.and(query().where(loginIdAttrName).like(keyword + "*").or(userDisplayNameAttrName).like(keyword + "*"));
    }
    users = ldapTemplate.search(criteria, ldapUserInfoMapper);
    return users;
}
Also used : Arrays(java.util.Arrays) LdapName(javax.naming.ldap.LdapName) Autowired(org.springframework.beans.factory.annotation.Autowired) LdapUtils(org.springframework.ldap.support.LdapUtils) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) LdapTemplate(org.springframework.ldap.core.LdapTemplate) StringUtils(org.apache.commons.lang3.StringUtils) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) Value(org.springframework.beans.factory.annotation.Value) Collectors.toCollection(java.util.stream.Collectors.toCollection) Strings(com.google.common.base.Strings) Attribute(javax.naming.directory.Attribute) LdapExtendProperties(com.ctrip.framework.apollo.portal.spi.configuration.LdapExtendProperties) DirContextAdapter(org.springframework.ldap.core.DirContextAdapter) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) SearchScope(org.springframework.ldap.query.SearchScope) ContainerCriteria(org.springframework.ldap.query.ContainerCriteria) Set(java.util.Set) Sets(com.google.common.collect.Sets) List(java.util.List) ContextMapper(org.springframework.ldap.core.ContextMapper) AttributesMapper(org.springframework.ldap.core.AttributesMapper) LdapProperties(com.ctrip.framework.apollo.portal.spi.configuration.LdapProperties) LdapQueryBuilder.query(org.springframework.ldap.query.LdapQueryBuilder.query) CollectionUtils(org.springframework.util.CollectionUtils) Collections(java.util.Collections) UserService(com.ctrip.framework.apollo.portal.spi.UserService) ArrayList(java.util.ArrayList) ContainerCriteria(org.springframework.ldap.query.ContainerCriteria) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo)

Example 14 with UserInfo

use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.

the class OidcUserInfoHolder method getUser.

@Override
public UserInfo getUser() {
    UserInfo userInfo = this.getUserInternal();
    if (StringUtils.hasText(userInfo.getName())) {
        return userInfo;
    }
    UserInfo userInfoFound = this.userService.findByUserId(userInfo.getUserId());
    if (userInfoFound != null) {
        return userInfoFound;
    }
    return userInfo;
}
Also used : UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo)

Example 15 with UserInfo

use of com.ctrip.framework.apollo.portal.entity.bo.UserInfo in project apollo by ctripcorp.

the class OidcUserInfoHolder method getUserInternal.

private UserInfo getUserInternal() {
    Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    if (principal instanceof OidcUser) {
        UserInfo userInfo = new UserInfo();
        OidcUser oidcUser = (OidcUser) principal;
        userInfo.setUserId(oidcUser.getSubject());
        userInfo.setName(oidcUser.getPreferredUsername());
        userInfo.setEmail(oidcUser.getEmail());
        return userInfo;
    }
    if (principal instanceof Jwt) {
        Jwt jwt = (Jwt) principal;
        UserInfo userInfo = new UserInfo();
        userInfo.setUserId(jwt.getSubject());
        return userInfo;
    }
    log.debug("principal is neither oidcUser nor jwt, principal=[{}]", principal);
    if (principal instanceof OAuth2User) {
        UserInfo userInfo = new UserInfo();
        OAuth2User oAuth2User = (OAuth2User) principal;
        userInfo.setUserId(oAuth2User.getName());
        userInfo.setName(oAuth2User.getAttribute(StandardClaimNames.PREFERRED_USERNAME));
        userInfo.setEmail(oAuth2User.getAttribute(StandardClaimNames.EMAIL));
        return userInfo;
    }
    if (principal instanceof Principal) {
        UserInfo userInfo = new UserInfo();
        Principal userPrincipal = (Principal) principal;
        userInfo.setUserId(userPrincipal.getName());
        return userInfo;
    }
    UserInfo userInfo = new UserInfo();
    userInfo.setUserId(String.valueOf(principal));
    return userInfo;
}
Also used : OAuth2User(org.springframework.security.oauth2.core.user.OAuth2User) Jwt(org.springframework.security.oauth2.jwt.Jwt) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) Principal(java.security.Principal) OidcUser(org.springframework.security.oauth2.core.oidc.user.OidcUser)

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