mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-07 09:28:49 +08:00
ExtendApiQQExmail
This commit is contained in:
parent
8317ad79bc
commit
30546a3d9e
@ -26,6 +26,7 @@ import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
|
|||||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||||
import org.maxkey.constants.Boolean;
|
import org.maxkey.constants.Boolean;
|
||||||
import org.maxkey.entity.Accounts;
|
import org.maxkey.entity.Accounts;
|
||||||
|
import org.maxkey.entity.UserInfo;
|
||||||
import org.maxkey.entity.apps.Apps;
|
import org.maxkey.entity.apps.Apps;
|
||||||
import org.maxkey.util.Instance;
|
import org.maxkey.util.Instance;
|
||||||
import org.maxkey.web.WebContext;
|
import org.maxkey.web.WebContext;
|
||||||
@ -55,21 +56,46 @@ public class ExtendApiAuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
|||||||
ModelAndView modelAndView=new ModelAndView("authorize/redirect_sso_submit");
|
ModelAndView modelAndView=new ModelAndView("authorize/redirect_sso_submit");
|
||||||
Apps apps=getApp(id);
|
Apps apps=getApp(id);
|
||||||
_logger.debug(""+apps);
|
_logger.debug(""+apps);
|
||||||
|
UserInfo userInfo = WebContext.getUserInfo();
|
||||||
if(Boolean.isTrue(apps.getIsAdapter())){
|
if(Boolean.isTrue(apps.getIsAdapter())){
|
||||||
Accounts appUser=getAccounts(apps);
|
|
||||||
|
|
||||||
if(appUser == null){
|
|
||||||
return generateInitCredentialModelAndView(id,"/authorize/api/"+id);
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractAuthorizeAdapter adapter =(AbstractAuthorizeAdapter)Instance.newInstance(apps.getAdapter());
|
AbstractAuthorizeAdapter adapter =(AbstractAuthorizeAdapter)Instance.newInstance(apps.getAdapter());
|
||||||
|
String username ="";
|
||||||
|
String password ="";
|
||||||
|
if(apps.getCredential()==1) {
|
||||||
|
if(apps.getSystemUserAttr().equalsIgnoreCase("uid")) {
|
||||||
|
username = userInfo.getId();
|
||||||
|
}else if(apps.getSystemUserAttr().equalsIgnoreCase("username")) {
|
||||||
|
username = userInfo.getUsername();
|
||||||
|
}else if(apps.getSystemUserAttr().equalsIgnoreCase("email")) {
|
||||||
|
username = userInfo.getEmail();
|
||||||
|
}else if(apps.getSystemUserAttr().equalsIgnoreCase("employeeNumber")) {
|
||||||
|
username = userInfo.getEmployeeNumber();
|
||||||
|
}else if(apps.getSystemUserAttr().equalsIgnoreCase("windowsaccount")) {
|
||||||
|
username = userInfo.getWindowsAccount();
|
||||||
|
}else if(apps.getSystemUserAttr().equalsIgnoreCase("mobile")) {
|
||||||
|
username = userInfo.getMobile();
|
||||||
|
}else if(apps.getSystemUserAttr().equalsIgnoreCase("workEmail")) {
|
||||||
|
username = userInfo.getWorkEmail();
|
||||||
|
}else {
|
||||||
|
username = userInfo.getEmail();
|
||||||
|
}
|
||||||
|
|
||||||
apps.setAppUser(appUser);
|
} else if(apps.getCredential()==2) {
|
||||||
|
username = apps.getSharedUsername();
|
||||||
|
password = apps.getSharedPassword();
|
||||||
|
}else if(apps.getCredential()==3) {
|
||||||
|
Accounts appUser=getAccounts(apps);
|
||||||
|
if(appUser == null){
|
||||||
|
return generateInitCredentialModelAndView(id,"/authorize/api/"+id);
|
||||||
|
}
|
||||||
|
apps.setAppUser(appUser);
|
||||||
|
}
|
||||||
|
|
||||||
modelAndView=adapter.authorize(
|
modelAndView=adapter.authorize(
|
||||||
WebContext.getUserInfo(),
|
WebContext.getUserInfo(),
|
||||||
apps,
|
apps,
|
||||||
appUser.getRelatedUsername()+"."+appUser.getRelatedPassword(),
|
username+"="+password,
|
||||||
modelAndView);
|
modelAndView);
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@ -58,6 +58,8 @@ public class ExtendApiQQExmailAdapter extends AbstractAuthorizeAdapter {
|
|||||||
HttpsTrusts.beforeConnection();
|
HttpsTrusts.beforeConnection();
|
||||||
|
|
||||||
Apps details=(Apps)app;
|
Apps details=(Apps)app;
|
||||||
|
String username = data.substring(0, data.indexOf("="));
|
||||||
|
String password = data.substring(data.indexOf("=") + 1);
|
||||||
//extraAttrs from Applications
|
//extraAttrs from Applications
|
||||||
ExtraAttrs extraAttrs=null;
|
ExtraAttrs extraAttrs=null;
|
||||||
if(details.getIsExtendAttr()==1){
|
if(details.getIsExtendAttr()==1){
|
||||||
@ -69,7 +71,7 @@ public class ExtendApiQQExmailAdapter extends AbstractAuthorizeAdapter {
|
|||||||
_logger.debug(""+token);
|
_logger.debug(""+token);
|
||||||
|
|
||||||
OAuthClient authkeyRestClient=new OAuthClient(
|
OAuthClient authkeyRestClient=new OAuthClient(
|
||||||
String.format(AUTHKEY_URI,token.getAccess_token(),details.getAppUser().getRelatedUsername()));
|
String.format(AUTHKEY_URI,token.getAccess_token(),username));
|
||||||
|
|
||||||
HashMap<String, String> authKey=JsonUtils.gson2Object(authkeyRestClient.execute().getBody(), HashMap.class);
|
HashMap<String, String> authKey=JsonUtils.gson2Object(authkeyRestClient.execute().getBody(), HashMap.class);
|
||||||
_logger.debug("authKey : "+authKey);
|
_logger.debug("authKey : "+authKey);
|
||||||
|
|||||||
@ -5,13 +5,13 @@
|
|||||||
<#include "authorize_common.ftl">
|
<#include "authorize_common.ftl">
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function redirectToLogin(){
|
function redirectToLogin(){
|
||||||
window.top.location.href ="${redirect_uri}";
|
window.top.location.href ="${redirect_uri!}";
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body onload="redirectToLogin()" style="display:none">
|
<body onload="redirectToLogin()" style="display:none">
|
||||||
<form id="redirect_sso_form" name="redirect_sso_form" action="${redirect_uri}" method="get">
|
<form id="redirect_sso_form" name="redirect_sso_form" action="${redirect_uri!}" method="get">
|
||||||
<table style="width:100%">
|
<table style="width:100%">
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2"><input type="submit" name="submitBtn" value="Continue..." /></td>
|
<td colspan="2"><input type="submit" name="submitBtn" value="Continue..." /></td>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user