generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PO-327: Add custom annotation for authorisation (#342)
* PO-327: Add custom annotation for authorisation * PO-327: Add custom annotation for authorisation * Fix typos
- Loading branch information
1 parent
eaab572
commit 431a759
Showing
11 changed files
with
400 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/uk/gov/hmcts/opal/authorisation/aspect/AuthorizedRoleHasPermission.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package uk.gov.hmcts.opal.authorisation.aspect; | ||
|
||
import uk.gov.hmcts.opal.authorisation.model.Permissions; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* The <code>AuthorizedRoleHasPermission</code> annotation is used to authorise or deny execution of a business method | ||
* based on the role. | ||
* If the given role has the permission then only execution will be allowed, otherwise PermissionNotAllowedException | ||
* will be thrown. | ||
* For example: | ||
* The role can be one of the argument of the annotated method. | ||
* <pre> | ||
* @AuthorizedRoleHasPermission(Permissions.ACCOUNT_ENQUIRY) | ||
* public void businessMethod(Role role) { ... } | ||
* </pre> | ||
* The role can be inferred if one of the argument is of type NoteDto, the role will be picked by matching | ||
* businessUnitId of NoteDto argument within the userState roles. | ||
* If this role has the permission then only execution will be allowed, otherwise PermissionNotAllowedException | ||
* will be thrown. | ||
* For example: | ||
* <pre> | ||
* @AuthorizedRoleHasPermission(Permissions.ACCOUNT_ENQUIRY_NOTES) | ||
* public NoteDto saveNote(NoteDto noteDto) { .. } | ||
* </pre> | ||
* The role can be inferred if one of the argument is of type NoteDto, the role will be picked by matching | ||
* businessUnitId of AddNoteDto argument within the userState roles. | ||
* If this role has the permission then only execution will be allowed, otherwise PermissionNotAllowedException | ||
* will be thrown. | ||
* For example: | ||
* <pre> | ||
* @AuthorizedRoleHasPermission(Permissions.ACCOUNT_ENQUIRY_NOTES) | ||
* public NoteDto saveNote(AddNoteDto addNoteDto) { .. } | ||
* </pre> | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface AuthorizedRoleHasPermission { | ||
Permissions value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/uk/gov/hmcts/opal/authorisation/aspect/RoleNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package uk.gov.hmcts.opal.authorisation.aspect; | ||
|
||
public class RoleNotFoundException extends RuntimeException { | ||
|
||
public RoleNotFoundException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.