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

添加数据中心验证代码

parent 3a0d6a73
......@@ -16,9 +16,14 @@
<dependency>
<groupId>maxkey</groupId>
<artifactId>maxkey-client-sdk</artifactId>
<version>3.0.0.RELEASE</version>
<type>jar</type>
<version>3.3.0</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>maxkey</groupId>-->
<!-- <artifactId>maxkey-client-sdk</artifactId>-->
<!-- <version>3.0.0.RELEASE</version>-->
<!-- <type>jar</type>-->
<!-- </dependency>-->
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
......
package com.github.wxiaoqi.security.auth.controller;
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.util.user.JwtAuthenticationRequest;
import com.github.wxiaoqi.security.common.constant.RequestTypeConstants;
......@@ -13,8 +12,16 @@ import com.nimbusds.jose.jwk.JWKSet;
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;
import io.swagger.annotations.Api;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
//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.Qualifier;
import org.springframework.beans.factory.annotation.Value;
......@@ -60,33 +67,50 @@ public class AuthController {
return new ObjectRestResponse<String>().data(token);
}
// @RequestMapping(value = "tokenMaxkey", method = RequestMethod.POST)
// public ObjectRestResponse<String> createAuthenticationTokenMaxkey(
// @RequestBody JwtAuthenticationRequest authenticationRequest,
// HttpServletRequest request) throws Exception {
// String path = request.getContextPath();
// String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
// String token=request.getParameter("jwt");
// System.out.println("jwt "+token);
// SignedJWT signedJWT=null;
//
// //JWKSetKeyStore jwkSetKeyStore=new JWKSetKeyStore();
//
// File jwksFile=new File(PathUtils.getInstance().getClassPath()+"jwk.jwks");
// JWKSet jwkSet= JWKSet.load(jwksFile);
//
// RSASSAVerifier rsaSSAVerifier = new RSASSAVerifier(((RSAKey) jwkSet.getKeyByKeyId("maxkey_rsa")).toRSAPublicKey());
// try {
//
// signedJWT = SignedJWT.parse(token);
// } catch (java.text.ParseException e) {
// // Invalid signed JWT encoding
// }
//
// System.out.println("signedJWT "+signedJWT);
// JWTClaimsSet jwtClaims =signedJWT.getJWTClaimsSet();
// return new ObjectRestResponse<String>().data("");
// }
@RequestMapping(value = "tokenMaxkey", method = RequestMethod.GET)
public ObjectRestResponse<String> createAuthenticationTokenMaxkey(String code, String accessToken,
HttpServletRequest request) throws Exception {
log.info(code+" tokenMaxkey code logging...");
// keliii 分请求类型处理token
String requestType = request.getHeader(RequestTypeConstants.HEADER_KEY);
if (requestType == null || requestType.trim().equals("")) {
requestType = RequestTypeConstants.BASE;
}
final String token;
String name = "";
OAuthService service = (OAuthService)request.getSession().getAttribute("oauthv20service");
if(service==null){
String callback="http://gdxm.upyuns.com/oauth20callback";
service = new ServiceBuilder()
.provider(MaxkeyApi20.class)
.apiKey("b32834accb544ea7a9a09dcae4a36403")
.apiSecret("E9UO53P3JH52aQAcnLP2FlLv8olKIB7u")
.callback(callback)
.build();
}
Token EMPTY_TOKEN = null;
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)
public ObjectRestResponse<String> createAuthenticationTokenSmall(
......
package com.github.wxiaoqi.security.auth.util.user;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class JwtAuthenticationRequest implements Serializable {
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 password;
public JwtAuthenticationRequest(String username, String password) {
this.username = username;
this.password = password;
}
public JwtAuthenticationRequest() {
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
private Integer checkpass = 1;
// public JwtAuthenticationRequest(String username, String password) {
// this.username = username;
// this.password = password;
// }
//
// public JwtAuthenticationRequest() {
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
}
......@@ -46,6 +46,8 @@ import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.net.CookieManager;
import java.net.CookieStore;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Date;
......@@ -132,42 +134,44 @@ public class AccessGatewayFilter implements GlobalFilter {
requestType = requestTypes.get(0);
}
if(null != requestType && !RequestTypeConstants.NOT.equals(requestType)) {
}
// 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();
// //设置登录
// CookieStore cookieStore = HttpRequest.getCookieManager().getCookieStore();
// cookieStore.add("");
//
// 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 {
// authToken = getAuthTokenFromRequest(request);
// IJWTInfo ijwtInfo = userAuthUtil.getInfoFromToken(authToken);
// if(null == ijwtInfo.getName() || !jwtClaims.getSubject().equals(ijwtInfo.getName())) {
// throw new Exception();
// signedJWT = SignedJWT.parse(tokenBean.getData());
// JWTClaimsSet jwtClaims =signedJWT.getJWTClaimsSet();
// //设置登录
//
// 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) {
// log.error("未登录,直接登录", e);
// ObjectRestResponse<String> restResponseToken = userService.createAuthenticationToken(jwtClaims.getSubject());
// authToken = restResponseToken.getData();
// } catch (java.text.ParseException e) {
// log.error(e.getMessage(), e);
// }
// } 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);
String requestUri = request.getPath().pathWithinApplication().value();
......
......@@ -60,7 +60,17 @@ public class AppUserRest {
@RequestMapping(value = "/user/validate", method = RequestMethod.POST)
public @ResponseBody
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