[go: nahoru, domu]

Skip to content

Commit

Permalink
!298 优化 solon 相关的 demo 代码
Browse files Browse the repository at this point in the history
Merge pull request !298 from 西东/dev
  • Loading branch information
click33 authored and gitee-org committed May 11, 2024
2 parents 89a69e5 + e024457 commit 26bf2bd
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 47 deletions.
2 changes: 1 addition & 1 deletion sa-token-demo/sa-token-demo-solon-redisson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>2.4.0</version>
<version>2.7.0</version>
<relativePath/>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion sa-token-demo/sa-token-demo-solon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>2.4.0</version>
<version>2.7.0</version>
<relativePath/>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>2.4.0</version>
<version>2.7.0</version>
<relativePath/>
</parent>

<!-- 定义 Sa-Token 版本号 -->
<properties>
<sa-token.version>1.38.0</sa-token.version>
<solon.version>2.2.3</solon.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class SsoConfig {
* 构建建 SaToken redis dao(如果不需要 redis;可以注释掉)
* */
@Bean
public SaTokenDao saTokenDaoInit(@Inject("${sa-token.redis}") SaTokenDaoOfRedis saTokenDao) {
public SaTokenDao saTokenDaoInit(@Inject("${sa-token.dao.redis}") SaTokenDaoOfRedis saTokenDao) {
return saTokenDao;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sa-token:
secret-key: kQwIOrYvnXmSDkwEiFngrKidMcdrgKor
# ---- 除了以上配置项,你还需要为 Sa-Token 配置http请求处理器(文档有步骤说明)

sa-token: #名字可以随意取
sa-token.dao: #名字可以随意取
redis:
server: "localhost:6379"
password: 123456
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>2.4.0</version>
<version>2.7.0</version>
<relativePath/>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SaConfig {
* 配置 Sa-Token 单独使用的Redis连接 (此处需要和SSO-Server端连接同一个Redis)
* */
@Bean
public SaTokenDao saTokenDaoInit(@Inject("${sa-token.redis}") SaTokenDaoOfRedis saTokenDao) {
public SaTokenDao saTokenDaoInit(@Inject("${sa-token.dao.redis}") SaTokenDaoOfRedis saTokenDao) {
return saTokenDao;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sa-token:
slo-url: http://sso.stp.com:9000/sso/signout

# 配置 Sa-Token 单独使用的Redis连接 (此处需要和SSO-Server端连接同一个Redis)
sa-token: #名字可以随意取
sa-token.dao: #名字可以随意取
redis:
server: "localhost:6379"
password: 123456
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>2.4.0</version>
<version>2.7.0</version>
<relativePath/>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SaConfig {
* 配置 Sa-Token 单独使用的Redis连接 (此处需要和SSO-Server端连接同一个Redis)
* */
@Bean
public SaTokenDao saTokenDaoInit(@Inject("${sa-token.redis}") SaTokenDaoOfRedis saTokenDao) {
public SaTokenDao saTokenDaoInit(@Inject("${sa-token.dao.redis}") SaTokenDaoOfRedis saTokenDao) {
return saTokenDao;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 端口
server:
port: 9001
port: 9002

# sa-token配置
sa-token:
Expand All @@ -13,7 +13,7 @@ sa-token:
is-slo: true

# 配置 Sa-Token 单独使用的Redis连接 (此处需要和SSO-Server端连接同一个Redis)
sa-token: #名字可以随意取
sa-token.dao: #名字可以随意取
redis:
server: "localhost:6379"
password: 123456
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>2.4.0</version>
<version>2.7.0</version>
<relativePath/>
</parent>

Expand All @@ -26,6 +26,12 @@
<groupId>org.noear</groupId>
<artifactId>solon-api</artifactId>
</dependency>

<!-- Http 请求工具 -->
<dependency>
<groupId>org.noear</groupId>
<artifactId>forest-solon-plugin</artifactId>
</dependency>

<!-- Sa-Token 权限认证, 在线文档:https://sa-token.cc/ -->
<dependency>
Expand All @@ -47,15 +53,7 @@
<artifactId>sa-token-redisx</artifactId>
<version>${sa-token.version}</version>
</dependency>

<!-- Http 请求工具 -->
<dependency>
<groupId>com.dtflys.forest</groupId>
<artifactId>forest-solon-plugin</artifactId>
<version>1.5.29</version>
</dependency>



</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SaConfig {
* 构建建 SaToken redis dao(如果不需要 redis;可以注释掉)
* */
@Bean
public SaTokenDao saTokenDaoInit(@Inject("${sa-token.redis}") SaTokenDaoOfRedis saTokenDao) {
public SaTokenDao saTokenDaoInit(@Inject("${sa-token.dao.redis}") SaTokenDaoOfRedis saTokenDao) {
return saTokenDao;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 端口
server:
port: 9001
port: 9003

# sa-token配置
sa-token:
Expand All @@ -23,7 +23,7 @@ sa-token:


# 配置 Sa-Token Dao(此处与SSO-Server端连接不同的Redis)
sa-token: #名字可以随意取
sa-token.dao: #名字可以随意取
redis:
server: "localhost:6379"
password: 123456
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.AppContext;
import org.noear.solon.core.bean.InitializingBean;

/**
* @author noear
Expand All @@ -33,12 +32,9 @@

@Condition(onClass = SaOAuth2Manager.class)
@Configuration
public class SaOAuth2AutoConfigure implements InitializingBean {
@Inject
private AppContext appContext;

@Override
public void afterInjection() throws Throwable {
public class SaOAuth2AutoConfigure {
@Bean
public void init(AppContext appContext) throws Throwable {
appContext.subBeansOfType(SaOAuth2Template.class, bean -> {
SaOAuth2Util.saOAuth2Template = bean;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,37 @@

@Condition(onClass = SaSsoManager.class)
@Configuration
public class SaSsoAutoConfigure implements InitializingBean {
@Inject
private AppContext appContext;

@Override
public void afterInjection() throws Throwable {
appContext.subBeansOfType(SaSsoServerTemplate.class, bean->{
public class SaSsoAutoConfigure {
@Bean
public void init(AppContext appContext) throws Throwable {
appContext.subBeansOfType(SaSsoServerTemplate.class, bean -> {
SaSsoServerProcessor.instance.ssoServerTemplate = bean;
});
appContext.subBeansOfType(SaSsoClientTemplate.class, bean->{
appContext.subBeansOfType(SaSsoClientTemplate.class, bean -> {
SaSsoClientProcessor.instance.ssoClientTemplate = bean;
});

appContext.subBeansOfType(SaSsoServerConfig.class, bean->{
appContext.subBeansOfType(SaSsoServerConfig.class, bean -> {
SaSsoManager.setServerConfig(bean);
});
appContext.subBeansOfType(SaSsoClientConfig.class, bean->{
appContext.subBeansOfType(SaSsoClientConfig.class, bean -> {
SaSsoManager.setClientConfig(bean);
});
}

/**
* 获取 SSO Server 配置Bean
* */
*/
@Bean
public SaSsoServerConfig getConfig(@Inject(value = "${sa-token.sso-server}",required = false) SaSsoServerConfig ssoConfig) {
public SaSsoServerConfig getConfig(@Inject(value = "${sa-token.sso-server}", required = false) SaSsoServerConfig ssoConfig) {
return ssoConfig;
}

/**
* 获取 SSO Client 配置Bean
* */
*/
@Bean
public SaSsoClientConfig getClientConfig(@Inject(value = "${sa-token.sso-client}",required = false) SaSsoClientConfig ssoConfig) {
public SaSsoClientConfig getClientConfig(@Inject(value = "${sa-token.sso-client}", required = false) SaSsoClientConfig ssoConfig) {
return ssoConfig;
}
}

0 comments on commit 26bf2bd

Please sign in to comment.