1 package com.supwisdom.institute.backend.gateway.authn.service;
5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.stereotype.Service;
8 import com.alibaba.fastjson.JSONObject;
9 import com.supwisdom.institute.backend.gateway.authn.model.Account;
10 import com.supwisdom.institute.backend.gateway.authn.model.Permission;
11 import com.supwisdom.institute.backend.gateway.authn.model.Role;
12 import com.supwisdom.institute.backend.gateway.authn.remote.web.client.AuthnAccountRemoteRestTemplate;
15 public class AuthnAccountService {
18 // private AuthnAccountRemoteFeignClient authnAccountRemote;
21 private AuthnAccountRemoteRestTemplate authnAccountRemote;
23 public Account account(String username) {
25 JSONObject jsonObject = authnAccountRemote.account(username);
26 if (jsonObject == null) {
30 if (jsonObject.getIntValue("code") == 0) {
31 JSONObject data = jsonObject.getJSONObject("data");
33 return data.toJavaObject(Account.class);
39 public List<Role> roles(String username) {
41 JSONObject jsonObject = authnAccountRemote.roles(username);
42 if (jsonObject == null) {
46 if (jsonObject.getIntValue("code") == 0) {
47 JSONObject data = jsonObject.getJSONObject("data");
49 return data.getJSONArray("roles").toJavaList(Role.class);
55 public List<Permission> menus(String username, String applicationId) {
57 JSONObject jsonObject = authnAccountRemote.menus(username, applicationId);
58 if (jsonObject == null) {
62 if (jsonObject.getIntValue("code") == 0) {
63 JSONObject data = jsonObject.getJSONObject("data");
65 return data.getJSONArray("permissions").toJavaList(Permission.class);