-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/add-task-ownership-handling (#10)
- Loading branch information
1 parent
bdc5b51
commit 755e469
Showing
5 changed files
with
69 additions
and
6 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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/behl/flare/exception/TaskOwnershipViolationException.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,16 @@ | ||
package com.behl.flare.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
public class TaskOwnershipViolationException extends ResponseStatusException { | ||
|
||
private static final long serialVersionUID = 3265020831437403636L; | ||
|
||
private static final String DEFAULT_MESSAGE = "Access Denied: insufficient privileges to perform this action."; | ||
|
||
public TaskOwnershipViolationException() { | ||
super(HttpStatus.FORBIDDEN, DEFAULT_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
20 changes: 20 additions & 0 deletions
20
src/main/java/com/behl/flare/utility/AuthenticatedUserIdProvider.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,20 @@ | ||
package com.behl.flare.utility; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class AuthenticatedUserIdProvider { | ||
|
||
public String getUserId() { | ||
return Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication()) | ||
.map(Authentication::getPrincipal) | ||
.filter(String.class::isInstance) | ||
.map(String.class::cast) | ||
.orElseThrow(IllegalStateException::new); | ||
} | ||
|
||
} |