-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from patelhumaira21/custom_error
Customizing the error message
- Loading branch information
Showing
6 changed files
with
44 additions
and
7 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
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/intuit/graphql/authorization/enforcement/RedactionContext.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,13 @@ | ||
package com.intuit.graphql.authorization.enforcement; | ||
|
||
import graphql.language.Field; | ||
import graphql.schema.FieldCoordinates; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
public class RedactionContext { | ||
Field field; | ||
FieldCoordinates fieldCoordinates; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/intuit/graphql/authorization/util/ScopeProvider.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 |
---|---|---|
@@ -1,13 +1,22 @@ | ||
package com.intuit.graphql.authorization.util; | ||
|
||
import com.intuit.graphql.authorization.enforcement.RedactionContext; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public interface ScopeProvider { | ||
|
||
String DEFAULT_ERROR_MESSAGE = "403 - Not authorized to access field=%s of type=%s"; | ||
|
||
// This method needs to return a set of strings if the scopes are passed and an empty set if not passed | ||
default Set<String> getScopes(Object o) { | ||
return new HashSet<>(); | ||
} | ||
|
||
default String getErrorMessage(RedactionContext redactionContext) { | ||
return String.format(DEFAULT_ERROR_MESSAGE, | ||
redactionContext.getField().getName(), redactionContext.getFieldCoordinates().getTypeName()); | ||
} | ||
|
||
} |
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