|
36 | 36 | import org.entur.gbfs.validation.model.ValidationResult; |
37 | 37 | import org.entur.gbfs.validation.model.ValidatorError; |
38 | 38 | import org.entur.gbfs.validator.api.gen.ValidateApiDelegate; |
39 | | -import org.entur.gbfs.validator.api.model.BasicAuth; |
40 | | -import org.entur.gbfs.validator.api.model.BearerTokenAuth; |
41 | 39 | import org.entur.gbfs.validator.api.model.FileError; |
42 | 40 | import org.entur.gbfs.validator.api.model.GbfsFile; |
43 | | -import org.entur.gbfs.validator.api.model.OAuthClientCredentialsGrantAuth; |
44 | 41 | import org.entur.gbfs.validator.api.model.SystemError; |
45 | 42 | import org.entur.gbfs.validator.api.model.ValidatePostRequest; |
46 | 43 | import org.entur.gbfs.validator.api.model.ValidatePostRequestAuth; |
@@ -113,40 +110,7 @@ public ResponseEntity<org.entur.gbfs.validator.api.model.ValidationResult> valid |
113 | 110 | validatePostRequest.getFeedUrl() |
114 | 111 | ); |
115 | 112 | try { |
116 | | - Authentication loaderAuth = null; |
117 | | - ValidatePostRequestAuth apiAuth = validatePostRequest.getAuth(); |
118 | | - |
119 | | - if (apiAuth != null) { |
120 | | - if (apiAuth instanceof BasicAuth basic) { |
121 | | - if (basic.getUsername() != null && basic.getPassword() != null) { |
122 | | - loaderAuth = |
123 | | - new org.entur.gbfs.validator.loader.auth.BasicAuth( |
124 | | - basic.getUsername(), |
125 | | - basic.getPassword() |
126 | | - ); |
127 | | - } |
128 | | - } else if (apiAuth instanceof BearerTokenAuth bearer) { |
129 | | - if (bearer.getToken() != null) { |
130 | | - loaderAuth = |
131 | | - new org.entur.gbfs.validator.loader.auth.BearerTokenAuth( |
132 | | - bearer.getToken() |
133 | | - ); |
134 | | - } |
135 | | - } else if (apiAuth instanceof OAuthClientCredentialsGrantAuth oauth) { |
136 | | - if ( |
137 | | - oauth.getClientId() != null && |
138 | | - oauth.getClientSecret() != null && |
139 | | - oauth.getTokenUrl() != null |
140 | | - ) { |
141 | | - loaderAuth = |
142 | | - new org.entur.gbfs.validator.loader.auth.OAuthClientCredentialsGrantAuth( |
143 | | - oauth.getClientId(), |
144 | | - oauth.getClientSecret(), |
145 | | - oauth.getTokenUrl().toString() |
146 | | - ); |
147 | | - } |
148 | | - } |
149 | | - } |
| 113 | + Authentication loaderAuth = getAuthentication(validatePostRequest); |
150 | 114 |
|
151 | 115 | List<LoadedFile> allLoadedFiles = loader.load( |
152 | 116 | validatePostRequest.getFeedUrl(), |
@@ -210,6 +174,47 @@ public ResponseEntity<org.entur.gbfs.validator.api.model.ValidationResult> valid |
210 | 174 | } |
211 | 175 | } |
212 | 176 |
|
| 177 | + private static Authentication getAuthentication( |
| 178 | + ValidatePostRequest validatePostRequest |
| 179 | + ) { |
| 180 | + Authentication loaderAuth = null; |
| 181 | + ValidatePostRequestAuth apiAuth = validatePostRequest.getAuth(); |
| 182 | + |
| 183 | + if (apiAuth != null) { |
| 184 | + String authType = apiAuth.getAuthType(); |
| 185 | + if ("basicAuth".equals(authType)) { |
| 186 | + if (apiAuth.getUsername() != null && apiAuth.getPassword() != null) { |
| 187 | + loaderAuth = |
| 188 | + new org.entur.gbfs.validator.loader.auth.BasicAuth( |
| 189 | + apiAuth.getUsername(), |
| 190 | + apiAuth.getPassword() |
| 191 | + ); |
| 192 | + } |
| 193 | + } else if ("bearerToken".equals(authType)) { |
| 194 | + if (apiAuth.getToken() != null) { |
| 195 | + loaderAuth = |
| 196 | + new org.entur.gbfs.validator.loader.auth.BearerTokenAuth( |
| 197 | + apiAuth.getToken() |
| 198 | + ); |
| 199 | + } |
| 200 | + } else if ("oauthClientCredentialsGrant".equals(authType)) { |
| 201 | + if ( |
| 202 | + apiAuth.getClientId() != null && |
| 203 | + apiAuth.getClientSecret() != null && |
| 204 | + apiAuth.getTokenUrl() != null |
| 205 | + ) { |
| 206 | + loaderAuth = |
| 207 | + new org.entur.gbfs.validator.loader.auth.OAuthClientCredentialsGrantAuth( |
| 208 | + apiAuth.getClientId(), |
| 209 | + apiAuth.getClientSecret(), |
| 210 | + apiAuth.getTokenUrl() |
| 211 | + ); |
| 212 | + } |
| 213 | + } |
| 214 | + } |
| 215 | + return loaderAuth; |
| 216 | + } |
| 217 | + |
213 | 218 | private org.entur.gbfs.validator.api.model.ValidationResult mergeValidationResults( |
214 | 219 | List<org.entur.gbfs.validator.api.model.ValidationResult> results |
215 | 220 | ) { |
|
0 commit comments