Optimize
This commit is contained in:
@@ -22,6 +22,7 @@ package org.maxkey.authz.formbased.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.authz.formbased.endpoint.adapter.FormBasedDefaultAdapter;
|
||||
@@ -62,40 +63,40 @@ public class FormBasedAuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
public ModelAndView authorize(
|
||||
HttpServletRequest request,
|
||||
@PathVariable("id") String id){
|
||||
AppsFormBasedDetails formBasedDetails=formBasedDetailsService.getAppDetails(id);
|
||||
_logger.debug(""+formBasedDetails);
|
||||
Apps application= getApp(id);
|
||||
|
||||
AppsFormBasedDetails formBasedDetails = formBasedDetailsService.getAppDetails(id);
|
||||
_logger.debug("formBasedDetails {}",formBasedDetails);
|
||||
Apps application = getApp(id);
|
||||
formBasedDetails.setAdapter(application.getAdapter());
|
||||
formBasedDetails.setIsAdapter(application.getIsAdapter());
|
||||
ModelAndView modelAndView=null;
|
||||
|
||||
Accounts appUser=getAccounts(formBasedDetails);
|
||||
Accounts account = getAccounts(formBasedDetails);
|
||||
_logger.debug("Accounts {}",account);
|
||||
|
||||
_logger.debug("Accounts "+appUser);
|
||||
if(appUser == null){
|
||||
if(account == null){
|
||||
return generateInitCredentialModelAndView(id,"/authz/formbased/"+id);
|
||||
|
||||
}else{
|
||||
formBasedDetails.setAppUser(appUser);
|
||||
|
||||
modelAndView=new ModelAndView();
|
||||
|
||||
AbstractAuthorizeAdapter adapter;
|
||||
|
||||
if(ConstsBoolean.isTrue(formBasedDetails.getIsAdapter())){
|
||||
adapter =(AbstractAuthorizeAdapter)Instance.newInstance(formBasedDetails.getAdapter());
|
||||
Object formBasedAdapter = Instance.newInstance(formBasedDetails.getAdapter());
|
||||
adapter =(AbstractAuthorizeAdapter)formBasedAdapter;
|
||||
}else{
|
||||
adapter =(AbstractAuthorizeAdapter)defaultFormBasedAdapter;
|
||||
FormBasedDefaultAdapter formBasedDefaultAdapter =new FormBasedDefaultAdapter();
|
||||
adapter =(AbstractAuthorizeAdapter)formBasedDefaultAdapter;
|
||||
}
|
||||
adapter.setAuthentication((SigninPrincipal)WebContext.getAuthentication().getPrincipal());
|
||||
adapter.setUserInfo(WebContext.getUserInfo());
|
||||
adapter.setApp(formBasedDetails);
|
||||
adapter.setAccount(account);
|
||||
|
||||
modelAndView=adapter.authorize(
|
||||
WebContext.getUserInfo(),
|
||||
formBasedDetails,
|
||||
appUser.getRelatedUsername()+"."+appUser.getRelatedPassword(),
|
||||
modelAndView);
|
||||
modelAndView = adapter.authorize(modelAndView);
|
||||
}
|
||||
|
||||
_logger.debug("FormBased View Name " + modelAndView.getViewName());
|
||||
_logger.debug("FormBased View Name {}" , modelAndView.getViewName());
|
||||
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
@@ -19,37 +19,30 @@ package org.maxkey.authz.formbased.endpoint.adapter;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import org.maxkey.authn.SigninPrincipal;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.constants.ConstsBoolean;
|
||||
import org.maxkey.crypto.DigestUtils;
|
||||
import org.maxkey.entity.UserInfo;
|
||||
import org.maxkey.entity.apps.AppsFormBasedDetails;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
public class FormBasedDefaultAdapter 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) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
|
||||
public ModelAndView authorize(ModelAndView modelAndView) {
|
||||
modelAndView.setViewName("authorize/formbased_sso_submint");
|
||||
AppsFormBasedDetails details=(AppsFormBasedDetails)app;
|
||||
|
||||
String password = details.getAppUser().getRelatedPassword();
|
||||
String password = account.getRelatedPassword();
|
||||
if(null==details.getPasswordAlgorithm()||details.getPasswordAlgorithm().equals("")){
|
||||
}else if(details.getPasswordAlgorithm().indexOf("HEX")>-1){
|
||||
password = DigestUtils.digestHex(details.getAppUser().getRelatedPassword(),details.getPasswordAlgorithm().substring(0, details.getPasswordAlgorithm().indexOf("HEX")));
|
||||
password = DigestUtils.digestHex(account.getRelatedPassword(),details.getPasswordAlgorithm().substring(0, details.getPasswordAlgorithm().indexOf("HEX")));
|
||||
}else{
|
||||
password = DigestUtils.digestBase64(details.getAppUser().getRelatedPassword(),details.getPasswordAlgorithm());
|
||||
password = DigestUtils.digestBase64(account.getRelatedPassword(),details.getPasswordAlgorithm());
|
||||
}
|
||||
|
||||
modelAndView.addObject("id", details.getId());
|
||||
@@ -58,9 +51,9 @@ public class FormBasedDefaultAdapter extends AbstractAuthorizeAdapter {
|
||||
modelAndView.addObject("loginUrl", details.getLoginUrl());
|
||||
modelAndView.addObject("usernameMapping", details.getUsernameMapping());
|
||||
modelAndView.addObject("passwordMapping", details.getPasswordMapping());
|
||||
modelAndView.addObject("username", details.getAppUser().getRelatedUsername());
|
||||
modelAndView.addObject("username", account.getRelatedUsername());
|
||||
modelAndView.addObject("password", password);
|
||||
modelAndView.addObject("timestamp", ""+Instant.now().getEpochSecond());
|
||||
modelAndView.addObject("timestamp", "" + Instant.now().getEpochSecond());
|
||||
|
||||
if(ConstsBoolean.isTrue(details.getIsExtendAttr())){
|
||||
modelAndView.addObject("extendAttr", details.getExtendAttr());
|
||||
|
||||
@@ -17,32 +17,25 @@
|
||||
|
||||
package org.maxkey.authz.formbased.endpoint.adapter;
|
||||
|
||||
import org.maxkey.authn.SigninPrincipal;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.constants.ConstsBoolean;
|
||||
import org.maxkey.entity.UserInfo;
|
||||
import org.maxkey.entity.apps.AppsFormBasedDetails;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
public class FormBasedNetease163EmailAdapter extends AbstractAuthorizeAdapter {
|
||||
|
||||
|
||||
@Override
|
||||
public String generateInfo(SigninPrincipal authentication,UserInfo userInfo,Object app) {
|
||||
public String generateInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encrypt(String data, String algorithmKey, String algorithm) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
|
||||
public ModelAndView authorize(ModelAndView modelAndView) {
|
||||
modelAndView.setViewName("authorize/formbased_163email_sso_submint");
|
||||
AppsFormBasedDetails details=(AppsFormBasedDetails)app;
|
||||
modelAndView.addObject("username", details.getAppUser().getRelatedUsername().substring(details.getAppUser().getRelatedUsername().indexOf("@")));
|
||||
modelAndView.addObject("email", details.getAppUser().getRelatedUsername());
|
||||
modelAndView.addObject("password", details.getAppUser().getRelatedPassword());
|
||||
modelAndView.addObject("username", account.getRelatedUsername().substring(account.getRelatedUsername().indexOf("@")));
|
||||
modelAndView.addObject("email", account.getRelatedUsername());
|
||||
modelAndView.addObject("password", account.getRelatedPassword());
|
||||
|
||||
if(ConstsBoolean.isTrue(details.getIsExtendAttr())){
|
||||
modelAndView.addObject("extendAttr", details.getExtendAttr());
|
||||
|
||||
@@ -19,45 +19,26 @@ package org.maxkey.authz.formbased.endpoint.adapter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.maxkey.authn.SigninPrincipal;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.crypto.DigestUtils;
|
||||
import org.maxkey.entity.UserInfo;
|
||||
import org.maxkey.entity.apps.AppsFormBasedDetails;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
public class FormBasedNeteaseNoteYoudaoAdapter 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) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
|
||||
public ModelAndView authorize(ModelAndView modelAndView) {
|
||||
modelAndView.setViewName("authorize/formbased_wy_youdao_sso_submint");
|
||||
AppsFormBasedDetails details=(AppsFormBasedDetails)app;
|
||||
modelAndView.addObject("username", details.getAppUser().getRelatedUsername());
|
||||
modelAndView.addObject("password", DigestUtils.md5Hex(details.getAppUser().getRelatedPassword()));
|
||||
modelAndView.addObject("username", account.getRelatedUsername());
|
||||
modelAndView.addObject("password", DigestUtils.md5Hex(account.getRelatedPassword()));
|
||||
modelAndView.addObject("currentTime", (new Date()).getTime());
|
||||
|
||||
/*
|
||||
if(BOOLEAN.isTrue(details.getIsExtendAttr())){
|
||||
modelAndView.addObject("extendAttr", details.getExtendAttr());
|
||||
modelAndView.addObject("isExtendAttr", true);
|
||||
}else{
|
||||
modelAndView.addObject("isExtendAttr", false);
|
||||
}
|
||||
|
||||
modelAndView.addObject("action", details.getRedirectUri());
|
||||
modelAndView.addObject("usernameMapping", details.getUsernameMapping());
|
||||
modelAndView.addObject("passwordMapping", details.getPasswordMapping());
|
||||
*/
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,9 @@ package org.maxkey.authz.formbased.endpoint.adapter;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import org.maxkey.authn.SigninPrincipal;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.constants.ConstsBoolean;
|
||||
import org.maxkey.crypto.DigestUtils;
|
||||
import org.maxkey.entity.UserInfo;
|
||||
import org.maxkey.entity.apps.AppsFormBasedDetails;
|
||||
import org.maxkey.web.WebContext;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
@@ -31,26 +29,21 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
public class FormBasedRedirectAdapter 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) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelAndView authorize(UserInfo userInfo, Object app, String data,ModelAndView modelAndView) {
|
||||
public ModelAndView authorize(ModelAndView modelAndView) {
|
||||
modelAndView.setViewName("authorize/formbased_redirect_submint");
|
||||
AppsFormBasedDetails details=(AppsFormBasedDetails)app;
|
||||
|
||||
String password = details.getAppUser().getRelatedPassword();
|
||||
String password = account.getRelatedPassword();
|
||||
if(null==details.getPasswordAlgorithm()||details.getPasswordAlgorithm().equals("")){
|
||||
}else if(details.getPasswordAlgorithm().indexOf("HEX")>-1){
|
||||
password = DigestUtils.digestHex(details.getAppUser().getRelatedPassword(),details.getPasswordAlgorithm().substring(0, details.getPasswordAlgorithm().indexOf("HEX")));
|
||||
password = DigestUtils.digestHex(account.getRelatedPassword(),details.getPasswordAlgorithm().substring(0, details.getPasswordAlgorithm().indexOf("HEX")));
|
||||
}else{
|
||||
password = DigestUtils.digestBase64(details.getAppUser().getRelatedPassword(),details.getPasswordAlgorithm());
|
||||
password = DigestUtils.digestBase64(account.getRelatedPassword(),details.getPasswordAlgorithm());
|
||||
}
|
||||
|
||||
modelAndView.addObject("id", details.getId());
|
||||
@@ -59,7 +52,7 @@ public class FormBasedRedirectAdapter extends AbstractAuthorizeAdapter {
|
||||
modelAndView.addObject("loginUrl", details.getLoginUrl());
|
||||
modelAndView.addObject("usernameMapping", details.getUsernameMapping());
|
||||
modelAndView.addObject("passwordMapping", details.getPasswordMapping());
|
||||
modelAndView.addObject("username", details.getAppUser().getRelatedUsername());
|
||||
modelAndView.addObject("username", account.getRelatedUsername());
|
||||
modelAndView.addObject("password", password);
|
||||
modelAndView.addObject("timestamp", ""+Instant.now().getEpochSecond());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user