Search in sources :

Example 1 with Accounts

use of org.maxkey.entity.Accounts in project MaxKey by dromara.

the class AppListController method appUserConfig.

@ResponseBody
@RequestMapping(value = { "/appUserConfig" })
public Message appUserConfig(@RequestParam("protocol") String protocol, @RequestParam("credential") int credential, @RequestParam("appId") String appId, @RequestParam("identity_username") String identity_username, @RequestParam("identity_password") String identity_password) {
    Apps app = appsService.get(appId);
    UserInfo userInfo = WebContext.getUserInfo();
    Accounts appUsers = new Accounts();
    appUsers.setAppId(appId);
    appUsers.setUserId(userInfo.getId());
    if (identity_password != null && !identity_password.equals("") && credential == Apps.CREDENTIALS.USER_DEFINED) {
        appUsers = appUsersService.load(new Accounts(userInfo.getId(), appId));
        if (appUsers == null) {
            appUsers = new Accounts();
            appUsers.setId(appUsers.generateId());
            appUsers.setAppId(appId);
            appUsers.setAppName(app.getName());
            appUsers.setUserId(userInfo.getId());
            appUsers.setUsername(userInfo.getUsername());
            appUsers.setDisplayName(userInfo.getDisplayName());
            appUsers.setRelatedUsername(identity_username);
            appUsers.setRelatedPassword(PasswordReciprocal.getInstance().encode(identity_password));
            appUsers.setInstId(userInfo.getInstId());
            appUsers.setStatus(ConstsStatus.ACTIVE);
            appUsersService.insert(appUsers);
        } else {
            appUsers.setRelatedUsername(identity_username);
            appUsers.setRelatedPassword(PasswordReciprocal.getInstance().encode(identity_password));
            appUsersService.update(appUsers);
        }
    }
    return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_SUCCESS), MessageType.success);
}
Also used : ConstsOperateMessage(org.maxkey.constants.ConstsOperateMessage) Message(org.maxkey.web.message.Message) UserInfo(org.maxkey.entity.UserInfo) UserApps(org.maxkey.entity.apps.UserApps) Apps(org.maxkey.entity.apps.Apps) Accounts(org.maxkey.entity.Accounts) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Accounts

use of org.maxkey.entity.Accounts 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)

Example 3 with Accounts

use of org.maxkey.entity.Accounts in project MaxKey by dromara.

the class ExtendApiAuthorizeEndpoint method authorize.

@Operation(summary = "ExtendApi认证地址接口", description = "参数应用ID", method = "GET")
@RequestMapping("/authz/api/{id}")
public ModelAndView authorize(HttpServletRequest request, @PathVariable("id") String id) {
    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);
        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.setApp(apps);
        adapter.setAccount(account);
        return adapter.authorize(modelAndView);
    } else {
        modelAndView.addObject("redirect_uri", apps.getLoginUrl());
        return modelAndView;
    }
}
Also used : AbstractAuthorizeAdapter(org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter) 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)

Example 4 with Accounts

use of org.maxkey.entity.Accounts in project MaxKey by dromara.

the class AccountsServiceTest method get.

@Test
public void get() throws Exception {
    _logger.info("get...");
    Accounts accounts = service.get("26b1c864-ae81-4b1f-9355-74c4c699cb6b");
    _logger.info("accounts " + accounts);
}
Also used : Accounts(org.maxkey.entity.Accounts) Test(org.junit.Test)

Example 5 with Accounts

use of org.maxkey.entity.Accounts in project MaxKey by dromara.

the class AccountsServiceTest method load.

@Test
public void load() throws Exception {
    _logger.info("get...");
    Accounts queryAccounts = new Accounts("7BF5315CA1004CDB8E614B0361C4D46B", "fe86db85-5475-4494-b5aa-dbd3b886ff64");
    Accounts accounts = service.load(queryAccounts);
    _logger.info("accounts " + accounts);
}
Also used : Accounts(org.maxkey.entity.Accounts) Test(org.junit.Test)

Aggregations

Accounts (org.maxkey.entity.Accounts)12 UserInfo (org.maxkey.entity.UserInfo)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Apps (org.maxkey.entity.apps.Apps)4 ModelAndView (org.springframework.web.servlet.ModelAndView)4 Operation (io.swagger.v3.oas.annotations.Operation)2 Test (org.junit.Test)2 AbstractAuthorizeAdapter (org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter)2 FormBasedDefaultAdapter (org.maxkey.authz.formbased.endpoint.adapter.FormBasedDefaultAdapter)1 ConstsOperateMessage (org.maxkey.constants.ConstsOperateMessage)1 AppsFormBasedDetails (org.maxkey.entity.apps.AppsFormBasedDetails)1 UserApps (org.maxkey.entity.apps.UserApps)1 Message (org.maxkey.web.message.Message)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1