doc: 新增 README.md

11111
winter 1 year ago
parent c1e2a62527
commit 46fa7bf45e

@ -0,0 +1,8 @@
# TeamModel extension
> SpringBoot base version of TeamModel extension
>
> **注意**: 所有复盘输出均已脱敏,不包含任何业务,密码等关键信息
## 迁移目录:
- Azure OIDC(SSO) 迁移
- id-token(jwt) 验证迁移 (出现语言框架之间的签名算法规范问题,解决见: [输出复盘](https://juejin.cn/post/7300036605099163702))

@ -57,6 +57,13 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- dingding -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>

@ -25,12 +25,10 @@ import java.util.stream.Collectors;
@Component @Component
@Slf4j @Slf4j
public class JwtTokenUtil { public class JwtTokenUtil {
private static final String CLAIM_KEY_USERNAME = "sub"; private static final long NEVER_EXPIRE = 315360000; // 没有永不过期的api: 让时钟偏移十年
private static final String CLAIM_KEY_CREATED = "created";
@Value("${jwt.secret}") @Value("${jwt.secret}")
private String secret; private String secret;
private Integer expiration = 30;
/** /**
* token * token
@ -40,27 +38,19 @@ public class JwtTokenUtil {
@Deprecated @Deprecated
public String generateToken(UserDetails userDetails){ public String generateToken(UserDetails userDetails){
Map<String, Object> claims = new HashMap<>(); Map<String, Object> claims = new HashMap<>();
claims.put(CLAIM_KEY_USERNAME,userDetails.getUsername()); // 添加 payload
claims.put(CLAIM_KEY_CREATED,new Date()); //claims.put(CLAIM_KEY_USERNAME,userDetails.getUsername());
//claims.put(CLAIM_KEY_CREATED,new Date());
return generateToken(claims); return generateToken(claims);
} }
@Deprecated @Deprecated
private String generateToken(Map<String,Object> claims){ private String generateToken(Map<String,Object> claims){
return Jwts.builder() return Jwts.builder()
.setClaims(claims) .setClaims(claims)
.setExpiration(getExpirationDate())
.signWith(SignatureAlgorithm.HS512,secret) .signWith(SignatureAlgorithm.HS512,secret)
.compact(); .compact();
} }
/**
* token
* @return
*/
private Date getExpirationDate() {
return new Date(System.currentTimeMillis() + expiration * 1000);
}
/** /**
* token * token
* @param token token * @param token token
@ -88,10 +78,11 @@ public class JwtTokenUtil {
try { try {
claims = Jwts.parser() claims = Jwts.parser()
.setSigningKey(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256")) .setSigningKey(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"))
.setAllowedClockSkewSeconds(NEVER_EXPIRE)
.parseClaimsJws(token) .parseClaimsJws(token)
.getBody(); .getBody();
} catch (Exception e) { } catch (Exception e) {
log.info("jwt解析出错:{}",token); log.warn("token 解析出错:{}",e.getMessage());
} }
return claims; return claims;
} }

@ -15,3 +15,6 @@ spring:
jwt: jwt:
secret: fXO6ko/qyXeYrkecPeKdgXnuLXf9vMEtnBC9OB3s+aA= secret: fXO6ko/qyXeYrkecPeKdgXnuLXf9vMEtnBC9OB3s+aA=
dingding:
server-url: https://oapi.dingtalk.com/robot/send?access_token=32d9b24f69c2c4fd7c2dab43268b6258a7214d2620e0805d7b6d1429003b64b6

@ -1,7 +1,14 @@
package cn.teammodel; package cn.teammodel;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import com.taobao.api.ApiException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays;
/** /**
* @author winter * @author winter
* @create 2023-11-10 10:42 * @create 2023-11-10 10:42
@ -22,4 +29,38 @@ public class TestWithoutSpring {
// e.printStackTrace(); // e.printStackTrace();
// } // }
} }
@Test
public void testDingDing() throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token=32d9b24f69c2c4fd7c2dab43268b6258a7214d2620e0805d7b6d1429003b64b6");
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("text");
OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
text.setContent("测试告警文本消息");
request.setText(text);
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
at.setAtMobiles(Arrays.asList("15196506772"));
// isAtAll类型如果不为Boolean请升级至最新SDK
at.setIsAtAll(true);
at.setAtUserIds(Arrays.asList("109929","32099"));
request.setAt(at);
request.setMsgtype("link");
OapiRobotSendRequest.Link link = new OapiRobotSendRequest.Link();
link.setMessageUrl("https://www.dingtalk.com/");
link.setPicUrl("");
link.setTitle("告警时代的火车向前开");
link.setText("告警这个即将发布的新版本创始人xx称它为红树林。而在此之前每当面临重大升级产品经理们都会取一个应景的代号这一次为什么是红树林");
request.setLink(link);
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
markdown.setTitle("杭州天气");
markdown.setText("#### 告警杭州天气 @156xxxx8827\n" +
"> 9度西北风1级空气良89相对温度73%\n\n" +
"> ![screenshot](https://gw.alicdn.com/tfs/TB1ut3xxbsrBKNjSZFpXXcXhFXa-846-786.png)\n" +
"> ###### 10点20分发布 [天气](http://www.thinkpage.cn/) \n");
request.setMarkdown(markdown);
OapiRobotSendResponse response = client.execute(request);
}
} }

Loading…
Cancel
Save