-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,573 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
.../integration-tests/src/main/java/io/quarkiverse/satoken/resteasy/it/StpInterfaceImpl.java
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
...y/integration-tests/src/main/java/io/quarkiverse/satoken/resteasy/it/TestApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.quarkiverse.satoken.resteasy.it; | ||
|
||
import io.quarkus.runtime.Quarkus; | ||
import io.quarkus.runtime.annotations.QuarkusMain; | ||
|
||
@QuarkusMain | ||
public class TestApplication { | ||
public static void main(String... args) { | ||
Quarkus.run(args); | ||
} | ||
} |
139 changes: 139 additions & 0 deletions
139
...main/java/io/quarkiverse/satoken/resteasy/it/configuration/RouterFilterConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package io.quarkiverse.satoken.resteasy.it.configuration; | ||
|
||
import cn.dev33.satoken.context.SaHolder; | ||
import cn.dev33.satoken.router.SaHttpMethod; | ||
import cn.dev33.satoken.router.SaRouter; | ||
import cn.dev33.satoken.stp.StpUtil; | ||
import cn.dev33.satoken.util.SaResult; | ||
import io.quarkiverse.satoken.core.filter.SaRouteInterceptor; | ||
import io.quarkus.arc.Priority; | ||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.arc.profile.IfBuildProfile; | ||
import io.vertx.ext.web.RoutingContext; | ||
import org.jboss.resteasy.reactive.server.core.CurrentRequestManager; | ||
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext; | ||
|
||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.inject.Produces; | ||
import javax.enterprise.inject.spi.CDI; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* RouterFilterConfiguration | ||
* | ||
* @author nayan | ||
* @date 2022/10/9 16:20 | ||
*/ | ||
@Dependent | ||
public class RouterFilterConfiguration { | ||
|
||
@Produces | ||
@Unremovable | ||
@Priority(1) | ||
public SaRouteInterceptor configure2() { | ||
return new SaRouteInterceptor("/**", handle -> { | ||
|
||
// 匹配 getInfo ,返回code=201 | ||
SaRouter.match("/**") | ||
.match(SaHttpMethod.POST) | ||
.matchMethod("POST") | ||
.match(SaHolder.getRequest().getMethod().equals("POST")) | ||
.match(r -> SaHolder.getRequest().isPath("/rt/getInfo")) | ||
.match(r -> SaHolder.getRequest().isParam("name", "zhang")) | ||
.back(SaResult.code(201)); | ||
|
||
// 匹配 getInfo2 ,返回code=202 | ||
SaRouter.match("/rt/getInfo2") | ||
.match(Arrays.asList("/rt/getInfo2", "/rt/*")) | ||
.notMatch("/rt/getInfo3") | ||
.notMatch(false) | ||
.notMatch(r -> false) | ||
.notMatch(SaHttpMethod.GET) | ||
.notMatchMethod("PUT") | ||
.notMatch(Arrays.asList("/rt/getInfo4", "/rt/getInfo5")) | ||
.back(SaResult.code(202)); | ||
|
||
// 匹配 getInfo3 ,返回code=203 | ||
SaRouter.match("/rt/getInfo3", "/rt/getInfo4", () -> SaRouter.back(SaResult.code(203))); | ||
SaRouter.match("/rt/getInfo4", "/rt/getInfo5", r -> SaRouter.back(SaResult.code(204))); | ||
SaRouter.match("/rt/getInfo5", () -> SaRouter.back(SaResult.code(205))); | ||
SaRouter.match("/rt/getInfo6", r -> SaRouter.back(SaResult.code(206))); | ||
|
||
// 通往 Controller | ||
SaRouter.match(Arrays.asList("/rt/getInfo7")).stop(); | ||
|
||
// 通往 Controller | ||
SaRouter.match("/rt/getInfo8", () -> SaRouter.stop()); | ||
|
||
SaRouter.matchMethod("POST").match("/rt/getInfo9").free(r -> SaRouter.back(SaResult.code(209))); | ||
SaRouter.match(SaHttpMethod.POST).match("/rt/getInfo10").setHit(false).back(); | ||
|
||
// 11 | ||
SaRouter.notMatch("/rt/getInfo11").reset().match("/rt/getInfo11").back(SaResult.code(211)); | ||
SaRouter.notMatch(SaHttpMethod.GET).match("/rt/getInfo12").back(SaResult.code(212)); | ||
SaRouter.notMatch(Arrays.asList("/rt/getInfo12", "/rt/getInfo14")).match("/rt/getInfo13").back(SaResult.code(213)); | ||
SaRouter.notMatchMethod("GET", "PUT").match("/rt/getInfo14").back(SaResult.code(214)); | ||
|
||
// SaRouter.match(Arrays.asList("/rt/getInfo15", "/rt/getInfo16")) | ||
ResteasyReactiveRequestContext resteasyReactiveRequestContext = CurrentRequestManager.get(); | ||
if (SaRouter.isMatchCurrURI("/rt/getInfo15")) { | ||
if (SaHolder.getRequest().getCookieValue("ddd") == null | ||
&& SaHolder.getStorage().getSource() ==resteasyReactiveRequestContext | ||
&& SaHolder.getRequest().getSource() == resteasyReactiveRequestContext | ||
&& SaHolder.getResponse().getSource() == resteasyReactiveRequestContext.serverResponse() | ||
) { | ||
SaRouter.newMatch().free(r -> SaRouter.back(SaResult.code(215))); | ||
} | ||
} | ||
|
||
SaRouter.match("/rt/getInfo16", () -> { | ||
try { | ||
SaHolder.getResponse().redirect(null); | ||
} catch (Exception e) { | ||
|
||
} | ||
SaHolder.getResponse().redirect("/rt/getInfo3"); | ||
}); | ||
}); | ||
} | ||
|
||
@Produces | ||
@Unremovable | ||
@IfBuildProfile("route") | ||
@Priority(100) | ||
public SaRouteInterceptor configure31() { | ||
return new SaRouteInterceptor("/rt/getInfo_200", handle -> { | ||
SaRouter.stop(); | ||
}); | ||
} | ||
|
||
@Produces | ||
@Unremovable | ||
@IfBuildProfile("route") | ||
@Priority(100) | ||
public SaRouteInterceptor configure32() { | ||
return new SaRouteInterceptor("/rt/getInfo_201", handle -> { | ||
StpUtil.checkLogin(); | ||
}); | ||
} | ||
|
||
@Produces | ||
@Unremovable | ||
@IfBuildProfile("route") | ||
@Priority(101) | ||
public SaRouteInterceptor configure33() { | ||
return new SaRouteInterceptor("/rt/getInfo_201", handle -> { | ||
SaRouter.back(SaResult.code(201)); | ||
}); | ||
} | ||
|
||
@Produces | ||
@Unremovable | ||
@IfBuildProfile("route") | ||
@Priority(100) | ||
public SaRouteInterceptor configure34() { | ||
return new SaRouteInterceptor("/rt/getInfo_202", handle -> { | ||
StpUtil.checkLogin(); | ||
}); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...main/java/io/quarkiverse/satoken/resteasy/it/configuration/StpInterfaceConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package io.quarkiverse.satoken.resteasy.it.configuration; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.inject.Produces; | ||
|
||
import cn.dev33.satoken.stp.StpInterface; | ||
import cn.dev33.satoken.util.SaFoxUtil; | ||
import io.quarkus.arc.DefaultBean; | ||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.arc.profile.IfBuildProfile; | ||
|
||
/** | ||
* StpInterfaceConfiguration | ||
* | ||
* @author nayan | ||
* @date 2022/10/8 18:55 | ||
*/ | ||
|
||
@Dependent | ||
public class StpInterfaceConfiguration { | ||
|
||
@Produces | ||
@Unremovable | ||
@IfBuildProfile("annotation") | ||
public StpInterface annotation() { | ||
return new StpInterface() { | ||
/** | ||
* 返回一个账号所拥有的权限码集合 | ||
*/ | ||
@Override | ||
public List<String> getPermissionList(Object loginId, String loginType) { | ||
int id = SaFoxUtil.getValueByType(loginId, int.class); | ||
if (id == 10001) { | ||
return Arrays.asList("user*", "art-add", "art-delete", "art-update", "art-get"); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* 返回一个账号所拥有的角色标识集合 | ||
*/ | ||
@Override | ||
public List<String> getRoleList(Object loginId, String loginType) { | ||
int id = SaFoxUtil.getValueByType(loginId, int.class); | ||
if (id == 10001) { | ||
return Arrays.asList("admin", "super-admin"); | ||
} else { | ||
return null; | ||
} | ||
} | ||
}; | ||
} | ||
|
||
@Produces | ||
@Unremovable | ||
@DefaultBean | ||
public StpInterface noopTracer() { | ||
return new StpInterface() { | ||
/** | ||
* 返回一个账号所拥有的权限码集合 | ||
*/ | ||
@Override | ||
public List<String> getPermissionList(Object loginId, String loginType) { | ||
int id = SaFoxUtil.getValueByType(loginId, int.class); | ||
if(id == 10001) { | ||
return Arrays.asList("user*", "art-add", "art-delete", "art-update", "art-get"); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* 返回一个账号所拥有的角色标识集合 | ||
*/ | ||
@Override | ||
public List<String> getRoleList(Object loginId, String loginType) { | ||
int id = SaFoxUtil.getValueByType(loginId, int.class); | ||
if(id == 10001) { | ||
return Arrays.asList("admin", "super-admin"); | ||
} else { | ||
return null; | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...ration-tests/src/main/java/io/quarkiverse/satoken/resteasy/it/integrate/MoreResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 io.quarkiverse.satoken.resteasy.it.integrate; | ||
|
||
import cn.dev33.satoken.basic.SaBasicUtil; | ||
import cn.dev33.satoken.context.SaHolder; | ||
import cn.dev33.satoken.context.model.SaRequest; | ||
import cn.dev33.satoken.util.SaFoxUtil; | ||
import cn.dev33.satoken.util.SaResult; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
|
||
@Path("/more/") | ||
@ApplicationScoped | ||
public class MoreResource { | ||
|
||
// 一些基本的测试 | ||
@POST | ||
@Path("getInfo") | ||
public SaResult getInfo() { | ||
SaRequest req = SaHolder.getRequest(); | ||
boolean flag = | ||
SaFoxUtil.equals(req.getParam("name"), "zhang") | ||
&& SaFoxUtil.equals(req.getParam("name2", "li"), "li") | ||
&& SaFoxUtil.equals(req.getParamNotNull("name"), "zhang") | ||
&& req.isParam("name", "zhang") | ||
&& req.isPath("/more/getInfo") | ||
&& req.hasParam("name") | ||
&& SaFoxUtil.equals(req.getHeader("div"), "val") | ||
&& SaFoxUtil.equals(req.getHeader("div", "zhang"), "val") | ||
&& SaFoxUtil.equals(req.getHeader("div2", "zhang"), "zhang"); | ||
|
||
SaHolder.getResponse().setServer("sa-server"); | ||
return SaResult.data(flag); | ||
} | ||
|
||
// Http Basic 认证 | ||
@POST | ||
@Path("basicAuth") | ||
public SaResult basicAuth() { | ||
SaBasicUtil.check("sa:123456"); | ||
return SaResult.ok(); | ||
} | ||
} |
Oops, something went wrong.