|
18 | 18 | import org.purpurmc.papyrus.db.repository.VersionRepository;
|
19 | 19 | import org.purpurmc.papyrus.exception.BuildAlreadyExists;
|
20 | 20 | import org.purpurmc.papyrus.exception.FileUploadError;
|
21 |
| -import org.purpurmc.papyrus.exception.InvalidAuthToken; |
22 | 21 | import org.purpurmc.papyrus.exception.InvalidStateKey;
|
| 22 | +import org.purpurmc.papyrus.util.AuthUtil; |
23 | 23 | import org.springframework.beans.factory.annotation.Autowired;
|
24 | 24 | import org.springframework.http.HttpHeaders;
|
25 | 25 | import org.springframework.http.ResponseEntity;
|
@@ -78,7 +78,7 @@ public CreationController(
|
78 | 78 | @PostMapping
|
79 | 79 | @ResponseBody
|
80 | 80 | public CreateBuild createBuild(@RequestHeader(HttpHeaders.AUTHORIZATION) String authHeader, @RequestBody CreateBuildBody body) {
|
81 |
| - this.requireAuth(authHeader); |
| 81 | + AuthUtil.requireAuth(configuration, authHeader); |
82 | 82 |
|
83 | 83 | Project project = null;
|
84 | 84 | Version version = null;
|
@@ -130,7 +130,7 @@ public CreateBuild createBuild(@RequestHeader(HttpHeaders.AUTHORIZATION) String
|
130 | 130 | @PostMapping("/upload")
|
131 | 131 | @ResponseBody
|
132 | 132 | public ResponseEntity<String> uploadFile(@RequestHeader(HttpHeaders.AUTHORIZATION) String authHeader, @RequestParam("stateKey") String stateKey, @RequestParam("file") MultipartFile uploadFile) {
|
133 |
| - this.requireAuth(authHeader); |
| 133 | + AuthUtil.requireAuth(configuration, authHeader); |
134 | 134 |
|
135 | 135 | CreationState state;
|
136 | 136 | try {
|
@@ -174,21 +174,6 @@ public ResponseEntity<String> uploadFile(@RequestHeader(HttpHeaders.AUTHORIZATIO
|
174 | 174 | return ResponseEntity.ok("");
|
175 | 175 | }
|
176 | 176 |
|
177 |
| - private void requireAuth(String authHeader) { |
178 |
| - String[] parts = authHeader.trim().split(" "); |
179 |
| - if (parts.length != 2) { |
180 |
| - throw new InvalidAuthToken(); |
181 |
| - } |
182 |
| - |
183 |
| - if (!parts[0].equals("Basic")) { |
184 |
| - throw new InvalidAuthToken(); |
185 |
| - } |
186 |
| - |
187 |
| - if (!parts[1].equals(configuration.getAuthToken())) { |
188 |
| - throw new InvalidAuthToken(); |
189 |
| - } |
190 |
| - } |
191 |
| - |
192 | 177 | private record CreateBuildBody(String project,
|
193 | 178 | String version,
|
194 | 179 | String build,
|
|
0 commit comments