AuthorizationUtils

This commit is contained in:
MaxKey
2022-04-12 22:31:41 +08:00
parent 742b660453
commit 50bfb3087e
75 changed files with 766 additions and 1638 deletions

View File

@@ -22,14 +22,15 @@ package org.maxkey.authz.exapi.endpoint;
import javax.servlet.http.HttpServletRequest;
import org.maxkey.authn.SigninPrincipal;
import org.maxkey.authn.annotation.CurrentUser;
import org.maxkey.authn.web.AuthorizationUtils;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
@@ -51,20 +52,23 @@ public class ExtendApiAuthorizeEndpoint extends AuthorizeBaseEndpoint{
@Operation(summary = "ExtendApi认证地址接口", description = "参数应用ID",method="GET")
@RequestMapping("/authz/api/{id}")
public ModelAndView authorize(HttpServletRequest request,@PathVariable("id") String id){
public ModelAndView authorize(
HttpServletRequest request,
@PathVariable("id") String id,
@CurrentUser UserInfo currentUser){
ModelAndView modelAndView=new ModelAndView("authorize/redirect_sso_submit");
Apps apps = getApp(id);
_logger.debug(""+apps);
if(ConstsBoolean.isTrue(apps.getIsAdapter())){
AbstractAuthorizeAdapter adapter = (AbstractAuthorizeAdapter)Instance.newInstance(apps.getAdapter());
Accounts account = getAccounts(apps);
Accounts account = getAccounts(apps,currentUser);
if(apps.getCredential()==Apps.CREDENTIALS.USER_DEFINED && account == null) {
return generateInitCredentialModelAndView(id,"/authorize/api/"+id);
}
adapter.setAuthentication((SigninPrincipal)WebContext.getAuthentication().getPrincipal());
adapter.setUserInfo(WebContext.getUserInfo());
adapter.setAuthentication(AuthorizationUtils.getPrincipal());
adapter.setUserInfo(currentUser);
adapter.setApp(apps);
adapter.setAccount(account);