-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add security identity suport on document push #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/com/coveo/pushapiclient/AnySecurityIdentityBuilder.java
This file contains hidden or 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,27 @@ | ||
| package com.coveo.pushapiclient; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public class AnySecurityIdentityBuilder implements SecurityIdentityBuilder { | ||
| private final String[] identities; | ||
| private final SecurityIdentityType securityIdentityType; | ||
| private final String securityProvider; | ||
|
|
||
| public AnySecurityIdentityBuilder(String identity, SecurityIdentityType securityIdentityType, String securityProvider) { | ||
| this.identities = new String[]{identity}; | ||
| this.securityIdentityType = securityIdentityType; | ||
| this.securityProvider = securityProvider; | ||
| } | ||
|
|
||
| public AnySecurityIdentityBuilder(String[] identities, SecurityIdentityType securityIdentityType, String securityProvider) { | ||
| this.identities = identities; | ||
| this.securityIdentityType = securityIdentityType; | ||
| this.securityProvider = securityProvider; | ||
| } | ||
|
|
||
| public SecurityIdentity[] build() { | ||
| return Arrays.stream(this.identities) | ||
| .map(identity -> new SecurityIdentity(identity, this.securityIdentityType, this.securityProvider)) | ||
| .toArray(SecurityIdentity[]::new); | ||
| } | ||
| } |
This file contains hidden or 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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/coveo/pushapiclient/GroupSecurityIdentityBuilder.java
This file contains hidden or 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,21 @@ | ||
| package com.coveo.pushapiclient; | ||
|
|
||
| public class GroupSecurityIdentityBuilder implements SecurityIdentityBuilder { | ||
| private final String[] identities; | ||
| private final String securityProvider; | ||
|
|
||
| public GroupSecurityIdentityBuilder(String identity, String securityProvider) { | ||
| this.identities = new String[]{identity}; | ||
| this.securityProvider = securityProvider; | ||
|
|
||
| } | ||
|
|
||
| public GroupSecurityIdentityBuilder(String[] identities, String securityProvider) { | ||
| this.identities = identities; | ||
| this.securityProvider = securityProvider; | ||
| } | ||
|
|
||
| public SecurityIdentity[] build() { | ||
| return new AnySecurityIdentityBuilder(this.identities, SecurityIdentityType.GROUP, this.securityProvider).build(); | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3,10 +3,10 @@ | |
| public class SecurityIdentity { | ||
| /** | ||
| * The name of the security identity. | ||
| * | ||
| * <p> | ||
| * Examples: | ||
| * - `[email protected]` | ||
| * - `SampleTeam2` | ||
| * - `[email protected]` | ||
| * - `SampleTeam2` | ||
| */ | ||
| public String identity; | ||
| /** | ||
|
|
@@ -20,8 +20,14 @@ public class SecurityIdentity { | |
| public SecurityIdentityType identityType; | ||
| /** | ||
| * The security identity provider through which the security identity is updated. | ||
| * | ||
| * <p> | ||
| * Defaults to the first security identity provider associated with the target Push source. | ||
| */ | ||
| public String securityProvider; | ||
|
|
||
| public SecurityIdentity(String identity, SecurityIdentityType securityIdentityType, String securityProvider) { | ||
| this.identity = identity; | ||
| this.identityType = securityIdentityType; | ||
| this.securityProvider = securityProvider; | ||
| } | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
src/main/java/com/coveo/pushapiclient/SecurityIdentityBuilder.java
This file contains hidden or 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,6 @@ | ||
| package com.coveo.pushapiclient; | ||
|
|
||
| public interface SecurityIdentityBuilder { | ||
| SecurityIdentity[] build(); | ||
| } | ||
|
|
32 changes: 32 additions & 0 deletions
32
src/main/java/com/coveo/pushapiclient/UserSecurityIdentityBuilder.java
This file contains hidden or 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,32 @@ | ||
| package com.coveo.pushapiclient; | ||
|
|
||
| public class UserSecurityIdentityBuilder implements SecurityIdentityBuilder { | ||
| private final String[] identities; | ||
| private final String securityProvider; | ||
|
|
||
| public UserSecurityIdentityBuilder(String identity, String securityProvider) { | ||
| this.identities = new String[]{identity}; | ||
| this.securityProvider = securityProvider; | ||
|
|
||
| } | ||
|
|
||
| public UserSecurityIdentityBuilder(String identity) { | ||
| this.identities = new String[]{identity}; | ||
| this.securityProvider = "Email Security Provider"; | ||
|
|
||
| } | ||
|
|
||
| public UserSecurityIdentityBuilder(String[] identities, String securityProvider) { | ||
| this.identities = identities; | ||
| this.securityProvider = securityProvider; | ||
| } | ||
|
|
||
| public UserSecurityIdentityBuilder(String[] identities) { | ||
| this.identities = identities; | ||
| this.securityProvider = "Email Security Provider"; | ||
| } | ||
|
|
||
| public SecurityIdentity[] build() { | ||
| return new AnySecurityIdentityBuilder(this.identities, SecurityIdentityType.USER, this.securityProvider).build(); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/coveo/pushapiclient/VirtualGroupSecurityIdentityBuilder.java
This file contains hidden or 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,22 @@ | ||
| package com.coveo.pushapiclient; | ||
|
|
||
| public class VirtualGroupSecurityIdentityBuilder implements SecurityIdentityBuilder { | ||
| private final String[] identities; | ||
| private final String securityProvider; | ||
|
|
||
| public VirtualGroupSecurityIdentityBuilder(String identity, String securityProvider) { | ||
| this.identities = new String[]{identity}; | ||
| this.securityProvider = securityProvider; | ||
|
|
||
| } | ||
|
|
||
| public VirtualGroupSecurityIdentityBuilder(String[] identities, String securityProvider) { | ||
| this.identities = identities; | ||
| this.securityProvider = securityProvider; | ||
| } | ||
|
|
||
| public SecurityIdentity[] build() { | ||
| return new AnySecurityIdentityBuilder(this.identities, SecurityIdentityType.VIRTUAL_GROUP, this.securityProvider).build(); | ||
| } | ||
| } | ||
|
|
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -27,19 +27,24 @@ public static void main(String[] args) { | |
| } | ||
|
|
||
| public static void testPushDocument(String sourceId, Source source) { | ||
| DocumentBuilder doc = new DocumentBuilder("https://perdu.com", "the title").withData("this is searchable").withDate(new Date()); | ||
| DocumentBuilder simpleDoc = new DocumentBuilder("https://perdu.com", "the title").withData("this is searchable").withDate(new Date()); | ||
| DocumentBuilder docWithMetadata = new DocumentBuilder("https://perdu.com/3", "the title 3").withMetadata(new HashMap<>() {{ | ||
| put("foo", "bar"); | ||
| put("my_field_1", "1"); | ||
| put("my_field_2", false); | ||
| put("my_field_3", 1234); | ||
| put("my_field_4", new String[]{"a", "b", "c"}); | ||
| }}); | ||
| System.out.println(doc.marshal()); | ||
| System.out.println(docWithMetadata.marshal()); | ||
| DocumentBuilder docWithSecurity = new DocumentBuilder("https://perdu.com/2", "the title 2") | ||
| .withData("this is searchable also") | ||
| .withAllowAnonymousUsers(false) | ||
| .withAllowedPermissions(new UserSecurityIdentityBuilder("[email protected]")) | ||
| .withDeniedPermissions(new UserSecurityIdentityBuilder(new String[]{"[email protected]", "[email protected]"})); | ||
|
|
||
| try { | ||
| source.addOrUpdateDocument(sourceId, doc); | ||
| source.addOrUpdateDocument(sourceId, simpleDoc); | ||
| source.addOrUpdateDocument(sourceId, docWithMetadata); | ||
| source.addOrUpdateDocument(sourceId, docWithSecurity); | ||
| } catch (IOException | InterruptedException e) { | ||
| System.out.println(e); | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the auto formatter from intellij: Just adds an explicit line break (paragraph) in the javadoc.