Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[type:feat]Auth adapts to namespace transformation #5667

Merged
merged 4 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion db/init/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2375,4 +2375,6 @@ ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMME

ALTER TABLE `shenyu`.`rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`;

ALTER TABLE `shenyu`.`meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId';
ALTER TABLE `shenyu`.`meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId';

ALTER TABLE `shenyu`.`app_auth` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `enabled`;
4 changes: 3 additions & 1 deletion db/init/ob/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2375,4 +2375,6 @@ ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMME

ALTER TABLE `shenyu`.`rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`;

ALTER TABLE `shenyu`.`meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId';
ALTER TABLE `shenyu`.`meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId';

ALTER TABLE `shenyu`.`app_auth` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `enabled`;
5 changes: 4 additions & 1 deletion db/init/og/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2681,4 +2681,7 @@ ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId';

ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId';
COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId';

ALTER TABLE "public"."app_auth" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."app_auth"."namespace_id" IS 'namespaceId';
5 changes: 4 additions & 1 deletion db/init/oracle/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2866,4 +2866,7 @@ ALTER TABLE rule ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN rule.namespace_id IS 'namespaceId';

ALTER TABLE meta_data ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN meta_data.namespace_id IS 'namespaceId';
COMMENT ON COLUMN meta_data.namespace_id IS 'namespaceId';

ALTER TABLE app_auth ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN app_auth.namespace_id IS 'namespaceId';
5 changes: 4 additions & 1 deletion db/init/pg/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2798,4 +2798,7 @@ ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId';

ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId';
COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId';

ALTER TABLE "public"."app_auth" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."app_auth"."namespace_id" IS 'namespaceId';
5 changes: 5 additions & 0 deletions db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,8 @@ UPDATE meta_data
SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385'
WHERE namespace_id IS NULL;

ALTER TABLE `shenyu`.`app_auth` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `enabled`;

UPDATE app_auth
SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385'
WHERE namespace_id IS NULL;
8 changes: 7 additions & 1 deletion db/upgrade/2.6.1-upgrade-2.7.0-og.sql
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,10 @@ UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385'
ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId';

UPDATE "public"."meta_data" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
UPDATE "public"."meta_data" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

ALTER TABLE "public"."app_auth" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."app_auth"."namespace_id" IS 'namespaceId';

UPDATE "public"."app_auth" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

7 changes: 6 additions & 1 deletion db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,9 @@ UPDATE rule SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE name
ALTER TABLE meta_data ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN meta_data.namespace_id IS 'namespaceId';

UPDATE meta_data SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
UPDATE meta_data SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

ALTER TABLE app_auth ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN app_auth.namespace_id IS 'namespaceId';

UPDATE app_auth SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
8 changes: 7 additions & 1 deletion db/upgrade/2.6.1-upgrade-2.7.0-pg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,10 @@ UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385'
ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId';

UPDATE "public"."meta_data" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
UPDATE "public"."meta_data" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

ALTER TABLE "public"."app_auth" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."app_auth"."namespace_id" IS 'namespaceId';

UPDATE "public"."app_auth" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.shenyu.admin.aspect.annotation.RestApi;
import org.apache.shenyu.admin.mapper.AppAuthMapper;
import org.apache.shenyu.admin.mapper.AuthPathMapper;
import org.apache.shenyu.admin.mapper.NamespaceMapper;
import org.apache.shenyu.admin.model.dto.AppAuthDTO;
import org.apache.shenyu.admin.model.dto.AuthApplyDTO;
import org.apache.shenyu.admin.model.dto.AuthPathWarpDTO;
Expand Down Expand Up @@ -96,17 +97,21 @@ public ShenyuAdminResult updateSk(@RequestParam("appKey")
* @param phone specific phone
* @param currentPage current page of list
* @param pageSize page size of query
* @param namespaceId namespaceId
* @return the shenyu result
*/
@GetMapping("/findPageByQuery")
@RequiresPermissions("system:authen:list")
public ShenyuAdminResult findPageByQuery(final String appKey, final String phone,
@RequestParam @NotNull(message = "currentPage not null") final Integer currentPage,
@RequestParam @NotNull(message = "pageSize not null") final Integer pageSize) {
@RequestParam @NotNull(message = "pageSize not null") final Integer pageSize,
@Valid @Existed(message = "namespaceId is not existed",
provider = NamespaceMapper.class) final String namespaceId) {
AppAuthQuery query = new AppAuthQuery();
query.setPhone(phone);
query.setAppKey(appKey);
query.setPageParameter(new PageParameter(currentPage, pageSize));
query.setNamespaceId(namespaceId);
CommonPager<AppAuthVO> commonPager = appAuthService.listByPage(query);
return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, commonPager);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.shenyu.admin.model.dto;

import org.apache.shenyu.admin.mapper.AppAuthMapper;
import org.apache.shenyu.admin.mapper.NamespaceMapper;
import org.apache.shenyu.admin.validation.annotation.Existed;

import jakarta.validation.Valid;
Expand Down Expand Up @@ -75,6 +76,13 @@ public class AppAuthDTO implements Serializable {

@Valid
private List<AuthPathDTO> authPathList;

/**
* namespaceId.
*/
@NotBlank
@Existed(message = "namespaceId is not existed", provider = NamespaceMapper.class)
private String namespaceId;

/**
* Gets the value of id.
Expand Down Expand Up @@ -255,6 +263,24 @@ public List<AuthPathDTO> getAuthPathList() {
public void setAuthPathList(final List<AuthPathDTO> authPathList) {
this.authPathList = authPathList;
}

/**
* get namespaceId.
*
* @return namespaceId
*/
public String getNamespaceId() {
return namespaceId;
}

/**
* set namespaceId.
*
* @param namespaceId namespaceId
*/
public void setNamespaceId(final String namespaceId) {
this.namespaceId = namespaceId;
}

@Override
public boolean equals(final Object o) {
Expand All @@ -274,11 +300,12 @@ public boolean equals(final Object o) {
&& Objects.equals(open, that.open)
&& Objects.equals(enabled, that.enabled)
&& Objects.equals(authParamList, that.authParamList)
&& Objects.equals(authPathList, that.authPathList);
&& Objects.equals(authPathList, that.authPathList)
&& Objects.equals(namespaceId, that.namespaceId);
}

@Override
public int hashCode() {
return Objects.hash(id, appKey, appSecret, userId, phone, extInfo, open, enabled, authParamList, authPathList);
return Objects.hash(id, appKey, appSecret, userId, phone, extInfo, open, enabled, authParamList, authPathList, namespaceId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import org.apache.shenyu.admin.mapper.NamespaceMapper;
import org.apache.shenyu.admin.validation.annotation.Existed;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -49,6 +52,13 @@ public class AuthApplyDTO implements Serializable {

private List<String> pathList;

/**
* namespaceId.
*/
@NotBlank
@Existed(message = "namespaceId is not existed", provider = NamespaceMapper.class)
private String namespaceId;

/**
* Gets the value of appKey.
*
Expand Down Expand Up @@ -193,6 +203,24 @@ public void setPathList(final List<String> pathList) {
this.pathList = pathList;
}

/**
* get namespaceId.
*
* @return namespaceId
*/
public String getNamespaceId() {
return namespaceId;
}

/**
* set namespaceId.
*
* @param namespaceId namespaceId
*/
public void setNamespaceId(final String namespaceId) {
this.namespaceId = namespaceId;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand All @@ -209,11 +237,12 @@ public boolean equals(final Object o) {
&& Objects.equals(appParam, that.appParam)
&& Objects.equals(extInfo, that.extInfo)
&& Objects.equals(open, that.open)
&& Objects.equals(pathList, that.pathList);
&& Objects.equals(pathList, that.pathList)
&& Objects.equals(namespaceId, that.namespaceId);
}

@Override
public int hashCode() {
return Objects.hash(appKey, userId, phone, appName, appParam, extInfo, open, pathList);
return Objects.hash(appKey, userId, phone, appName, appParam, extInfo, open, pathList, namespaceId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

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

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import org.apache.shenyu.admin.mapper.AppAuthMapper;
import org.apache.shenyu.admin.validation.annotation.Existed;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,20 @@ public final class AppAuthDO extends BaseDO {

private String extInfo;

private String namespaceId;

public AppAuthDO() {
}

public AppAuthDO(final String appKey, final String appSecret, final Boolean enabled, final Boolean open, final String userId, final String phone, final String extInfo) {
public AppAuthDO(final String appKey, final String appSecret, final Boolean enabled, final Boolean open, final String userId, final String phone, final String extInfo, final String namespaceId) {
this.appKey = appKey;
this.appSecret = appSecret;
this.enabled = enabled;
this.open = open;
this.userId = userId;
this.phone = phone;
this.extInfo = extInfo;
this.namespaceId = namespaceId;
}

/**
Expand Down Expand Up @@ -199,6 +202,24 @@ public void setExtInfo(final String extInfo) {
this.extInfo = extInfo;
}

/**
* get namespaceId.
*
* @return namespaceId
*/
public String getNamespaceId() {
return namespaceId;
}

/**
* set namespaceId.
*
* @param namespaceId namespaceId
*/
public void setNamespaceId(final String namespaceId) {
this.namespaceId = namespaceId;
}

/**
* Build AppAuthDO object with given AppAuthDTO object.
*
Expand Down Expand Up @@ -243,6 +264,7 @@ public static AppAuthDO create(final AuthApplyDTO authApplyDTO) {
.appSecret(SignUtils.generateKey())
.open(item.getOpen())
.enabled(true)
.namespaceId(item.getNamespaceId())
.dateCreated(currentTime)
.dateUpdated(currentTime)
.build();
Expand Down Expand Up @@ -276,12 +298,13 @@ public boolean equals(final Object o) {
&& open.equals(appAuthDO.open)
&& userId.equals(appAuthDO.userId)
&& phone.equals(appAuthDO.phone)
&& extInfo.equals(appAuthDO.extInfo);
&& extInfo.equals(appAuthDO.extInfo)
&& namespaceId.equals(appAuthDO.namespaceId);
}

@Override
public int hashCode() {
return Objects.hash(appKey, appSecret, enabled, open, userId, phone, extInfo);
return Objects.hash(appKey, appSecret, enabled, open, userId, phone, extInfo, namespaceId);
}

public static final class AppAuthDOBuilder {
Expand All @@ -302,6 +325,8 @@ public static final class AppAuthDOBuilder {

private String id;

private String namespaceId;

private Timestamp dateCreated;

private Timestamp dateUpdated;
Expand Down Expand Up @@ -397,6 +422,17 @@ public AppAuthDOBuilder id(final String id) {
return this;
}

/**
* namespaceId.
*
* @param namespaceId namespaceId
* @return AppAuthDOBuilder
*/
public AppAuthDOBuilder namespaceId(final String namespaceId) {
this.namespaceId = namespaceId;
return this;
}

/**
* dateCreated.
*
Expand Down Expand Up @@ -436,6 +472,7 @@ public AppAuthDO build() {
appAuthDO.setId(id);
appAuthDO.setDateCreated(dateCreated);
appAuthDO.setDateUpdated(dateUpdated);
appAuthDO.setNamespaceId(namespaceId);
return appAuthDO;
}
}
Expand Down
Loading
Loading