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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations