Search in sources :

Example 1 with FormBasedDefaultAdapter

use of org.maxkey.authz.formbased.endpoint.adapter.FormBasedDefaultAdapter in project MaxKey by dromara.

the class FormBasedAuthorizeEndpoint method authorize.

@Operation(summary = "FormBased认证地址接口", description = "参数应用ID", method = "GET")
@RequestMapping("/authz/formbased/{id}")
public ModelAndView authorize(HttpServletRequest request, @PathVariable("id") String id) {
    AppsFormBasedDetails formBasedDetails = formBasedDetailsService.getAppDetails(id, true);
    _logger.debug("formBasedDetails {}", formBasedDetails);
    Apps application = getApp(id);
    formBasedDetails.setAdapter(application.getAdapter());
    formBasedDetails.setIsAdapter(application.getIsAdapter());
    ModelAndView modelAndView = null;
    Accounts account = getAccounts(formBasedDetails);
    _logger.debug("Accounts {}", account);
    if (account == null) {
        return generateInitCredentialModelAndView(id, "/authz/formbased/" + id);
    } else {
        modelAndView = new ModelAndView();
        AbstractAuthorizeAdapter adapter;
        if (ConstsBoolean.isTrue(formBasedDetails.getIsAdapter())) {
            Object formBasedAdapter = Instance.newInstance(formBasedDetails.getAdapter());
            adapter = (AbstractAuthorizeAdapter) formBasedAdapter;
        } else {
            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(modelAndView);
    }
    _logger.debug("FormBased View Name {}", modelAndView.getViewName());
    return modelAndView;
}
Also used : AbstractAuthorizeAdapter(org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter) FormBasedDefaultAdapter(org.maxkey.authz.formbased.endpoint.adapter.FormBasedDefaultAdapter) AppsFormBasedDetails(org.maxkey.entity.apps.AppsFormBasedDetails) ModelAndView(org.springframework.web.servlet.ModelAndView) Apps(org.maxkey.entity.apps.Apps) Accounts(org.maxkey.entity.Accounts) Operation(io.swagger.v3.oas.annotations.Operation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)1 AbstractAuthorizeAdapter (org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter)1 FormBasedDefaultAdapter (org.maxkey.authz.formbased.endpoint.adapter.FormBasedDefaultAdapter)1 Accounts (org.maxkey.entity.Accounts)1 Apps (org.maxkey.entity.apps.Apps)1 AppsFormBasedDetails (org.maxkey.entity.apps.AppsFormBasedDetails)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1