Showing
16 changed files
with
634 additions
and
31 deletions
@@ -12,9 +12,7 @@ import org.springframework.scheduling.annotation.Async; | @@ -12,9 +12,7 @@ import org.springframework.scheduling.annotation.Async; | ||
12 | import org.springframework.scheduling.annotation.EnableAsync; | 12 | import org.springframework.scheduling.annotation.EnableAsync; |
13 | import org.springframework.stereotype.Component; | 13 | import org.springframework.stereotype.Component; |
14 | 14 | ||
15 | -import java.util.HashMap; | ||
16 | -import java.util.List; | ||
17 | -import java.util.Map; | 15 | +import java.util.*; |
18 | import java.util.concurrent.ConcurrentHashMap; | 16 | import java.util.concurrent.ConcurrentHashMap; |
19 | 17 | ||
20 | /** | 18 | /** |
@@ -29,6 +27,9 @@ public class UserAuthLocal { | @@ -29,6 +27,9 @@ public class UserAuthLocal { | ||
29 | 27 | ||
30 | private static ConcurrentHashMap<String, AuthModule> modulemap = new ConcurrentHashMap<>(); | 28 | private static ConcurrentHashMap<String, AuthModule> modulemap = new ConcurrentHashMap<>(); |
31 | 29 | ||
30 | + private static ConcurrentHashMap<String, Set<String>> moduleGroupmap = new ConcurrentHashMap<>(); | ||
31 | + | ||
32 | + | ||
32 | @Autowired | 33 | @Autowired |
33 | HttpRestClient httpRestClient; | 34 | HttpRestClient httpRestClient; |
34 | 35 | ||
@@ -44,57 +45,73 @@ public class UserAuthLocal { | @@ -44,57 +45,73 @@ public class UserAuthLocal { | ||
44 | } | 45 | } |
45 | 46 | ||
46 | //加载mudule信息 | 47 | //加载mudule信息 |
47 | - BaseResponse<List<AuthModule>> moduleResponse = httpRestClient.exchangeForget(HttpUriContants.GET_All_MODULE, new ParameterizedTypeReference<BaseResponse<List<AuthModule>>>() {}, null); | 48 | + BaseResponse<List<AuthModule>> moduleResponse = httpRestClient.exchangeForget(HttpUriContants.GET_All_MODULE, new ParameterizedTypeReference<BaseResponse<List<AuthModule>>>() { |
49 | + }, null); | ||
48 | List<AuthModule> modulelist = moduleResponse.getData(); | 50 | List<AuthModule> modulelist = moduleResponse.getData(); |
49 | for (AuthModule module : modulelist) { | 51 | for (AuthModule module : modulelist) { |
50 | modulemap.put(module.getModuleName(), module); | 52 | modulemap.put(module.getModuleName(), module); |
51 | } | 53 | } |
52 | 54 | ||
55 | + //加载module组信息 | ||
56 | + for (Map.Entry<String,AuthModule> entry : modulemap.entrySet()){ | ||
57 | + AuthModule authModule = entry.getValue(); | ||
58 | + String group = authModule.getModuleGroup(); | ||
59 | + if (StringUtils.isNotBlank(group)){ | ||
60 | + if (moduleGroupmap.containsKey(group)){ | ||
61 | + moduleGroupmap.get(group).add(entry.getKey()); | ||
62 | + }else { | ||
63 | + Set<String> groupSet = new HashSet<>(); | ||
64 | + groupSet.add(entry.getKey()); | ||
65 | + moduleGroupmap.put(group,groupSet); | ||
66 | + } | ||
67 | + } | ||
68 | + } | ||
53 | } | 69 | } |
54 | 70 | ||
55 | /** | 71 | /** |
56 | * jian quan | 72 | * jian quan |
73 | + * | ||
57 | * @param user | 74 | * @param user |
58 | * @param module | 75 | * @param module |
59 | * @return | 76 | * @return |
60 | */ | 77 | */ |
61 | - public boolean auth(String user,String module){ | ||
62 | - if(usermap.isEmpty()){//改用延时加载 | 78 | + public boolean auth(String user, String module) { |
79 | + if (usermap.isEmpty()) {//改用延时加载 | ||
63 | init(); | 80 | init(); |
64 | } | 81 | } |
65 | User u = usermap.get(user); | 82 | User u = usermap.get(user); |
66 | - if (u == null){ | 83 | + if (u == null) { |
67 | return false; | 84 | return false; |
68 | } | 85 | } |
69 | AuthModule authModule = modulemap.get(module); | 86 | AuthModule authModule = modulemap.get(module); |
70 | - if (authModule == null){ | 87 | + if (authModule == null) { |
71 | return false; | 88 | return false; |
72 | } | 89 | } |
73 | //最高权限 | 90 | //最高权限 |
74 | - if (StringUtils.isNotBlank(u.getModuleGroups())){ | 91 | + if (StringUtils.isNotBlank(u.getModuleGroups())) { |
75 | String[] moduleGroupArray = u.getModuleGroups().split(","); | 92 | String[] moduleGroupArray = u.getModuleGroups().split(","); |
76 | - for (String groupName:moduleGroupArray){ | ||
77 | - if ("all".equals(groupName)){ | ||
78 | - return true; | ||
79 | - } | 93 | + for (String groupName : moduleGroupArray) { |
94 | + if ("all".equals(groupName)) { | ||
95 | + return true; | ||
96 | + } | ||
80 | } | 97 | } |
81 | } | 98 | } |
82 | //先查找group | 99 | //先查找group |
83 | String moduleGroup = authModule.getModuleGroup(); | 100 | String moduleGroup = authModule.getModuleGroup(); |
84 | - if (moduleGroup != null && StringUtils.isNotBlank(u.getModuleGroups())){ | 101 | + if (moduleGroup != null && StringUtils.isNotBlank(u.getModuleGroups())) { |
85 | String[] moduleGroupArray = u.getModuleGroups().split(","); | 102 | String[] moduleGroupArray = u.getModuleGroups().split(","); |
86 | - for (String groupName:moduleGroupArray){ | ||
87 | - if (moduleGroup.equals(groupName)){ | 103 | + for (String groupName : moduleGroupArray) { |
104 | + if (moduleGroup.equals(groupName)) { | ||
88 | return true; | 105 | return true; |
89 | } | 106 | } |
90 | } | 107 | } |
91 | } | 108 | } |
92 | 109 | ||
93 | //在查找单一类 | 110 | //在查找单一类 |
94 | - if (StringUtils.isNotBlank(u.getModules())){ | 111 | + if (StringUtils.isNotBlank(u.getModules())) { |
95 | String[] modulesArray = u.getModules().split(","); | 112 | String[] modulesArray = u.getModules().split(","); |
96 | - for (String moduleName:modulesArray){ | ||
97 | - if (module.equals(moduleName)){ | 113 | + for (String moduleName : modulesArray) { |
114 | + if (module.equals(moduleName)) { | ||
98 | return true; | 115 | return true; |
99 | } | 116 | } |
100 | } | 117 | } |
@@ -110,23 +127,50 @@ public class UserAuthLocal { | @@ -110,23 +127,50 @@ public class UserAuthLocal { | ||
110 | * @return | 127 | * @return |
111 | */ | 128 | */ |
112 | public User getUserByname(String name) { | 129 | public User getUserByname(String name) { |
113 | - if(usermap.isEmpty()){//改用延时加载 | 130 | + if (usermap.isEmpty()) {//改用延时加载 |
114 | init(); | 131 | init(); |
115 | } | 132 | } |
116 | return usermap.get(name); | 133 | return usermap.get(name); |
117 | } | 134 | } |
118 | 135 | ||
136 | + public AuthModule getAuthModuleByname(String name) { | ||
137 | + if (modulemap.isEmpty()) {//改用延时加载 | ||
138 | + init(); | ||
139 | + } | ||
140 | + return modulemap.get(name); | ||
141 | + } | ||
142 | + | ||
119 | /** | 143 | /** |
120 | - * 获取用户 | 144 | + * 获取用户所有的权限 |
121 | * | 145 | * |
122 | * @param name | 146 | * @param name |
123 | * @return | 147 | * @return |
124 | */ | 148 | */ |
125 | - public AuthModule getAuthModuleByname(String name) { | ||
126 | - if(modulemap.isEmpty()){//改用延时加载 | 149 | + public Set<String> getAllModuleByname(String name) { |
150 | + | ||
151 | + Set<String> set = new HashSet<>(); | ||
152 | + if (usermap.isEmpty()) {//改用延时加载 | ||
127 | init(); | 153 | init(); |
128 | } | 154 | } |
129 | - return modulemap.get(name); | 155 | + User u = usermap.get(name); |
156 | + String groups = u.getModuleGroups(); | ||
157 | + if (StringUtils.isNotBlank(groups)){//添加组 | ||
158 | + for (String group : groups.split(",")) { | ||
159 | + if ("all".equals(group)){ | ||
160 | + set.addAll(modulemap.keySet()); | ||
161 | + return set; | ||
162 | + } | ||
163 | + set.addAll(moduleGroupmap.get(group)); | ||
164 | + } | ||
165 | + } | ||
166 | + //添加但模块 | ||
167 | + String modules = u.getModules(); | ||
168 | + if (StringUtils.isNotBlank(modules)){//添加组 | ||
169 | + for (String module : modules.split(",")) { | ||
170 | + set.add(module); | ||
171 | + } | ||
172 | + } | ||
173 | + return set; | ||
130 | } | 174 | } |
131 | 175 | ||
132 | /** | 176 | /** |
@@ -141,9 +185,9 @@ public class UserAuthLocal { | @@ -141,9 +185,9 @@ public class UserAuthLocal { | ||
141 | BaseResponse<User> response = httpRestClient.exchangeForget(HttpUriContants.GET_USER_BY_NAME, new ParameterizedTypeReference<BaseResponse<User>>() { | 185 | BaseResponse<User> response = httpRestClient.exchangeForget(HttpUriContants.GET_USER_BY_NAME, new ParameterizedTypeReference<BaseResponse<User>>() { |
142 | }, map); | 186 | }, map); |
143 | User user = response.getData(); | 187 | User user = response.getData(); |
144 | - if (user == null){ | 188 | + if (user == null) { |
145 | usermap.remove(name); | 189 | usermap.remove(name); |
146 | - }else{ | 190 | + } else { |
147 | usermap.put(name, user); | 191 | usermap.put(name, user); |
148 | } | 192 | } |
149 | } | 193 | } |
@@ -157,13 +201,26 @@ public class UserAuthLocal { | @@ -157,13 +201,26 @@ public class UserAuthLocal { | ||
157 | public void flushModule(String name) { | 201 | public void flushModule(String name) { |
158 | Map<String, String> map = new HashMap<>(); | 202 | Map<String, String> map = new HashMap<>(); |
159 | map.put("name", name); | 203 | map.put("name", name); |
204 | + AuthModule oldAuthModule = modulemap.get(name); | ||
160 | BaseResponse<AuthModule> response = httpRestClient.exchangeForget(HttpUriContants.MODULE_GET_BYNAME, new ParameterizedTypeReference<BaseResponse<AuthModule>>() { | 205 | BaseResponse<AuthModule> response = httpRestClient.exchangeForget(HttpUriContants.MODULE_GET_BYNAME, new ParameterizedTypeReference<BaseResponse<AuthModule>>() { |
161 | }, map); | 206 | }, map); |
162 | AuthModule authModule = response.getData(); | 207 | AuthModule authModule = response.getData(); |
163 | - if (authModule == null){ | 208 | + if (authModule == null) { |
164 | modulemap.remove(name); | 209 | modulemap.remove(name); |
165 | - }else{ | 210 | + //删除组里的模块 |
211 | + String group = oldAuthModule.getModuleGroup(); | ||
212 | + if (moduleGroupmap.containsKey(group)) { | ||
213 | + moduleGroupmap.get(group).remove(name); | ||
214 | + } | ||
215 | + } else { | ||
166 | modulemap.put(name, authModule); | 216 | modulemap.put(name, authModule); |
217 | + if (moduleGroupmap.containsKey(authModule.getModuleGroup())){ | ||
218 | + moduleGroupmap.get(authModule.getModuleGroup()).add(name); | ||
219 | + }else { | ||
220 | + Set<String> groupSet = new HashSet<>(); | ||
221 | + groupSet.add(name); | ||
222 | + moduleGroupmap.put(authModule.getModuleGroup(),groupSet); | ||
223 | + } | ||
167 | } | 224 | } |
168 | } | 225 | } |
169 | 226 |
1 | +package com.ui.app.common; | ||
2 | + | ||
3 | +import java.util.HashSet; | ||
4 | +import java.util.List; | ||
5 | +import java.util.Set; | ||
6 | + | ||
7 | +/** | ||
8 | + * Created by zhengyouwei on 2016/11/15. | ||
9 | + */ | ||
10 | +public class AppModule { | ||
11 | + | ||
12 | + private static final Set<String> appModuleSet = new HashSet<>(); | ||
13 | + | ||
14 | + static { | ||
15 | + appModuleSet.add("javaRestart"); | ||
16 | + } | ||
17 | + | ||
18 | + public static String getAuthAppModule(Set<String> modules) { | ||
19 | + StringBuilder stringBuilder = new StringBuilder(); | ||
20 | + for (String module : modules) { | ||
21 | + if (appModuleSet.contains(module)) { | ||
22 | + stringBuilder.append(module).append("|"); | ||
23 | + } | ||
24 | + } | ||
25 | + String result = stringBuilder.toString(); | ||
26 | + if (result.endsWith("|")){ | ||
27 | + return result.substring(0,result.length() - 1).toLowerCase(); | ||
28 | + }else { | ||
29 | + return ""; | ||
30 | + } | ||
31 | + } | ||
32 | + | ||
33 | +} |
1 | +package com.ui.app.common; | ||
2 | + | ||
3 | +/** | ||
4 | + * Created by zhengyouwei on 2016/11/15. | ||
5 | + */ | ||
6 | +public interface ErrorCode { | ||
7 | + | ||
8 | + public static final int SYSTEM_ERROR = -200; | ||
9 | + | ||
10 | + public static final String SYSTEM_ERROR_MESSAGE = "system error"; | ||
11 | + | ||
12 | + public static final int LOGIN_ERROR = -300; | ||
13 | + | ||
14 | + public static final String LOGIN_ERROR_MESSAGE = "login failed"; | ||
15 | + | ||
16 | + public static final int TOKEN_ERROR = -301; | ||
17 | + | ||
18 | + public static final String TOKEN_ERROR_MESSAGE = "token invalid"; | ||
19 | + | ||
20 | + public static final int AUTH_ERROR = -302; | ||
21 | + | ||
22 | + public static final String AUTH_ERROR_MESSAGE = "auth failed"; | ||
23 | + | ||
24 | + public static final int PARAM_ERROR = -303; | ||
25 | + | ||
26 | + public static final String PARAM_ERROR_MESSAGE = "param failed"; | ||
27 | + | ||
28 | +} |
1 | +package com.ui.app.resp; | ||
2 | + | ||
3 | +import lombok.Data; | ||
4 | + | ||
5 | +/** | ||
6 | + * Created by zhengyouwei on 2016/11/15. | ||
7 | + */ | ||
8 | +@Data | ||
9 | +public class AccountInfo { | ||
10 | + private String token; | ||
11 | + private String accountname; | ||
12 | + //(a|b|c 全小写) | ||
13 | + private String privacy; | ||
14 | + private String email; | ||
15 | + private String cName; | ||
16 | + private String mobile; | ||
17 | + private String role; | ||
18 | + | ||
19 | +} |
@@ -81,6 +81,11 @@ public class HttpUriContants { | @@ -81,6 +81,11 @@ public class HttpUriContants { | ||
81 | public static final String USER_DELETE_NAME = "/user/deleteByName"; | 81 | public static final String USER_DELETE_NAME = "/user/deleteByName"; |
82 | public static final String USER_OPERATE = "/user/operate"; | 82 | public static final String USER_OPERATE = "/user/operate"; |
83 | 83 | ||
84 | + public static final String APP_ADD_SEESION = "/user/appAddSession"; | ||
85 | + public static final String APP_GET_SEESION = "/user/appGetSession"; | ||
86 | + public static final String APP_REMOVE_SEESION = "/user/appRemoveSession"; | ||
87 | + | ||
88 | + | ||
84 | 89 | ||
85 | /** | 90 | /** |
86 | * module | 91 | * module |
@@ -173,6 +178,10 @@ public class HttpUriContants { | @@ -173,6 +178,10 @@ public class HttpUriContants { | ||
173 | public static final String JAVA_RESTART_STATAUS = "/javaRestart/getProjectStatus"; | 178 | public static final String JAVA_RESTART_STATAUS = "/javaRestart/getProjectStatus"; |
174 | public static final String JAVA_STOP_RESTART = "/javaRestart/stopOrRestart"; | 179 | public static final String JAVA_STOP_RESTART = "/javaRestart/stopOrRestart"; |
175 | public static final String JAVA_GET_MESSAGE = "/javaRestart/getMessage"; | 180 | public static final String JAVA_GET_MESSAGE = "/javaRestart/getMessage"; |
181 | + public static final String JAVA_RESTART_ALL = "/javaRestart/queryAll"; | ||
182 | + public static final String JAVA_STOP_APP = "/javaRestart/appExe"; | ||
183 | + | ||
184 | + | ||
176 | 185 | ||
177 | //双中心切换 | 186 | //双中心切换 |
178 | public static final String CENTERSWITCH_GET = "/centerSwitch/getSwitchList"; | 187 | public static final String CENTERSWITCH_GET = "/centerSwitch/getSwitchList"; |
@@ -24,7 +24,7 @@ public class ProjectOnline { | @@ -24,7 +24,7 @@ public class ProjectOnline { | ||
24 | JAVA_LIST.add(new Project("1","yohobuy-order","124","yoho30")); | 24 | JAVA_LIST.add(new Project("1","yohobuy-order","124","yoho30")); |
25 | JAVA_LIST.add(new Project("1","yoho-push","137","yoho30")); | 25 | JAVA_LIST.add(new Project("1","yoho-push","137","yoho30")); |
26 | JAVA_LIST.add(new Project("1","cms_push","514","yoho30")); | 26 | JAVA_LIST.add(new Project("1","cms_push","514","yoho30")); |
27 | - JAVA_LIST.add(new Project("1","mars_push","494","yoho30")); | 27 | + //JAVA_LIST.add(new Project("1","mars_push","494","yoho30")); |
28 | JAVA_LIST.add(new Project("1","yohobuy-shops","490","yoho30")); | 28 | JAVA_LIST.add(new Project("1","yohobuy-shops","490","yoho30")); |
29 | JAVA_LIST.add(new Project("1","yoho-social","353","yoho30")); | 29 | JAVA_LIST.add(new Project("1","yoho-social","353","yoho30")); |
30 | JAVA_LIST.add(new Project("1","yohobuy-union","133","yoho30")); | 30 | JAVA_LIST.add(new Project("1","yohobuy-union","133","yoho30")); |
1 | +package com.ui.ctrl.app; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSONObject; | ||
4 | +import com.ui.User.UserAuthLocal; | ||
5 | +import com.ui.app.common.ErrorCode; | ||
6 | +import com.ui.app.req.AppBaseReq; | ||
7 | +import com.ui.contants.HttpUriContants; | ||
8 | +import com.ui.http.HttpRestClient; | ||
9 | +import com.ui.model.BaseResponse; | ||
10 | +import com.ui.project.Project; | ||
11 | +import org.apache.commons.lang.StringUtils; | ||
12 | +import org.aspectj.lang.ProceedingJoinPoint; | ||
13 | +import org.aspectj.lang.Signature; | ||
14 | +import org.aspectj.lang.annotation.Around; | ||
15 | +import org.aspectj.lang.annotation.Aspect; | ||
16 | +import org.slf4j.Logger; | ||
17 | +import org.slf4j.LoggerFactory; | ||
18 | +import org.springframework.beans.factory.annotation.Autowired; | ||
19 | +import org.springframework.core.ParameterizedTypeReference; | ||
20 | +import org.springframework.core.annotation.AnnotationUtils; | ||
21 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
22 | + | ||
23 | +import java.util.List; | ||
24 | +import java.util.Set; | ||
25 | + | ||
26 | +@Aspect | ||
27 | +public class AppAspect { | ||
28 | + | ||
29 | + private Logger log = LoggerFactory.getLogger("appLogger"); | ||
30 | + | ||
31 | + @Autowired | ||
32 | + private HttpRestClient httpClient; | ||
33 | + | ||
34 | + @Autowired | ||
35 | + private UserAuthLocal userAuthLocal; | ||
36 | + | ||
37 | + @Around("within(com.ui.ctrl.app.*Ctrl) && execution (@org.springframework.web.bind.annotation.RequestMapping * *.*(..))") | ||
38 | + public Object appAspect(final ProceedingJoinPoint pjp) throws Throwable { | ||
39 | + BaseResponse baseResponse = new BaseResponse(); | ||
40 | + Signature signature = pjp.getSignature(); | ||
41 | + String method = signature.getName(); | ||
42 | + try { | ||
43 | + RequestMapping requestMapping = AnnotationUtils.findAnnotation(signature.getDeclaringType(), RequestMapping.class); | ||
44 | + String path = requestMapping.value()[0]; | ||
45 | + String module = path.split("_")[1]; | ||
46 | + if (!"login".equals(module)) {//登录不管 | ||
47 | + Object[] paramsArray = pjp.getArgs();//参数 | ||
48 | + AppBaseReq appBaseReq = argsArrayToJson(paramsArray); | ||
49 | + log.info(method + "--req--" + JSONObject.toJSONString(appBaseReq)); | ||
50 | + String accountname = appBaseReq.getAccountname();//用户名 | ||
51 | + String token = appBaseReq.getToken();//token | ||
52 | + if (StringUtils.isBlank(accountname) || StringUtils.isBlank(token)) { | ||
53 | + baseResponse.setCode(ErrorCode.PARAM_ERROR); | ||
54 | + baseResponse.setMessage(ErrorCode.PARAM_ERROR_MESSAGE); | ||
55 | + log.info(method + "--resp--" + JSONObject.toJSONString(baseResponse)); | ||
56 | + return baseResponse; | ||
57 | + } | ||
58 | + | ||
59 | + //校验token | ||
60 | + BaseResponse<String> response = httpClient.defaultPost(HttpUriContants.APP_GET_SEESION + "?token=" + token, null, BaseResponse.class); | ||
61 | + if (response == null) {//获取失败 | ||
62 | + baseResponse.setCode(ErrorCode.TOKEN_ERROR); | ||
63 | + baseResponse.setMessage(ErrorCode.TOKEN_ERROR_MESSAGE); | ||
64 | + log.info(method + "--resp--" + JSONObject.toJSONString(baseResponse)); | ||
65 | + return baseResponse; | ||
66 | + } | ||
67 | + String redisAccountName = response.getData(); | ||
68 | + if (StringUtils.isBlank(redisAccountName) || !redisAccountName.equals(accountname)) {//token失效 | ||
69 | + baseResponse.setCode(ErrorCode.SYSTEM_ERROR); | ||
70 | + baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE); | ||
71 | + log.info(method + "--resp--" + JSONObject.toJSONString(baseResponse)); | ||
72 | + return baseResponse; | ||
73 | + } | ||
74 | + //校验权限 | ||
75 | + Set<String> set = userAuthLocal.getAllModuleByname(accountname); | ||
76 | + if (!set.contains(module)) { | ||
77 | + baseResponse.setCode(ErrorCode.AUTH_ERROR); | ||
78 | + baseResponse.setMessage(ErrorCode.AUTH_ERROR_MESSAGE); | ||
79 | + log.info(method + "--resp--" + JSONObject.toJSONString(baseResponse)); | ||
80 | + return baseResponse; | ||
81 | + } | ||
82 | + } | ||
83 | + } catch (Exception e) { | ||
84 | + log.error("AppAspect failed", e); | ||
85 | + } | ||
86 | + try { | ||
87 | + Object result = pjp.proceed(); | ||
88 | + log.info(method + "--resp--" + JSONObject.toJSONString(result)); | ||
89 | + return result; | ||
90 | + } catch (Exception e) { | ||
91 | + log.error("AppAspect exe failed", e); | ||
92 | + baseResponse.setCode(ErrorCode.SYSTEM_ERROR); | ||
93 | + baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE); | ||
94 | + log.info(method + "--resp--" + JSONObject.toJSONString(baseResponse)); | ||
95 | + return baseResponse; | ||
96 | + } | ||
97 | + | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * 请求参数拼装 | ||
102 | + * | ||
103 | + * @param paramsArray | ||
104 | + * @return | ||
105 | + */ | ||
106 | + | ||
107 | + private AppBaseReq argsArrayToJson(Object[] paramsArray) { | ||
108 | + if (paramsArray != null && paramsArray.length > 0) { | ||
109 | + AppBaseReq appBaseReq = (AppBaseReq) paramsArray[0]; | ||
110 | + return appBaseReq; | ||
111 | + } | ||
112 | + return null; | ||
113 | + } | ||
114 | + | ||
115 | +} |
1 | +package com.ui.ctrl.app; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSON; | ||
4 | +import com.ui.app.common.ErrorCode; | ||
5 | +import com.ui.app.req.AppBaseReq; | ||
6 | +import com.ui.app.req.JavaRestartOperate; | ||
7 | +import com.ui.app.req.JavaRestartStatus; | ||
8 | +import com.ui.contants.HttpUriContants; | ||
9 | +import com.ui.http.HttpRestClient; | ||
10 | +import com.ui.model.BaseResponse; | ||
11 | +import com.ui.project.Project; | ||
12 | +import org.apache.commons.lang.StringUtils; | ||
13 | +import org.slf4j.Logger; | ||
14 | +import org.slf4j.LoggerFactory; | ||
15 | +import org.springframework.beans.factory.annotation.Autowired; | ||
16 | +import org.springframework.core.ParameterizedTypeReference; | ||
17 | +import org.springframework.web.bind.annotation.RequestBody; | ||
18 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
19 | +import org.springframework.web.bind.annotation.RestController; | ||
20 | + | ||
21 | +import java.util.LinkedList; | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | + | ||
25 | +/** | ||
26 | + * Created by zhengyouwei on 2016/11/14. | ||
27 | + * app 服务端,重写一个 | ||
28 | + */ | ||
29 | + | ||
30 | +@RestController | ||
31 | +@RequestMapping(value = "/app_javaRestart") | ||
32 | +public class AppJavaRestartCtrl { | ||
33 | + Logger log = LoggerFactory.getLogger(AppJavaRestartCtrl.class); | ||
34 | + | ||
35 | + @Autowired | ||
36 | + private HttpRestClient httpClient; | ||
37 | + | ||
38 | + /** | ||
39 | + * 获取所有的项目 | ||
40 | + * | ||
41 | + * @return | ||
42 | + */ | ||
43 | + @RequestMapping("/app_getprojectlist") | ||
44 | + public BaseResponse getProjectList(@RequestBody AppBaseReq appBaseReq) { | ||
45 | + BaseResponse baseResponse = new BaseResponse(); | ||
46 | + try { | ||
47 | + BaseResponse<List<Project>> response = httpClient.exchangeForget(HttpUriContants.JAVA_RESTART_ALL, new ParameterizedTypeReference<BaseResponse<List<Project>>>() { | ||
48 | + }, null); | ||
49 | + List<String> stringList = new LinkedList<>(); | ||
50 | + if (response != null) { | ||
51 | + for (Project project : response.getData()) { | ||
52 | + stringList.add(project.getName()); | ||
53 | + } | ||
54 | + } | ||
55 | + baseResponse.setData(stringList); | ||
56 | + } catch (Exception e) { | ||
57 | + log.error("app javaRestart getProjectList error", e); | ||
58 | + baseResponse.setCode(ErrorCode.SYSTEM_ERROR); | ||
59 | + baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE); | ||
60 | + | ||
61 | + } | ||
62 | + return baseResponse; | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
66 | + * 获取项目的状态 | ||
67 | + * | ||
68 | + * @return | ||
69 | + */ | ||
70 | + @RequestMapping("/app_getprojectdetail") | ||
71 | + public BaseResponse getProjectDetail(@RequestBody JavaRestartStatus javaRestartStatus) { | ||
72 | + BaseResponse baseResponse = new BaseResponse(); | ||
73 | + try { | ||
74 | + BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_RESTART_STATAUS + "?project=" + javaRestartStatus.getProject(), null, BaseResponse.class); | ||
75 | + if (rep == null){ | ||
76 | + baseResponse.setCode(ErrorCode.SYSTEM_ERROR); | ||
77 | + baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE); | ||
78 | + return baseResponse; | ||
79 | + }else { | ||
80 | + baseResponse.setData(rep.getData()); | ||
81 | + } | ||
82 | + } catch (Exception e) { | ||
83 | + log.error("app javaRestart getProjectDetail error", e); | ||
84 | + baseResponse.setCode(ErrorCode.SYSTEM_ERROR); | ||
85 | + baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE); | ||
86 | + | ||
87 | + } | ||
88 | + return baseResponse; | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * 操作 | ||
93 | + * | ||
94 | + * @return | ||
95 | + */ | ||
96 | + @RequestMapping("/app_operate") | ||
97 | + public BaseResponse javaRestartOperate(@RequestBody JavaRestartOperate javaRestartOperate) { | ||
98 | + BaseResponse baseResponse = new BaseResponse(); | ||
99 | + try { | ||
100 | + if (StringUtils.isBlank(javaRestartOperate.getProject()) || StringUtils.isBlank(javaRestartOperate.getOperate()) || javaRestartOperate.getIps() == null ){ | ||
101 | + baseResponse.setCode(ErrorCode.PARAM_ERROR); | ||
102 | + baseResponse.setMessage(ErrorCode.PARAM_ERROR_MESSAGE); | ||
103 | + return baseResponse; | ||
104 | + } | ||
105 | + | ||
106 | + httpClient.defaultPost(HttpUriContants.JAVA_STOP_APP, javaRestartOperate, BaseResponse.class); | ||
107 | + } catch (Exception e) { | ||
108 | + log.error("app javaRestart getprojects error", e); | ||
109 | + baseResponse.setCode(ErrorCode.SYSTEM_ERROR); | ||
110 | + baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE); | ||
111 | + | ||
112 | + } | ||
113 | + return baseResponse; | ||
114 | + } | ||
115 | + | ||
116 | + public static void main(String[] args) { | ||
117 | + JavaRestartOperate javaRestartOperate = new JavaRestartOperate(); | ||
118 | + javaRestartOperate.setToken("FdHvfmnGrsGrWGFz"); | ||
119 | + javaRestartOperate.setAccountname("admin"); | ||
120 | + javaRestartOperate.setOperate("stop"); | ||
121 | + javaRestartOperate.setProject("yoho-gateway"); | ||
122 | + javaRestartOperate.setIps(new String[]{"172.168.1.1","172.165.1.1"}); | ||
123 | + System.out.println(JSON.toJSON(javaRestartOperate)); | ||
124 | + | ||
125 | + } | ||
126 | + | ||
127 | +} |
1 | +package com.ui.ctrl.app; | ||
2 | + | ||
3 | +import com.ui.User.MD5Util; | ||
4 | +import com.ui.User.UserAuthLocal; | ||
5 | +import com.ui.app.common.AppModule; | ||
6 | +import com.ui.app.common.ErrorCode; | ||
7 | +import com.ui.app.req.AppBaseReq; | ||
8 | +import com.ui.app.req.LoginReq; | ||
9 | +import com.ui.app.resp.AccountInfo; | ||
10 | +import com.ui.contants.HttpUriContants; | ||
11 | +import com.ui.http.HttpRestClient; | ||
12 | +import com.ui.model.BaseResponse; | ||
13 | +import com.ui.model.req.User; | ||
14 | +import org.apache.commons.lang.RandomStringUtils; | ||
15 | +import org.slf4j.Logger; | ||
16 | +import org.slf4j.LoggerFactory; | ||
17 | +import org.springframework.beans.factory.annotation.Autowired; | ||
18 | +import org.springframework.web.bind.annotation.RequestBody; | ||
19 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
20 | +import org.springframework.web.bind.annotation.RestController; | ||
21 | + | ||
22 | +import java.util.Set; | ||
23 | + | ||
24 | + | ||
25 | +/** | ||
26 | + * Created by zhengyouwei on 2016/11/14. | ||
27 | + * app 服务端,重写一个 | ||
28 | + */ | ||
29 | + | ||
30 | +@RestController | ||
31 | +@RequestMapping(value = "/app_login") | ||
32 | +public class AppLoginCtrl { | ||
33 | + Logger log = LoggerFactory.getLogger(AppLoginCtrl.class); | ||
34 | + | ||
35 | + @Autowired | ||
36 | + private HttpRestClient httpClient; | ||
37 | + | ||
38 | + @Autowired | ||
39 | + private UserAuthLocal userAuthLocal; | ||
40 | + | ||
41 | + /** | ||
42 | + * 登录 | ||
43 | + * @param loginReq | ||
44 | + * @return | ||
45 | + */ | ||
46 | + @RequestMapping("/app_login") | ||
47 | + public BaseResponse login(@RequestBody LoginReq loginReq) { | ||
48 | + BaseResponse baseResponse = new BaseResponse(); | ||
49 | + try { | ||
50 | + User u = userAuthLocal.getUserByname(loginReq.getAccountname()); | ||
51 | + if (u == null) { | ||
52 | + baseResponse.setCode(ErrorCode.LOGIN_ERROR); | ||
53 | + baseResponse.setMessage("account not exist"); | ||
54 | + return baseResponse; | ||
55 | + } | ||
56 | + if (u.getPwd().equals(MD5Util.encryption(loginReq.getPassword()))) {//登录成功 | ||
57 | + //生成TOKEN | ||
58 | + String token = RandomStringUtils.randomAlphabetic(16); | ||
59 | + //记录token | ||
60 | + httpClient.defaultPost(HttpUriContants.APP_ADD_SEESION + "?name=" + loginReq.getAccountname() + "&token=" + token, null, BaseResponse.class); | ||
61 | + | ||
62 | + //返回信息 | ||
63 | + AccountInfo accountInfo = new AccountInfo(); | ||
64 | + accountInfo.setAccountname(loginReq.getAccountname()); | ||
65 | + accountInfo.setToken(token); | ||
66 | + accountInfo.setCName(u.getCName()); | ||
67 | + accountInfo.setEmail(u.getEmail()); | ||
68 | + accountInfo.setMobile(u.getMobile()); | ||
69 | + accountInfo.setRole(u.getRole()); | ||
70 | + Set<String> authModules = userAuthLocal.getAllModuleByname(loginReq.getAccountname()); | ||
71 | + String privacy = AppModule.getAuthAppModule(authModules); | ||
72 | + accountInfo.setPrivacy(privacy); | ||
73 | + baseResponse.setData(accountInfo); | ||
74 | + } else { | ||
75 | + baseResponse.setCode(ErrorCode.LOGIN_ERROR); | ||
76 | + baseResponse.setMessage("password error"); | ||
77 | + return baseResponse; | ||
78 | + } | ||
79 | + | ||
80 | + } catch (Exception e) { | ||
81 | + log.error("app login error",e); | ||
82 | + baseResponse.setCode(ErrorCode.SYSTEM_ERROR); | ||
83 | + baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE); | ||
84 | + | ||
85 | + } | ||
86 | + return baseResponse; | ||
87 | + | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * 登出 | ||
92 | + * @return | ||
93 | + */ | ||
94 | + @RequestMapping("/app_logout") | ||
95 | + public BaseResponse logout(@RequestBody AppBaseReq appBaseReq) { | ||
96 | + BaseResponse baseResponse = new BaseResponse(); | ||
97 | + try { | ||
98 | + httpClient.defaultPost(HttpUriContants.APP_REMOVE_SEESION + "?token=" + appBaseReq.getToken(), null, BaseResponse.class); | ||
99 | + } catch (Exception e) { | ||
100 | + log.error("app logout error",e); | ||
101 | + baseResponse.setCode(ErrorCode.SYSTEM_ERROR); | ||
102 | + baseResponse.setMessage(ErrorCode.SYSTEM_ERROR_MESSAGE); | ||
103 | + | ||
104 | + } | ||
105 | + return baseResponse; | ||
106 | + | ||
107 | + } | ||
108 | + | ||
109 | +} |
@@ -16,7 +16,9 @@ | @@ -16,7 +16,9 @@ | ||
16 | <context:property-placeholder location="classpath:*.properties" /> | 16 | <context:property-placeholder location="classpath:*.properties" /> |
17 | <context:component-scan base-package="com.ui" /> | 17 | <context:component-scan base-package="com.ui" /> |
18 | <!-- 打开aop 注解 --> | 18 | <!-- 打开aop 注解 --> |
19 | - <aop:aspectj-autoproxy proxy-target-class="true"/> | 19 | + <aop:aspectj-autoproxy/> |
20 | + <bean id="appAspect" class="com.ui.ctrl.app.AppAspect" /> | ||
21 | + | ||
20 | 22 | ||
21 | <mvc:annotation-driven> | 23 | <mvc:annotation-driven> |
22 | <mvc:message-converters> | 24 | <mvc:message-converters> |
@@ -71,9 +73,12 @@ | @@ -71,9 +73,12 @@ | ||
71 | <mvc:exclude-mapping path="/script/**"/> | 73 | <mvc:exclude-mapping path="/script/**"/> |
72 | <mvc:exclude-mapping path="/sql_format/**"/> | 74 | <mvc:exclude-mapping path="/sql_format/**"/> |
73 | <mvc:exclude-mapping path="/dashboard/**"/> | 75 | <mvc:exclude-mapping path="/dashboard/**"/> |
76 | + <mvc:exclude-mapping path="/app_login/**"/> | ||
77 | + <mvc:exclude-mapping path="/app_javaRestart/**"/> | ||
74 | 78 | ||
75 | <bean class="com.ui.interceptor.AuthInterceptor"/> | 79 | <bean class="com.ui.interceptor.AuthInterceptor"/> |
76 | </mvc:interceptor> | 80 | </mvc:interceptor> |
81 | + | ||
77 | </mvc:interceptors> | 82 | </mvc:interceptors> |
78 | 83 | ||
79 | </beans> | 84 | </beans> |
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | <!-- 日志最大的历史 7天 --> | 11 | <!-- 日志最大的历史 7天 --> |
12 | <property name="maxHistory" value="2"/> | 12 | <property name="maxHistory" value="2"/> |
13 | <!-- 日志最大的文件大小 10MB--> | 13 | <!-- 日志最大的文件大小 10MB--> |
14 | - <property name="maxFileSize" value="10MB"/> | 14 | + <property name="maxFileSize" value="30MB"/> |
15 | 15 | ||
16 | <!-- ConsoleAppender 控制台输出日志 --> | 16 | <!-- ConsoleAppender 控制台输出日志 --> |
17 | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | 17 | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
@@ -66,6 +66,29 @@ | @@ -66,6 +66,29 @@ | ||
66 | </encoder> | 66 | </encoder> |
67 | </appender> | 67 | </appender> |
68 | 68 | ||
69 | + <!-- 按照每天生成日志文件 --> | ||
70 | + <appender name="APP_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
71 | + <file>${catalina.home}/logs/app.log</file> | ||
72 | + <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> | ||
73 | + <level>INFO</level> | ||
74 | + </filter> | ||
75 | + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
76 | + <!-- 按天回滚 daily --> | ||
77 | + <fileNamePattern> | ||
78 | + ${catalina.home}/logs/app.%d{yyyy-MM-dd}.%i.log.gz | ||
79 | + </fileNamePattern> | ||
80 | + <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> | ||
81 | + <!-- or whenever the file size reaches 100MB --> | ||
82 | + <maxFileSize>${maxFileSize}</maxFileSize> | ||
83 | + </timeBasedFileNamingAndTriggeringPolicy> | ||
84 | + <!-- 日志最大的历史 60天 --> | ||
85 | + <maxHistory>${maxHistory}</maxHistory> | ||
86 | + </rollingPolicy> | ||
87 | + <encoder> | ||
88 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level - %msg%n</pattern> | ||
89 | + </encoder> | ||
90 | + </appender> | ||
91 | + | ||
69 | <!-- root级别 DEBUG --> | 92 | <!-- root级别 DEBUG --> |
70 | <root level="INFO"> | 93 | <root level="INFO"> |
71 | <!-- 控制台输出 --> | 94 | <!-- 控制台输出 --> |
@@ -75,4 +98,9 @@ | @@ -75,4 +98,9 @@ | ||
75 | <appender-ref ref="WARN" /> | 98 | <appender-ref ref="WARN" /> |
76 | </root> | 99 | </root> |
77 | 100 | ||
101 | + <logger name="appLogger" additivity="false"> | ||
102 | + <level value="INFO"/> | ||
103 | + <appender-ref ref="APP_LOG"/> | ||
104 | + </logger> | ||
105 | + | ||
78 | </configuration> | 106 | </configuration> |
-
Please register or login to post a comment