ExtendApiQQExmail

This commit is contained in:
MaxKey 2021-08-07 12:19:35 +08:00
parent 8317ad79bc
commit 30546a3d9e
3 changed files with 39 additions and 11 deletions

View File

@ -26,6 +26,7 @@ import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
import org.maxkey.constants.Boolean;
import org.maxkey.entity.Accounts;
import org.maxkey.entity.UserInfo;
import org.maxkey.entity.apps.Apps;
import org.maxkey.util.Instance;
import org.maxkey.web.WebContext;
@ -55,21 +56,46 @@ public class ExtendApiAuthorizeEndpoint extends AuthorizeBaseEndpoint{
ModelAndView modelAndView=new ModelAndView("authorize/redirect_sso_submit");
Apps apps=getApp(id);
_logger.debug(""+apps);
UserInfo userInfo = WebContext.getUserInfo();
if(Boolean.isTrue(apps.getIsAdapter())){
Accounts appUser=getAccounts(apps);
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();
}
} 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);
}
AbstractAuthorizeAdapter adapter =(AbstractAuthorizeAdapter)Instance.newInstance(apps.getAdapter());
apps.setAppUser(appUser);
}
modelAndView=adapter.authorize(
WebContext.getUserInfo(),
apps,
appUser.getRelatedUsername()+"."+appUser.getRelatedPassword(),
username+"="+password,
modelAndView);
return modelAndView;
}else{

View File

@ -58,6 +58,8 @@ public class ExtendApiQQExmailAdapter extends AbstractAuthorizeAdapter {
HttpsTrusts.beforeConnection();
Apps details=(Apps)app;
String username = data.substring(0, data.indexOf("="));
String password = data.substring(data.indexOf("=") + 1);
//extraAttrs from Applications
ExtraAttrs extraAttrs=null;
if(details.getIsExtendAttr()==1){
@ -69,7 +71,7 @@ public class ExtendApiQQExmailAdapter extends AbstractAuthorizeAdapter {
_logger.debug(""+token);
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);
_logger.debug("authKey : "+authKey);

View File

@ -5,13 +5,13 @@
<#include "authorize_common.ftl">
<script type="text/javascript">
function redirectToLogin(){
window.top.location.href ="${redirect_uri}";
window.top.location.href ="${redirect_uri!}";
}
</script>
</head>
<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%">
<tr>
<td colspan="2"><input type="submit" name="submitBtn" value="Continue..." /></td>