Optimize
This commit is contained in:
@@ -22,11 +22,11 @@ package org.maxkey.authz.exapi.endpoint;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.maxkey.authn.SigninPrincipal;
|
||||
import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.constants.ConstsBoolean;
|
||||
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;
|
||||
@@ -54,53 +54,23 @@ public class ExtendApiAuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
public ModelAndView authorize(HttpServletRequest request,@PathVariable("id") String id){
|
||||
|
||||
ModelAndView modelAndView=new ModelAndView("authorize/redirect_sso_submit");
|
||||
Apps apps=getApp(id);
|
||||
Apps apps = getApp(id);
|
||||
_logger.debug(""+apps);
|
||||
UserInfo userInfo = WebContext.getUserInfo();
|
||||
if(ConstsBoolean.isTrue(apps.getIsAdapter())){
|
||||
|
||||
AbstractAuthorizeAdapter adapter =(AbstractAuthorizeAdapter)Instance.newInstance(apps.getAdapter());
|
||||
String username ="";
|
||||
String password ="";
|
||||
if(apps.getCredential()==1) {
|
||||
if(apps.getSystemUserAttr().equalsIgnoreCase("userId")) {
|
||||
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);
|
||||
}
|
||||
apps.setAppUser(appUser);
|
||||
AbstractAuthorizeAdapter adapter = (AbstractAuthorizeAdapter)Instance.newInstance(apps.getAdapter());
|
||||
Accounts account = getAccounts(apps);
|
||||
if(apps.getCredential()==Apps.CREDENTIALS.USER_DEFINED && account == null) {
|
||||
return generateInitCredentialModelAndView(id,"/authorize/api/"+id);
|
||||
}
|
||||
|
||||
modelAndView=adapter.authorize(
|
||||
WebContext.getUserInfo(),
|
||||
apps,
|
||||
username+"="+password,
|
||||
modelAndView);
|
||||
return modelAndView;
|
||||
adapter.setAuthentication((SigninPrincipal)WebContext.getAuthentication().getPrincipal());
|
||||
adapter.setUserInfo(WebContext.getUserInfo());
|
||||
adapter.setApp(apps);
|
||||
adapter.setAccount(account);
|
||||
|
||||
return adapter.authorize(modelAndView);
|
||||
}else{
|
||||
modelAndView.addObject("redirect_uri", getApp(id).getLoginUrl());
|
||||
|
||||
modelAndView.addObject("redirect_uri", apps.getLoginUrl());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,13 +19,12 @@ package org.maxkey.authz.exapi.endpoint.adapter;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import org.maxkey.authn.SigninPrincipal;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.client.http.HttpVerb;
|
||||
import org.maxkey.client.oauth.OAuthClient;
|
||||
import org.maxkey.crypto.DigestUtils;
|
||||
import org.maxkey.entity.Accounts;
|
||||
import org.maxkey.entity.ExtraAttrs;
|
||||
import org.maxkey.entity.UserInfo;
|
||||
import org.maxkey.entity.apps.Apps;
|
||||
import org.maxkey.util.HttpsTrusts;
|
||||
import org.maxkey.util.JsonUtils;
|
||||
@@ -45,6 +44,8 @@ public class ExtendApiCndnsApiMailAdapter extends AbstractAuthorizeAdapter {
|
||||
//sign with parameter
|
||||
//sign=md5(action=getUserInfo&appid=***&email=admin@maxkey.org&time=1579736456 + md5(token))
|
||||
|
||||
Accounts account;
|
||||
|
||||
static String SIGN_STRING ="action=getDomainInfo&appid=%s%s";
|
||||
|
||||
static String SIGN_EMAIL_STRING ="action=getUserInfo&appid=%s&email=%s&time=%s%s";
|
||||
@@ -55,18 +56,18 @@ public class ExtendApiCndnsApiMailAdapter extends AbstractAuthorizeAdapter {
|
||||
|
||||
|
||||
@Override
|
||||
public String generateInfo(SigninPrincipal authentication,UserInfo userInfo,Object app) {
|
||||
public Object generateInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encrypt(String data, String algorithmKey, String algorithm) {
|
||||
public Object encrypt(Object data, String algorithmKey, String algorithm) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
|
||||
public ModelAndView authorize(ModelAndView modelAndView) {
|
||||
HttpsTrusts.beforeConnection();
|
||||
|
||||
Apps details=(Apps)app;
|
||||
|
||||
@@ -18,12 +18,11 @@
|
||||
package org.maxkey.authz.exapi.endpoint.adapter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import org.maxkey.authn.SigninPrincipal;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.client.oauth.OAuthClient;
|
||||
import org.maxkey.client.oauth.model.Token;
|
||||
import org.maxkey.entity.Accounts;
|
||||
import org.maxkey.entity.ExtraAttrs;
|
||||
import org.maxkey.entity.UserInfo;
|
||||
import org.maxkey.entity.apps.Apps;
|
||||
import org.maxkey.util.HttpsTrusts;
|
||||
import org.maxkey.util.JsonUtils;
|
||||
@@ -43,25 +42,20 @@ public class ExtendApiQQExmailAdapter extends AbstractAuthorizeAdapter {
|
||||
//https://exmail.qq.com/qy_mng_logic/doc#10036
|
||||
static String AUTHKEY_URI="https://api.exmail.qq.com/cgi-bin/service/get_login_url?access_token=%s&userid=%s";
|
||||
|
||||
Accounts account;
|
||||
|
||||
@Override
|
||||
public String generateInfo(SigninPrincipal authentication,UserInfo userInfo,Object app) {
|
||||
public Object generateInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encrypt(String data, String algorithmKey, String algorithm) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
|
||||
public ModelAndView authorize(ModelAndView modelAndView) {
|
||||
HttpsTrusts.beforeConnection();
|
||||
|
||||
Apps details=(Apps)app;
|
||||
String username = data.substring(0, data.indexOf("="));
|
||||
String password = data.substring(data.indexOf("=") + 1);
|
||||
_logger.trace("username " + username +" password " + password);
|
||||
//extraAttrs from Applications
|
||||
ExtraAttrs extraAttrs=null;
|
||||
if(details.getIsExtendAttr()==1){
|
||||
@@ -74,7 +68,7 @@ public class ExtendApiQQExmailAdapter extends AbstractAuthorizeAdapter {
|
||||
_logger.debug(""+token);
|
||||
|
||||
OAuthClient authkeyRestClient=new OAuthClient(
|
||||
String.format(AUTHKEY_URI,token.getAccess_token(),username));
|
||||
String.format(AUTHKEY_URI,token.getAccess_token(),userInfo.getUsername()));
|
||||
|
||||
HashMap<String, String> authKey=JsonUtils.gson2Object(authkeyRestClient.execute().getBody(), HashMap.class);
|
||||
_logger.debug("authKey : "+authKey);
|
||||
|
||||
@@ -18,11 +18,10 @@
|
||||
package org.maxkey.authz.exapi.endpoint.adapter;
|
||||
|
||||
import java.time.Instant;
|
||||
import org.maxkey.authn.SigninPrincipal;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.crypto.DigestUtils;
|
||||
import org.maxkey.entity.Accounts;
|
||||
import org.maxkey.entity.ExtraAttrs;
|
||||
import org.maxkey.entity.UserInfo;
|
||||
import org.maxkey.entity.apps.Apps;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -43,18 +42,20 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
public class ExtendApiTimestampSignAdapter extends AbstractAuthorizeAdapter {
|
||||
final static Logger _logger = LoggerFactory.getLogger(ExtendApiTimestampSignAdapter.class);
|
||||
|
||||
Accounts account;
|
||||
|
||||
@Override
|
||||
public String generateInfo(SigninPrincipal authentication,UserInfo userInfo,Object app) {
|
||||
public Object generateInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encrypt(String data, String algorithmKey, String algorithm) {
|
||||
public Object encrypt(Object data, String algorithmKey, String algorithm) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
|
||||
public ModelAndView authorize(ModelAndView modelAndView) {
|
||||
Apps details=(Apps)app;
|
||||
|
||||
String code = details.getPrincipal();
|
||||
|
||||
@@ -18,11 +18,10 @@
|
||||
package org.maxkey.authz.exapi.endpoint.adapter;
|
||||
|
||||
import java.time.Instant;
|
||||
import org.maxkey.authn.SigninPrincipal;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.crypto.DigestUtils;
|
||||
import org.maxkey.entity.Accounts;
|
||||
import org.maxkey.entity.ExtraAttrs;
|
||||
import org.maxkey.entity.UserInfo;
|
||||
import org.maxkey.entity.apps.Apps;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -44,18 +43,20 @@ public class ExtendApiZentaoAdapter extends AbstractAuthorizeAdapter {
|
||||
static String login_url_template="api.php?m=user&f=apilogin&account=%s&code=%s&time=%s&token=%s";
|
||||
static String login_url_m_template="account=%s&code=%s&time=%s&token=%s";
|
||||
|
||||
Accounts account;
|
||||
|
||||
@Override
|
||||
public String generateInfo(SigninPrincipal authentication,UserInfo userInfo,Object app) {
|
||||
public Object generateInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encrypt(String data, String algorithmKey, String algorithm) {
|
||||
public Object encrypt(Object data, String algorithmKey, String algorithm) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
|
||||
public ModelAndView authorize(ModelAndView modelAndView) {
|
||||
Apps details=(Apps)app;
|
||||
//extraAttrs from Applications
|
||||
ExtraAttrs extraAttrs=null;
|
||||
|
||||
Reference in New Issue
Block a user