Skip to content

Commit

Permalink
add Oidc preferred username (#3629)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdiskg authored May 25, 2021
1 parent dc41c93 commit 150955f
Show file tree
Hide file tree
Showing 42 changed files with 849 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class AppDTO extends BaseDTO{

private String ownerName;

private String ownerDisplayName;

private String ownerEmail;

public long getId() {
Expand All @@ -47,52 +49,59 @@ public void setId(long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAppId() {
return appId;
}

public String getName() {
return name;
public void setAppId(String appId) {
this.appId = appId;
}

public String getOrgId() {
return orgId;
}

public void setOrgId(String orgId) {
this.orgId = orgId;
}

public String getOrgName() {
return orgName;
}

public String getOwnerEmail() {
return ownerEmail;
public void setOrgName(String orgName) {
this.orgName = orgName;
}

public String getOwnerName() {
return ownerName;
}

public void setAppId(String appId) {
this.appId = appId;
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}

public void setName(String name) {
this.name = name;
public String getOwnerDisplayName() {
return ownerDisplayName;
}

public void setOrgId(String orgId) {
this.orgId = orgId;
public void setOwnerDisplayName(String ownerDisplayName) {
this.ownerDisplayName = ownerDisplayName;
}

public void setOrgName(String orgName) {
this.orgName = orgName;
public String getOwnerEmail() {
return ownerEmail;
}

public void setOwnerEmail(String ownerEmail) {
this.ownerEmail = ownerEmail;
}

public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public class BaseDTO {

protected String dataChangeLastModifiedBy;

protected String dataChangeCreatedByDisplayName;

protected String dataChangeLastModifiedByDisplayName;

protected Date dataChangeCreatedTime;

protected Date dataChangeLastModifiedTime;
Expand All @@ -45,6 +49,22 @@ public void setDataChangeLastModifiedBy(String dataChangeLastModifiedBy) {
this.dataChangeLastModifiedBy = dataChangeLastModifiedBy;
}

public String getDataChangeCreatedByDisplayName() {
return dataChangeCreatedByDisplayName;
}

public void setDataChangeCreatedByDisplayName(String dataChangeCreatedByDisplayName) {
this.dataChangeCreatedByDisplayName = dataChangeCreatedByDisplayName;
}

public String getDataChangeLastModifiedByDisplayName() {
return dataChangeLastModifiedByDisplayName;
}

public void setDataChangeLastModifiedByDisplayName(String dataChangeLastModifiedByDisplayName) {
this.dataChangeLastModifiedByDisplayName = dataChangeLastModifiedByDisplayName;
}

public Date getDataChangeCreatedTime() {
return dataChangeCreatedTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ExecutorService;
Expand All @@ -62,7 +64,8 @@ public abstract class AbstractBaseIntegrationTest {

private static final Gson GSON = new Gson();

protected RestTemplate restTemplate = (new TestRestTemplate()).getRestTemplate();
protected RestTemplate restTemplate = (new TestRestTemplate(new RestTemplateBuilder()
.setConnectTimeout(Duration.ofSeconds(5)))).getRestTemplate();

@PostConstruct
private void postConstruct() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public void testPollNotificationWthPublicNamespaceAndDataCenter() throws Excepti
assertNotEquals(ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, messages.get(key).longValue());
}

@Test(timeout = 5000L)
@Test(timeout = 10000L)
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWthMultipleNamespacesAndMultipleNamespacesChanged()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@
package com.ctrip.framework.apollo.portal.controller;


import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.dto.PageDTO;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.http.MultiResponseEntity;
import com.ctrip.framework.apollo.common.http.RichResponseEntity;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.portal.environment.Env;
import com.ctrip.framework.apollo.portal.component.PortalSettings;
import com.ctrip.framework.apollo.portal.enricher.adapter.AppDtoUserInfoEnrichedAdapter;
import com.ctrip.framework.apollo.portal.entity.model.AppModel;
import com.ctrip.framework.apollo.portal.entity.po.Role;
import com.ctrip.framework.apollo.portal.entity.vo.EnvClusterInfo;
import com.ctrip.framework.apollo.portal.environment.Env;
import com.ctrip.framework.apollo.portal.listener.AppCreationEvent;
import com.ctrip.framework.apollo.portal.listener.AppDeletionEvent;
import com.ctrip.framework.apollo.portal.listener.AppInfoChangedEvent;
import com.ctrip.framework.apollo.portal.service.AdditionalUserInfoEnrichService;
import com.ctrip.framework.apollo.portal.service.AppService;
import com.ctrip.framework.apollo.portal.service.RoleInitializationService;
import com.ctrip.framework.apollo.portal.service.RolePermissionService;
Expand All @@ -56,6 +60,7 @@
import org.springframework.web.client.HttpClientErrorException;

import javax.validation.Valid;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
Expand All @@ -71,20 +76,23 @@ public class AppController {
private final ApplicationEventPublisher publisher;
private final RolePermissionService rolePermissionService;
private final RoleInitializationService roleInitializationService;
private final AdditionalUserInfoEnrichService additionalUserInfoEnrichService;

public AppController(
final UserInfoHolder userInfoHolder,
final AppService appService,
final PortalSettings portalSettings,
final ApplicationEventPublisher publisher,
final RolePermissionService rolePermissionService,
final RoleInitializationService roleInitializationService) {
final RoleInitializationService roleInitializationService,
final AdditionalUserInfoEnrichService additionalUserInfoEnrichService) {
this.userInfoHolder = userInfoHolder;
this.appService = appService;
this.portalSettings = portalSettings;
this.publisher = publisher;
this.rolePermissionService = rolePermissionService;
this.roleInitializationService = roleInitializationService;
this.additionalUserInfoEnrichService = additionalUserInfoEnrichService;
}

@GetMapping
Expand Down Expand Up @@ -182,9 +190,12 @@ public ResponseEntity<Void> create(@PathVariable String env, @Valid @RequestBody
}

@GetMapping("/{appId:.+}")
public App load(@PathVariable String appId) {

return appService.load(appId);
public AppDTO load(@PathVariable String appId) {
App app = appService.load(appId);
AppDTO appDto = BeanUtils.transform(AppDTO.class, app);
additionalUserInfoEnrichService.enrichAdditionalUserInfo(Collections.singletonList(appDto),
AppDtoUserInfoEnrichedAdapter::new);
return appDto;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2021 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.portal.enricher;

import com.ctrip.framework.apollo.portal.enricher.adapter.UserInfoEnrichedAdapter;
import com.ctrip.framework.apollo.portal.entity.bo.UserInfo;
import java.util.Map;

/**
* @author vdisk <vdisk@foxmail.com>
*/
public interface AdditionalUserInfoEnricher {

/**
* enrich an additional user info for the dto list
*
* @param adapter enrich adapter
* @param userInfoMap userInfo map
*/
void enrichAdditionalUserInfo(UserInfoEnrichedAdapter adapter, Map<String, UserInfo> userInfoMap);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2021 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.portal.enricher.adapter;

import com.ctrip.framework.apollo.common.dto.AppDTO;

/**
* @author vdisk <vdisk@foxmail.com>
*/
public class AppDtoUserInfoEnrichedAdapter implements UserInfoEnrichedAdapter {

private final AppDTO dto;

public AppDtoUserInfoEnrichedAdapter(AppDTO dto) {
this.dto = dto;
}

@Override
public final String getFirstUserId() {
return this.dto.getDataChangeCreatedBy();
}

@Override
public final void setFirstUserDisplayName(String userDisplayName) {
this.dto.setDataChangeCreatedByDisplayName(userDisplayName);
}

@Override
public final String getSecondUserId() {
return this.dto.getDataChangeLastModifiedBy();
}

@Override
public final void setSecondUserDisplayName(String userDisplayName) {
this.dto.setDataChangeLastModifiedByDisplayName(userDisplayName);
}

@Override
public final String getThirdUserId() {
return this.dto.getOwnerName();
}

@Override
public final void setThirdUserDisplayName(String userDisplayName) {
this.dto.setOwnerDisplayName(userDisplayName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2021 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.portal.enricher.adapter;

import com.ctrip.framework.apollo.common.dto.BaseDTO;

/**
* @author vdisk <vdisk@foxmail.com>
*/
public class BaseDtoUserInfoEnrichedAdapter implements UserInfoEnrichedAdapter {

private final BaseDTO dto;

public BaseDtoUserInfoEnrichedAdapter(BaseDTO dto) {
this.dto = dto;
}

@Override
public final String getFirstUserId() {
return this.dto.getDataChangeCreatedBy();
}

@Override
public final void setFirstUserDisplayName(String userDisplayName) {
this.dto.setDataChangeCreatedByDisplayName(userDisplayName);
}

@Override
public final String getSecondUserId() {
return this.dto.getDataChangeLastModifiedBy();
}

@Override
public final void setSecondUserDisplayName(String userDisplayName) {
this.dto.setDataChangeLastModifiedByDisplayName(userDisplayName);
}
}
Loading

0 comments on commit 150955f

Please sign in to comment.