Skip to content

Commit

Permalink
perf($ApiGateway): use lombok val annotation
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
Johnny Miller (锺俊) committed Dec 29, 2020
1 parent 0ef5666 commit aec0662
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.jmsoftware.maf.apigateway.remoteapi.AuthCenterRemoteApi;
import com.jmsoftware.maf.common.bean.ResponseBodyBean;
import com.jmsoftware.maf.common.domain.authcenter.permission.GetPermissionListByRoleIdListPayload;
import com.jmsoftware.maf.common.domain.authcenter.permission.GetPermissionListByRoleIdListResponse;
import com.jmsoftware.maf.common.domain.authcenter.permission.PermissionType;
import com.jmsoftware.maf.common.domain.authcenter.role.GetRoleListByUserIdResponse;
import com.jmsoftware.maf.common.domain.authcenter.security.UserPrincipal;
Expand All @@ -24,7 +23,6 @@
import reactor.core.publisher.Mono;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -58,7 +56,7 @@ public Mono<AuthorizationDecision> check(Mono<Authentication> authentication, Au
.switchIfEmpty(Flux.error(new SecurityException(HttpStatus.UNAUTHORIZED, "Roles not assigned!")));

// Filter "admin" role and then, map Flux<?> to Mono<List<Long>>
Mono<List<Long>> roleIdListMono = getRoleListByUserIdResponseFlux
val roleIdListMono = getRoleListByUserIdResponseFlux
.filter(role -> StrUtil.equals("admin", role.getName()))
.map(GetRoleListByUserIdResponse.Role::getId).collectList()
.switchIfEmpty(getRoleListByUserIdResponseFlux
Expand All @@ -67,7 +65,7 @@ public Mono<AuthorizationDecision> check(Mono<Authentication> authentication, Au

// Get permission list based on the Mono<List<Long>>
// auth-center will respond /** for role "admin"
Mono<GetPermissionListByRoleIdListResponse> getPermissionListByRoleIdListResponseMono = roleIdListMono.flatMap(
val getPermissionListByRoleIdListResponseMono = roleIdListMono.flatMap(
roleIdList -> {
GetPermissionListByRoleIdListPayload payload = new GetPermissionListByRoleIdListPayload();
payload.setRoleIdList(roleIdList);
Expand Down

0 comments on commit aec0662

Please sign in to comment.