1.增加异常枚举
2.完善Access_Token的获取接口代码
This commit is contained in:
parent
4d4b8f58bd
commit
47b2796c27
56
pom.xml
56
pom.xml
@ -61,36 +61,36 @@
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<!-- gson -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.google.code.gson</groupId>-->
|
||||
<!-- <artifactId>gson</artifactId>-->
|
||||
<!-- <version>2.8.5</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- 邮件 -->
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>javax.mail</artifactId>
|
||||
<version>1.6.2</version>
|
||||
</dependency>
|
||||
<!-- jackson json处理 -->
|
||||
<!-- Jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.4</version>
|
||||
</dependency>
|
||||
<!-- <!– 邮件 –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.sun.mail</groupId>-->
|
||||
<!-- <artifactId>javax.mail</artifactId>-->
|
||||
<!-- <version>1.6.2</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <!– jackson json处理 –>-->
|
||||
<!-- <!– Jackson –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.fasterxml.jackson.core</groupId>-->
|
||||
<!-- <artifactId>jackson-databind</artifactId>-->
|
||||
<!-- <version>2.9.4</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- fastJson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>2.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.9.4</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.fasterxml.jackson.core</groupId>-->
|
||||
<!-- <artifactId>jackson-annotations</artifactId>-->
|
||||
<!-- <version>2.9.4</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.fasterxml.jackson.core</groupId>-->
|
||||
<!-- <artifactId>jackson-core</artifactId>-->
|
||||
<!-- <version>2.9.4</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- 日志处理 -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
@ -9,13 +9,14 @@ package com.dnslin.onemanager.logic;
|
||||
*/
|
||||
public interface AuthToken {
|
||||
/**
|
||||
* 功能描述
|
||||
* 获取AccessToken
|
||||
* @author dnslin
|
||||
* @date 10/25
|
||||
* @param clientId
|
||||
* @param redirectUri
|
||||
* @param clientSecret
|
||||
* @return
|
||||
*/
|
||||
String getAccessToken(String clientId, String redirectUri);
|
||||
void getAccessToken(String clientId, String redirectUri,String clientSecret);
|
||||
String getRefreshToken();
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.dnslin.onemanager.logic.impl;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dnslin.onemanager.exception.AppException;
|
||||
import com.dnslin.onemanager.logic.AuthToken;
|
||||
import com.dnslin.onemanager.result.ResponseEnum;
|
||||
@ -24,14 +26,26 @@ public class AuthTokenImpl extends HttpServlet implements AuthToken {
|
||||
private final ServletContext context = this.getServletContext();
|
||||
|
||||
@Override
|
||||
public String getAccessToken(String clientId, String redirectUri) {
|
||||
String code = (String)context.getAttribute("code");
|
||||
if (code == null || code.isEmpty()){
|
||||
throw new AppException(ResponseEnum.SYSTEM_ERROR);
|
||||
public void getAccessToken(String clientId, String redirectUri, String clientSecret) {
|
||||
String code = (String) context.getAttribute("code");
|
||||
if (code == null || code.isEmpty()) {
|
||||
throw new AppException(ResponseEnum.AUTH_CODE_ISNULL);
|
||||
}
|
||||
Map<String, String> param = new HashMap<String, String>();
|
||||
HttpClientUtils.doPost("",param);
|
||||
return null;
|
||||
param.put("client_id", clientId);
|
||||
param.put("scope", "files.readwrite.all files.readwrite offline_access");
|
||||
param.put("code", code);
|
||||
param.put("redirect_uri", redirectUri);
|
||||
param.put("grant_type", "authorization_code");
|
||||
param.put("client_secret", clientSecret);
|
||||
String accessJson = HttpClientUtils.doPost("https://login.microsoftonline.com/common/oauth2/v2.0/token", param).getContent();
|
||||
if (accessJson == null || accessJson.isEmpty()) {
|
||||
throw new AppException(ResponseEnum.THE_RESULT_SET_IS_EMPTY);
|
||||
}
|
||||
Console.log("结果集accessJson:==>" + accessJson);
|
||||
String access_token = JSONObject.parseObject(accessJson).getString("access_token");
|
||||
Console.log("Access_token:==>" + access_token);
|
||||
context.setAttribute("access_token",access_token);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,7 +10,8 @@ public enum ResponseEnum {
|
||||
Cookie_not_found("4004","Cookie获取失败"),
|
||||
Token_invalid("4005","Token失效"),
|
||||
PARAMETERS_ARE_MISSING("4006","参数缺失"),
|
||||
AUTH_CODE_ISNULL("4007","Auth Code 为空");
|
||||
AUTH_CODE_ISNULL("4007","Auth Code 为空"),
|
||||
THE_RESULT_SET_IS_EMPTY("4008","请求结果集为Null,请联系管理员");
|
||||
|
||||
|
||||
private String code;
|
||||
|
Loading…
Reference in New Issue
Block a user