SHOW:
|
|
- or go back to the newest paste.
| 1 | // Controller | |
| 2 | public String execute() | |
| 3 | throws Exception {
| |
| 4 | if(UserSecurityContext.hasPermission("SOME_AUTHORIZATION")) {
| |
| 5 | try {
| |
| 6 | - | service.callSomething(); |
| 6 | + | ServiceResult result = service.callSomething(); |
| 7 | - | return SUCCESS; |
| 7 | + | return result.execute(this); |
| 8 | } | |
| 9 | catch(SomeReallyBadUnExpectedException e) {
| |
| 10 | e.printStackTrace(); | |
| 11 | throw new RuntimeException(e); | |
| 12 | } | |
| 13 | } | |
| 14 | else {
| |
| 15 | addActionError("error.permission.denied");
| |
| 16 | return INPUT; | |
| 17 | } | |
| 18 | } | |
| 19 | ||
| 20 | public class AccessDeniedServiceResult implements ServiceResult {
| |
| 21 | @Override | |
| 22 | public String execute(Action action) {
| |
| 23 | action.addActionError("error.permission.denied");
| |
| 24 | return INPUT; | |
| 25 | } | |
| 26 | } | |
| 27 | ||
| 28 | // Service | |
| 29 | // Just an example of how you can do service exceptions | |
| 30 | public ServiceResult callSomething() | |
| 31 | throws AccessDeniedException {
| |
| 32 | if(!UserSecurityContext.hasPermission("SOME_AUTH"))
| |
| 33 | return new AccessDeniedServiceResult(); | |
| 34 | ||
| 35 | // do your service stuff | |
| 36 | } |