Commit 7642dd61 authored by 周健威's avatar 周健威

添加数据中心验证代码

parent 3a0d6a73
...@@ -16,9 +16,14 @@ ...@@ -16,9 +16,14 @@
<dependency> <dependency>
<groupId>maxkey</groupId> <groupId>maxkey</groupId>
<artifactId>maxkey-client-sdk</artifactId> <artifactId>maxkey-client-sdk</artifactId>
<version>3.0.0.RELEASE</version> <version>3.3.0</version>
<type>jar</type>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>maxkey</groupId>-->
<!-- <artifactId>maxkey-client-sdk</artifactId>-->
<!-- <version>3.0.0.RELEASE</version>-->
<!-- <type>jar</type>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>com.nimbusds</groupId> <groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId> <artifactId>nimbus-jose-jwt</artifactId>
......
package com.github.wxiaoqi.security.auth.controller; package com.github.wxiaoqi.security.auth.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.connsec.client.utils.PathUtils;
import com.github.wxiaoqi.security.auth.service.AuthService; import com.github.wxiaoqi.security.auth.service.AuthService;
import com.github.wxiaoqi.security.auth.util.user.JwtAuthenticationRequest; import com.github.wxiaoqi.security.auth.util.user.JwtAuthenticationRequest;
import com.github.wxiaoqi.security.common.constant.RequestTypeConstants; import com.github.wxiaoqi.security.common.constant.RequestTypeConstants;
...@@ -13,8 +12,16 @@ import com.nimbusds.jose.jwk.JWKSet; ...@@ -13,8 +12,16 @@ import com.nimbusds.jose.jwk.JWKSet;
import com.nimbusds.jwt.JWTClaimsSet; import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT; import com.nimbusds.jwt.SignedJWT;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
//import org.maxkey.client.utils.PathUtils; //import org.maxkey.client.utils.PathUtils;
import org.maxkey.client.entity.UserInfo;
import org.maxkey.client.oauth.OAuthClient;
import org.maxkey.client.oauth.builder.ServiceBuilder;
import org.maxkey.client.oauth.builder.api.MaxkeyApi20;
import org.maxkey.client.oauth.model.Token;
import org.maxkey.client.oauth.model.Verifier;
import org.maxkey.client.oauth.oauth.OAuthService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -60,33 +67,50 @@ public class AuthController { ...@@ -60,33 +67,50 @@ public class AuthController {
return new ObjectRestResponse<String>().data(token); return new ObjectRestResponse<String>().data(token);
} }
// @RequestMapping(value = "tokenMaxkey", method = RequestMethod.POST) @RequestMapping(value = "tokenMaxkey", method = RequestMethod.GET)
// public ObjectRestResponse<String> createAuthenticationTokenMaxkey( public ObjectRestResponse<String> createAuthenticationTokenMaxkey(String code, String accessToken,
// @RequestBody JwtAuthenticationRequest authenticationRequest, HttpServletRequest request) throws Exception {
// HttpServletRequest request) throws Exception { log.info(code+" tokenMaxkey code logging...");
// String path = request.getContextPath(); // keliii 分请求类型处理token
// String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; String requestType = request.getHeader(RequestTypeConstants.HEADER_KEY);
// String token=request.getParameter("jwt"); if (requestType == null || requestType.trim().equals("")) {
// System.out.println("jwt "+token); requestType = RequestTypeConstants.BASE;
// SignedJWT signedJWT=null; }
// final String token;
// //JWKSetKeyStore jwkSetKeyStore=new JWKSetKeyStore(); String name = "";
//
// File jwksFile=new File(PathUtils.getInstance().getClassPath()+"jwk.jwks"); OAuthService service = (OAuthService)request.getSession().getAttribute("oauthv20service");
// JWKSet jwkSet= JWKSet.load(jwksFile);
// if(service==null){
// RSASSAVerifier rsaSSAVerifier = new RSASSAVerifier(((RSAKey) jwkSet.getKeyByKeyId("maxkey_rsa")).toRSAPublicKey()); String callback="http://gdxm.upyuns.com/oauth20callback";
// try { service = new ServiceBuilder()
// .provider(MaxkeyApi20.class)
// signedJWT = SignedJWT.parse(token); .apiKey("b32834accb544ea7a9a09dcae4a36403")
// } catch (java.text.ParseException e) { .apiSecret("E9UO53P3JH52aQAcnLP2FlLv8olKIB7u")
// // Invalid signed JWT encoding .callback(callback)
// } .build();
// }
// System.out.println("signedJWT "+signedJWT);
// JWTClaimsSet jwtClaims =signedJWT.getJWTClaimsSet(); Token EMPTY_TOKEN = null;
// return new ObjectRestResponse<String>().data(""); Verifier verifier = new Verifier(request.getParameter("code"));
// } Token accessTokeToken = service.getAccessToken(EMPTY_TOKEN, verifier);
OAuthClient restClient=new OAuthClient("https://gdxm.upyuns.com/sign/api/oauth/v20/me");
UserInfo userInfo=restClient.getUserInfo(accessTokeToken.getAccess_token());
JwtAuthenticationRequest authenticationRequest = new JwtAuthenticationRequest(userInfo.getUsername(), null, JwtAuthenticationRequest.CHECKPASS_NO);
if (RequestTypeConstants.APP.equals(requestType)) {
token = appAuthService.login(authenticationRequest);
} else {
token = authService.login(authenticationRequest);
}
return new ObjectRestResponse<String>().data(token);
}
@Data
public static class TokenMaxkey {
private String token;
private String accessToken;
}
@RequestMapping(value = "token/small", method = RequestMethod.POST) @RequestMapping(value = "token/small", method = RequestMethod.POST)
public ObjectRestResponse<String> createAuthenticationTokenSmall( public ObjectRestResponse<String> createAuthenticationTokenSmall(
......
package com.github.wxiaoqi.security.auth.util.user; package com.github.wxiaoqi.security.auth.util.user;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable; import java.io.Serializable;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class JwtAuthenticationRequest implements Serializable { public class JwtAuthenticationRequest implements Serializable {
private static final long serialVersionUID = -8445943548965154778L; private static final long serialVersionUID = -8445943548965154778L;
public static final int CHECKPASS_NO = 0;
public static final int CHECKPASS_YES = 1;
private String username; private String username;
private String password; private String password;
private Integer checkpass = 1;
public JwtAuthenticationRequest(String username, String password) {
this.username = username;
this.password = password; // public JwtAuthenticationRequest(String username, String password) {
} // this.username = username;
// this.password = password;
public JwtAuthenticationRequest() { // }
} //
// public JwtAuthenticationRequest() {
public String getPassword() { // }
return password; //
} // public String getPassword() {
// return password;
public void setPassword(String password) { // }
this.password = password; //
} // public void setPassword(String password) {
// this.password = password;
public String getUsername() { // }
return username; //
} // public String getUsername() {
// return username;
public void setUsername(String username) { // }
this.username = username; //
} // public void setUsername(String username) {
// this.username = username;
// }
} }
...@@ -46,6 +46,8 @@ import org.springframework.web.server.ServerWebExchange; ...@@ -46,6 +46,8 @@ import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.net.CookieManager;
import java.net.CookieStore;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
...@@ -132,42 +134,44 @@ public class AccessGatewayFilter implements GlobalFilter { ...@@ -132,42 +134,44 @@ public class AccessGatewayFilter implements GlobalFilter {
requestType = requestTypes.get(0); requestType = requestTypes.get(0);
} }
if(null != requestType && !RequestTypeConstants.NOT.equals(requestType)) { // CookieStore cookieStore = HttpRequest.getCookieManager().getCookieStore();
// cookieStore.add("");
}
// String authToken = null;
// if (strings != null) {
// authToken = strings.get(0);
// }
// httpRequest.addHeaders("")
// String authToken = null;
// if(usercenterResult.contains("用户用心")) {
// //退出本地登录
// }else {
// TokenBean tokenBean = JSONUtil.toBean(usercenterResult, TokenBean.class);
// try {
// signedJWT = SignedJWT.parse(tokenBean.getData());
// JWTClaimsSet jwtClaims =signedJWT.getJWTClaimsSet();
// //设置登录
// //
// IJWTInfo user = null; // if(null != requestType && !RequestTypeConstants.NOT.equals(requestType)) {
// String authToken = null;
// httpRequest.addHeaders("")
// String authToken = null;
// Cookie cookie = new Cookie("cookieName", "cookieValue");
// if(usercenterResult.contains("用户用心")) {
// //退出本地登录
// }else {
// TokenBean tokenBean = JSONUtil.toBean(usercenterResult, TokenBean.class);
// try { // try {
// authToken = getAuthTokenFromRequest(request); // signedJWT = SignedJWT.parse(tokenBean.getData());
// IJWTInfo ijwtInfo = userAuthUtil.getInfoFromToken(authToken); // JWTClaimsSet jwtClaims =signedJWT.getJWTClaimsSet();
// if(null == ijwtInfo.getName() || !jwtClaims.getSubject().equals(ijwtInfo.getName())) { // //设置登录
// throw new Exception(); //
// IJWTInfo user = null;
// try {
// authToken = getAuthTokenFromRequest(request);
// IJWTInfo ijwtInfo = userAuthUtil.getInfoFromToken(authToken);
// if(null == ijwtInfo.getName() || !jwtClaims.getSubject().equals(ijwtInfo.getName())) {
// throw new Exception();
// }
// } catch (Exception e) {
// log.error("未登录,直接登录", e);
// ObjectRestResponse<String> restResponseToken = userService.createAuthenticationToken(jwtClaims.getSubject());
// authToken = restResponseToken.getData();
// } // }
// } catch (Exception e) { // } catch (java.text.ParseException e) {
// log.error("未登录,直接登录", e); // log.error(e.getMessage(), e);
// ObjectRestResponse<String> restResponseToken = userService.createAuthenticationToken(jwtClaims.getSubject());
// authToken = restResponseToken.getData();
// } // }
// } catch (java.text.ParseException e) {
// log.error(e.getMessage(), e);
// } // }
// request.getHeaders().set(userAuthConfig.getTokenHeader(), authToken);
// } // }
// request.getHeaders().set(userAuthConfig.getTokenHeader(), authToken);
//end
// setLogService(serverWebExchange, gatewayFilterChain); // setLogService(serverWebExchange, gatewayFilterChain);
String requestUri = request.getPath().pathWithinApplication().value(); String requestUri = request.getPath().pathWithinApplication().value();
......
...@@ -60,7 +60,17 @@ public class AppUserRest { ...@@ -60,7 +60,17 @@ public class AppUserRest {
@RequestMapping(value = "/user/validate", method = RequestMethod.POST) @RequestMapping(value = "/user/validate", method = RequestMethod.POST)
public @ResponseBody public @ResponseBody
AppUserInfo validate(@RequestBody Map<String,String> body){ AppUserInfo validate(@RequestBody Map<String,String> body){
return appPermissionService.validate(body.get("username"),body.get("password")); if(null != body.get("checkpass") && body.get("checkpass") == "0") {
AppUserInfo info = new AppUserInfo();
AppUserLogin user = appUserLoginBiz.checkeUserLogin(body.get("username"));
if (user != null ) {
info.setUsername(user.getUsername());
info.setId(user.getId() + "");
}
return info;
}else {
return appPermissionService.validate(body.get("username"),body.get("password"));
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment