3
3
import com .arextest .common .annotation .AppAuth ;
4
4
import com .arextest .common .context .ArexContext ;
5
5
import com .arextest .common .jwt .JWTService ;
6
- import com .arextest .common .model .response .ResponseCode ;
7
- import com .arextest .common .utils .ResponseUtils ;
6
+ import com .arextest .common .utils .ResponseUtils_New ;
8
7
import com .arextest .config .model .dao .config .SystemConfigurationCollection .KeySummary ;
9
8
import com .arextest .config .model .dto .application .ApplicationConfiguration ;
10
9
import com .arextest .config .model .dto .system .SystemConfiguration ;
11
10
import com .arextest .config .repository .impl .ApplicationConfigurationRepositoryImpl ;
12
11
import com .arextest .config .repository .impl .SystemConfigurationRepositoryImpl ;
12
+ import com .arextest .storage .model .ArexStorageResponseCode ;
13
13
import com .arextest .storage .service .config .ApplicationService ;
14
14
import java .util .List ;
15
15
import java .util .Optional ;
@@ -61,18 +61,12 @@ public Object doAround(ProceedingJoinPoint point, AppAuth auth) throws Throwable
61
61
// do aspect by appId
62
62
if (context .getAppId () == null ) {
63
63
LOGGER .error ("header has no appId" );
64
- return reject (point , auth , NO_APPID );
64
+ return reject (point , auth , NO_APPID , ArexStorageResponseCode . APP_AUTH_NO_APP_ID );
65
65
}
66
66
67
67
// do aspect by owner exist
68
68
OwnerExistResult ownerExistResult = getOwnerExistResult ();
69
- if (ownerExistResult .getExist ()) {
70
- context .setPassAuth (true );
71
- return point .proceed ();
72
- } else {
73
- context .setPassAuth (false );
74
- return reject (point , auth , ownerExistResult .getRemark ());
75
- }
69
+ return processOwnerExistVerify (ownerExistResult , context , point , auth );
76
70
77
71
} finally {
78
72
ArexContext .removeContext ();
@@ -110,23 +104,39 @@ protected OwnerExistResult getOwnerExistResult() {
110
104
List <ApplicationConfiguration > applications = applicationConfigurationRepository .listBy (
111
105
context .getAppId ());
112
106
if (CollectionUtils .isEmpty (applications )) {
113
- LOGGER .error ("error appId" );
114
- return new OwnerExistResult (false , ERROR_APPID );
107
+ LOGGER .error ("error appId, appId: {}" , context .getAppId ());
108
+ return new OwnerExistResult (false , ERROR_APPID ,
109
+ ArexStorageResponseCode .APP_AUTH_ERROR_APP_ID );
115
110
}
116
111
ApplicationConfiguration application = applications .get (0 );
117
112
owners = application .getOwners ();
118
113
}
119
114
if (CollectionUtils .isEmpty (owners ) || owners .contains (userName )) {
120
- return new OwnerExistResult (true , null );
115
+ return new OwnerExistResult (true , null , null );
121
116
} else {
122
- return new OwnerExistResult (false , NO_PERMISSION );
117
+ return new OwnerExistResult (false , NO_PERMISSION ,
118
+ ArexStorageResponseCode .APP_AUTH_NO_PERMISSION );
123
119
}
124
120
}
125
121
126
- private Object reject (ProceedingJoinPoint point , AppAuth auth , String remark ) throws Throwable {
122
+ private Object processOwnerExistVerify (OwnerExistResult ownerExistResult , ArexContext context ,
123
+ ProceedingJoinPoint point , AppAuth auth )
124
+ throws Throwable {
125
+ if (ownerExistResult .getExist ()) {
126
+ context .setPassAuth (true );
127
+ return point .proceed ();
128
+ } else {
129
+ context .setPassAuth (false );
130
+ return reject (point , auth , ownerExistResult .getRemark (), ownerExistResult .getResponseCode ());
131
+ }
132
+ }
133
+
134
+
135
+ private Object reject (ProceedingJoinPoint point , AppAuth auth , String remark , int responseCode )
136
+ throws Throwable {
127
137
switch (auth .rejectStrategy ()) {
128
138
case FAIL_RESPONSE :
129
- return ResponseUtils .errorResponse (remark , ResponseCode . AUTHENTICATION_FAILED );
139
+ return ResponseUtils_New .errorResponse (remark , responseCode );
130
140
case DOWNGRADE :
131
141
ArexContext .getContext ().setPassAuth (false );
132
142
return point .proceed ();
@@ -135,6 +145,7 @@ private Object reject(ProceedingJoinPoint point, AppAuth auth, String remark) th
135
145
}
136
146
}
137
147
148
+
138
149
private void init () {
139
150
authSwitch = Optional .ofNullable (
140
151
systemConfigurationRepository .getSystemConfigByKey (KeySummary .AUTH_SWITCH ))
@@ -149,5 +160,6 @@ public static class OwnerExistResult {
149
160
150
161
private Boolean exist ;
151
162
private String remark ;
163
+ private Integer responseCode ;
152
164
}
153
165
}
0 commit comments