Skip to content

Commit

Permalink
refactor shenyu-admin: ignore password in api.
Browse files Browse the repository at this point in the history
  • Loading branch information
midnight2104 committed Nov 15, 2021
1 parent c07f247 commit e633991
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public ShenyuAdminResult queryDashboardUsers(final String userName,
new PageParameter(currentPage, pageSize)));

if (CollectionUtils.isNotEmpty(commonPager.getDataList())) {
commonPager.getDataList()
.forEach(item -> item.setPassword(""));
return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, commonPager);
} else {
return ShenyuAdminResult.error(ShenyuResultMessage.DASHBOARD_QUERY_ERROR);
Expand All @@ -98,10 +96,9 @@ public ShenyuAdminResult queryDashboardUsers(final String userName,
@GetMapping("/{id}")
public ShenyuAdminResult detailDashboardUser(@PathVariable("id") final String id) {
DashboardUserEditVO dashboardUserEditVO = dashboardUserService.findById(id);
return Optional.ofNullable(dashboardUserEditVO).map(item -> {
item.setPassword("");
return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, item);
}).orElseGet(() -> ShenyuAdminResult.error(ShenyuResultMessage.DASHBOARD_QUERY_ERROR));
return Optional.ofNullable(dashboardUserEditVO)
.map(item -> ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, item))
.orElseGet(() -> ShenyuAdminResult.error(ShenyuResultMessage.DASHBOARD_QUERY_ERROR));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.shenyu.admin.model.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.shenyu.admin.model.entity.DashboardUserDO;
import org.apache.shenyu.common.utils.DateUtils;

Expand Down Expand Up @@ -44,6 +45,7 @@ public class DashboardUserVO implements Serializable {
/**
* user password.
*/
@JsonIgnore
private String password;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public void queryDashboardUsers() throws Exception {
mockMvc.perform(get(url))
.andExpect(status().isOk())
.andExpect(jsonPath("$.message", is(ShenyuResultMessage.QUERY_SUCCESS)))
.andExpect(jsonPath("$.data.dataList[0].password", is("")))
.andReturn();

final CommonPager<DashboardUserVO> commonPagerError = new CommonPager<>(new PageParameter(),
Expand All @@ -121,8 +120,7 @@ public void detailDashboardUser() throws Exception {
final String url = "/dashboardUser/1";
mockMvc.perform(get(url))
.andExpect(status().isOk())
.andExpect(jsonPath("$.message", is(ShenyuResultMessage.DETAIL_SUCCESS)))
.andExpect(jsonPath("$.data.password", is("")));
.andExpect(jsonPath("$.message", is(ShenyuResultMessage.DETAIL_SUCCESS)));

given(dashboardUserService.findById(any())).willReturn(null);
mockMvc.perform(get(url))
Expand Down

0 comments on commit e633991

Please sign in to comment.