Skip to content

Commit de37c8f

Browse files
authored
Annotate PrepareAction with CSRF not required (#38)
1 parent 7664e43 commit de37c8f

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

src/org/labkey/filetransfer/FileTransferController.java

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.labkey.api.data.Container;
3434
import org.labkey.api.data.ContainerManager;
3535
import org.labkey.api.security.AdminConsoleAction;
36+
import org.labkey.api.security.CSRF;
3637
import org.labkey.api.security.RequiresNoPermission;
3738
import org.labkey.api.security.RequiresPermission;
3839
import org.labkey.api.security.User;
@@ -87,7 +88,7 @@ public static ActionURL getComplianceSettingsURL()
8788
}
8889

8990
@AdminConsoleAction(AdminOperationsPermission.class)
90-
public class ConfigurationAction extends FormViewAction<FileTransferConfigForm>
91+
public static class ConfigurationAction extends FormViewAction<FileTransferConfigForm>
9192
{
9293
@Override
9394
public void addNavTrail(NavTree root)
@@ -160,11 +161,11 @@ public URLHelper getSuccessURL(FileTransferConfigForm form)
160161

161162
/**
162163
* This action stores certain properties in the session and then redirects to the authentication provider's
163-
* authorization UI. This redirect contains a parameter indicating the action to return to when authentication is
164+
* authorization UI. This redirect contains a parameter indicating the action to return to when authentication is
164165
* complete.
165166
*/
166167
@RequiresPermission(ReadPermission.class)
167-
public class AuthAction extends SimpleViewAction<TransferSelectionForm>
168+
public static class AuthAction extends SimpleViewAction<TransferSelectionForm>
168169
{
169170
@Override
170171
public void addNavTrail(NavTree root)
@@ -203,6 +204,7 @@ public String getDataRegionSelectionKey()
203204
return dataRegionSelectionKey;
204205
}
205206

207+
@SuppressWarnings("unused")
206208
public void setDataRegionSelectionKey(String dataRegionSelectionKey)
207209
{
208210
this.dataRegionSelectionKey = dataRegionSelectionKey;
@@ -213,21 +215,22 @@ public Integer getWebPartId()
213215
return webPartId;
214216
}
215217

218+
@SuppressWarnings("unused")
216219
public void setWebPartId(Integer webPartId)
217220
{
218221
this.webPartId = webPartId;
219222
}
220223
}
221224

222225
/**
223-
* This action is the target of the authorization action from the file transfer provider. If authorization has
226+
* This action is the target of the authorization action from the file transfer provider. If authorization has
224227
* been granted, the code provided from that authorization will be used to retrieve credentials to be used in
225-
* initiating transfer requests. In any case, this action redirects to a page where we give feedback to the user
228+
* initiating transfer requests. In any case, this action redirects to a page where we give feedback to the user
226229
* and display items for next steps, which are either to return to the page where the initial selection of files was
227230
* made, choose a destination endpoint, or initiate a transfer of the selected files.
228231
*/
229232
@RequiresNoPermission
230-
public class TokensAction extends SimpleRedirectAction<AuthForm>
233+
public static class TokensAction extends SimpleRedirectAction<AuthForm>
231234
{
232235
private boolean authorized = false;
233236
private ErrorCode errorCode = null;
@@ -306,6 +309,7 @@ public String getCode()
306309
return _code;
307310
}
308311

312+
@SuppressWarnings("unused")
309313
public void setCode(String code)
310314
{
311315
_code = code;
@@ -316,21 +320,22 @@ public String getError()
316320
return _error;
317321
}
318322

323+
@SuppressWarnings("unused")
319324
public void setError(String error)
320325
{
321326
_error = error;
322327
}
323328
}
324329

325330
@RequiresPermission(ReadPermission.class)
326-
public class TransferAction extends MutatingApiAction<TransferRequestForm>
331+
public static class TransferAction extends MutatingApiAction<TransferRequestForm>
327332
{
328333
@Override
329334
public Object execute(TransferRequestForm form, BindException errors)
330335
{
331336
FileTransferProvider provider = FileTransferManager.get().getProvider(getViewContext());
332337
if (provider == null)
333-
return new SimpleResponse(false, "Count not find File Transfer Provider in this session.");
338+
return new SimpleResponse(false, "Could not find File Transfer Provider in this session.");
334339
TransferEndpoint source = new TransferEndpoint(form.getSourceEndpoint(), form.getSourcePath());
335340
TransferEndpoint destination = new TransferEndpoint(form.getDestinationEndpoint(), form.getDestinationPath());
336341
try
@@ -358,6 +363,7 @@ public String getSourceEndpoint()
358363
return sourceEndpoint;
359364
}
360365

366+
@SuppressWarnings("unused")
361367
public void setSourceEndpoint(String sourceEndpoint)
362368
{
363369
this.sourceEndpoint = sourceEndpoint;
@@ -368,6 +374,7 @@ public String getSourcePath()
368374
return sourcePath;
369375
}
370376

377+
@SuppressWarnings("unused")
371378
public void setSourcePath(String sourcePath)
372379
{
373380
this.sourcePath = sourcePath;
@@ -378,6 +385,7 @@ public String getDestinationEndpoint()
378385
return destinationEndpoint;
379386
}
380387

388+
@SuppressWarnings("unused")
381389
public void setDestinationEndpoint(String destinationEndpoint)
382390
{
383391
this.destinationEndpoint = destinationEndpoint;
@@ -388,6 +396,7 @@ public String getDestinationPath()
388396
return destinationPath;
389397
}
390398

399+
@SuppressWarnings("unused")
391400
public void setDestinationPath(String destinationPath)
392401
{
393402
this.destinationPath = destinationPath;
@@ -398,14 +407,16 @@ public String getLabel()
398407
return label;
399408
}
400409

410+
@SuppressWarnings("unused")
401411
public void setLabel(String label)
402412
{
403413
this.label = label;
404414
}
405415
}
406416

407417
@RequiresPermission(ReadPermission.class)
408-
public class PrepareAction extends SimpleViewAction<PrepareTransferForm>
418+
@CSRF(CSRF.Method.NONE) // Globus POSTs to this action, but it's non-mutating, so no need for CSRF
419+
public static class PrepareAction extends SimpleViewAction<PrepareTransferForm>
409420
{
410421
@Override
411422
public void addNavTrail(NavTree root)
@@ -455,6 +466,7 @@ public Boolean getAuthorized()
455466
return authorized;
456467
}
457468

469+
@SuppressWarnings("unused")
458470
public void setAuthorized(Boolean authorized)
459471
{
460472
this.authorized = authorized;
@@ -466,16 +478,19 @@ public String getDestinationId()
466478
return endpoint_id;
467479
}
468480

481+
@SuppressWarnings("unused")
469482
public void setDestinationId(String destinationId)
470483
{
471484
endpoint_id = destinationId;
472485
}
473486

487+
@SuppressWarnings("unused")
474488
public String getEndpoint_id()
475489
{
476490
return endpoint_id;
477491
}
478492

493+
@SuppressWarnings("unused")
479494
public void setEndpoint_id(String endpoint_id)
480495
{
481496
this.endpoint_id = endpoint_id;
@@ -486,6 +501,7 @@ public String getPath()
486501
return path;
487502
}
488503

504+
@SuppressWarnings("unused")
489505
public void setPath(String path)
490506
{
491507
this.path = path;
@@ -496,6 +512,7 @@ public String getLabel()
496512
return label;
497513
}
498514

515+
@SuppressWarnings("unused")
499516
public void setLabel(String label)
500517
{
501518
this.label = label;
@@ -506,6 +523,7 @@ public ErrorCode getErrorCode()
506523
return errorCode;
507524
}
508525

526+
@SuppressWarnings("unused")
509527
public void setErrorCode(ErrorCode errorCode)
510528
{
511529
this.errorCode = errorCode;
@@ -522,19 +540,17 @@ public void testActionPermissions()
522540
User user = TestContext.get().getUser();
523541
assertTrue(user.hasSiteAdminPermission());
524542

525-
FileTransferController controller = new FileTransferController();
526-
527543
// @RequiresPermission(ReadPermission.class)
528544
assertForReadPermission(user,
529-
controller.new PrepareAction(),
530-
controller.new TransferAction(),
531-
controller.new AuthAction()
545+
new PrepareAction(),
546+
new TransferAction(),
547+
new AuthAction()
532548
);
533549

534550
// @AdminConsoleAction
535551
// @RequiresPermission(AdminOperationsPermission.class)
536552
assertForAdminPermission(ContainerManager.getRoot(), user,
537-
controller.new ConfigurationAction()
553+
new ConfigurationAction()
538554
);
539555
}
540556
}

0 commit comments

Comments
 (0)