-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
smallchill
committed
Apr 29, 2023
1 parent
647d85e
commit fd5135e
Showing
40 changed files
with
291 additions
and
253 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
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
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
24 changes: 24 additions & 0 deletions
24
blade-auth/src/test/java/org/springblade/test/SignKeyGenerator.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,24 @@ | ||
package org.springblade.test; | ||
|
||
import org.springblade.core.tool.utils.RandomType; | ||
import org.springblade.core.tool.utils.StringUtil; | ||
|
||
/** | ||
* signKey生成器 | ||
* | ||
* @author Chill | ||
*/ | ||
public class SignKeyGenerator { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("======================================================="); | ||
for (int i = 0; i < 10; i++) { | ||
String signKey = StringUtil.random(32, RandomType.ALL); | ||
System.out.println("SpringBlade SignKey:[" + signKey + "] "); | ||
} | ||
System.out.println("======================================================="); | ||
System.out.println("====== blade.token.sign-key 的值从中挑选一个便可 ========="); | ||
System.out.println("======================================================="); | ||
} | ||
|
||
} |
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
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
44 changes: 44 additions & 0 deletions
44
blade-gateway/src/main/java/org/springblade/gateway/config/JwtConfiguration.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,44 @@ | ||
/** | ||
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 ([email protected]). | ||
* <p> | ||
* Licensed 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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 org.springblade.gateway.config; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springblade.gateway.props.JwtProperties; | ||
import org.springblade.gateway.utils.JwtUtil; | ||
import org.springframework.beans.factory.SmartInitializingSingleton; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* JWT配置信息 | ||
* | ||
* @author Chill | ||
*/ | ||
@Slf4j | ||
@Configuration(proxyBeanMethods = false) | ||
@AllArgsConstructor | ||
@EnableConfigurationProperties({JwtProperties.class}) | ||
public class JwtConfiguration implements SmartInitializingSingleton { | ||
|
||
private final JwtProperties properties; | ||
|
||
@Override | ||
public void afterSingletonsInstantiated() { | ||
JwtUtil.setJwtProperties(properties); | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
blade-gateway/src/main/java/org/springblade/gateway/props/JwtProperties.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,58 @@ | ||
/* | ||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* Neither the name of the dreamlu.net developer nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* Author: Chill 庄骞 ([email protected]) | ||
*/ | ||
package org.springblade.gateway.props; | ||
|
||
import io.jsonwebtoken.JwtException; | ||
import lombok.Data; | ||
import org.springblade.core.launch.constant.TokenConstant; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
/** | ||
* JWT配置 | ||
* | ||
* @author Chill | ||
*/ | ||
@Data | ||
@ConfigurationProperties("blade.token") | ||
public class JwtProperties { | ||
|
||
/** | ||
* token是否有状态 | ||
*/ | ||
private Boolean state = Boolean.FALSE; | ||
|
||
/** | ||
* 是否只可同时在线一人 | ||
*/ | ||
private Boolean single = Boolean.FALSE; | ||
|
||
/** | ||
* token签名 | ||
*/ | ||
private String signKey = ""; | ||
|
||
/** | ||
* 获取签名规则 | ||
*/ | ||
public String getSignKey() { | ||
if (this.signKey.length() < TokenConstant.SIGN_KEY_LENGTH) { | ||
throw new JwtException("请配置 blade.token.sign-key 的值, 长度32位以上"); | ||
} | ||
return this.signKey; | ||
} | ||
|
||
} |
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
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
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
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
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
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
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
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
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
Oops, something went wrong.