beeb74adebf7205b20420587f6bb5d9830f7694f
[institute/sw-backend.git] /
1 package com.supwisdom.institute.backend.gateway.authn.service;
2
3 import java.util.List;
4
5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.stereotype.Service;
7
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;
13
14 @Service
15 public class AuthnAccountService {
16   
17 //  @Autowired
18 //  private AuthnAccountRemoteFeignClient authnAccountRemote;
19   
20   @Autowired
21   private AuthnAccountRemoteRestTemplate authnAccountRemote;
22   
23   public Account account(String username) {
24     
25     JSONObject jsonObject = authnAccountRemote.account(username);
26     if (jsonObject == null) {
27       return null;
28     }
29     
30     if (jsonObject.getIntValue("code") == 0) {
31       JSONObject data = jsonObject.getJSONObject("data");
32       
33       return data.toJavaObject(Account.class);
34     }
35     
36     return null;
37   }
38
39   public List<Role> roles(String username) {
40     
41     JSONObject jsonObject = authnAccountRemote.roles(username);
42     if (jsonObject == null) {
43       return null;
44     }
45     
46     if (jsonObject.getIntValue("code") == 0) {
47       JSONObject data = jsonObject.getJSONObject("data");
48       
49       return data.getJSONArray("roles").toJavaList(Role.class);
50     }
51     
52     return null;
53   }
54
55   public List<Permission> menus(String username, String applicationId) {
56     
57     JSONObject jsonObject = authnAccountRemote.menus(username, applicationId);
58     if (jsonObject == null) {
59       return null;
60     }
61     
62     if (jsonObject.getIntValue("code") == 0) {
63       JSONObject data = jsonObject.getJSONObject("data");
64       
65       return data.getJSONArray("permissions").toJavaList(Permission.class);
66     }
67     
68     return null;
69   }
70
71 }