Search in sources :

Example 1 with UserInfo

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

the class CtripUserInfoHolder method getUser.

@Override
public UserInfo getUser() {
    try {
        Object assertion = getAssertion.invoke(assertionHolder);
        Method getPrincipal = assertion.getClass().getMethod("getPrincipal");
        Object principal = getPrincipal.invoke(assertion);
        Method getName = principal.getClass().getMethod("getName");
        String name = (String) getName.invoke(principal);
        UserInfo userInfo = new UserInfo();
        userInfo.setUserId(name);
        return userInfo;
    } catch (Exception e) {
        throw new RuntimeException("get user info from assertion holder error", e);
    }
}
Also used : UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) Method(java.lang.reflect.Method)

Example 2 with UserInfo

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

the class CtripUserService method transformUserServiceResponseToUserInfo.

private UserInfo transformUserServiceResponseToUserInfo(UserServiceResponse userServiceResponse) {
    UserInfo userInfo = new UserInfo();
    userInfo.setUserId(userServiceResponse.getEmpaccount());
    userInfo.setName(userServiceResponse.getDisplayname());
    userInfo.setEmail(userServiceResponse.getEmail());
    return userInfo;
}
Also used : UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo)

Example 3 with UserInfo

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

the class UserAccessFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    String requestUri = ((HttpServletRequest) request).getRequestURI();
    try {
        if (!isOpenAPIRequest(requestUri) && !isStaticResource(requestUri)) {
            UserInfo userInfo = userInfoHolder.getUser();
            if (userInfo != null) {
                Tracer.logEvent(TracerEventType.USER_ACCESS, userInfo.getUserId());
            }
        }
    } catch (Throwable e) {
        Tracer.logError("Record user access info error.", e);
    }
    chain.doFilter(request, response);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo)

Example 4 with UserInfo

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

the class ConfigPublishEmailBuilder method recipients.

private List<String> recipients(String appId, String namespaceName, String env) {
    Set<UserInfo> modifyRoleUsers = rolePermissionService.queryUsersWithRole(RoleUtils.buildNamespaceRoleName(appId, namespaceName, RoleType.MODIFY_NAMESPACE));
    Set<UserInfo> envModifyRoleUsers = rolePermissionService.queryUsersWithRole(RoleUtils.buildNamespaceRoleName(appId, namespaceName, RoleType.MODIFY_NAMESPACE, env));
    Set<UserInfo> releaseRoleUsers = rolePermissionService.queryUsersWithRole(RoleUtils.buildNamespaceRoleName(appId, namespaceName, RoleType.RELEASE_NAMESPACE));
    Set<UserInfo> envReleaseRoleUsers = rolePermissionService.queryUsersWithRole(RoleUtils.buildNamespaceRoleName(appId, namespaceName, RoleType.RELEASE_NAMESPACE, env));
    Set<UserInfo> owners = rolePermissionService.queryUsersWithRole(RoleUtils.buildAppMasterRoleName(appId));
    Set<String> userIds = new HashSet<>(modifyRoleUsers.size() + releaseRoleUsers.size() + owners.size());
    for (UserInfo userInfo : modifyRoleUsers) {
        userIds.add(userInfo.getUserId());
    }
    for (UserInfo userInfo : envModifyRoleUsers) {
        userIds.add(userInfo.getUserId());
    }
    for (UserInfo userInfo : releaseRoleUsers) {
        userIds.add(userInfo.getUserId());
    }
    for (UserInfo userInfo : envReleaseRoleUsers) {
        userIds.add(userInfo.getUserId());
    }
    for (UserInfo userInfo : owners) {
        userIds.add(userInfo.getUserId());
    }
    List<UserInfo> userInfos = userService.findByUserIds(Lists.newArrayList(userIds));
    if (CollectionUtils.isEmpty(userInfos)) {
        return Collections.emptyList();
    }
    List<String> recipients = new ArrayList<>(userInfos.size());
    for (UserInfo userInfo : userInfos) {
        recipients.add(userInfo.getEmail());
    }
    return recipients;
}
Also used : ArrayList(java.util.ArrayList) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) HashSet(java.util.HashSet)

Example 5 with UserInfo

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

the class ConsumerService method createConsumer.

public Consumer createConsumer(Consumer consumer) {
    String appId = consumer.getAppId();
    Consumer managedConsumer = consumerRepository.findByAppId(appId);
    if (managedConsumer != null) {
        throw new BadRequestException("Consumer already exist");
    }
    String ownerName = consumer.getOwnerName();
    UserInfo owner = userService.findByUserId(ownerName);
    if (owner == null) {
        throw new BadRequestException(String.format("User does not exist. UserId = %s", ownerName));
    }
    consumer.setOwnerEmail(owner.getEmail());
    String operator = userInfoHolder.getUser().getUserId();
    consumer.setDataChangeCreatedBy(operator);
    consumer.setDataChangeLastModifiedBy(operator);
    return consumerRepository.save(consumer);
}
Also used : Consumer(com.ctrip.framework.apollo.openapi.entity.Consumer) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) 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