Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
13 changes: 9 additions & 4 deletions src/main/java/com/coveo/pushapiclient/DocumentBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,18 @@ public DocumentBuilder withMetadata(Map<String, Object> metadata) {
return this;
}

public DocumentBuilder withAllowedPermissions() {
// TODO
public DocumentBuilder withAllowedPermissions(SecurityIdentityBuilder allowedPermissions) {
this.document.permissions[0].allowedPermissions = allowedPermissions.build();
return this;
}

public DocumentBuilder withDeniedPermissions() {
// TODO
public DocumentBuilder withDeniedPermissions(SecurityIdentityBuilder deniedPermissions) {
this.document.permissions[0].deniedPermissions = deniedPermissions.build();
return this;
}

public DocumentBuilder withAllowAnonymousUsers(Boolean allowAnonymous) {
this.document.permissions[0].allowAnonymous = allowAnonymous;
return this;
}

Expand Down
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();
}
}
14 changes: 10 additions & 4 deletions src/main/java/com/coveo/pushapiclient/SecurityIdentity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
public class SecurityIdentity {
/**
* The name of the security identity.
*
* <p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Member Author

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.

* Examples:
* - `[email protected]`
* - `SampleTeam2`
* - `[email protected]`
* - `SampleTeam2`
*/
public String identity;
/**
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.coveo.pushapiclient;

public interface SecurityIdentityBuilder {
SecurityIdentity[] build();
}

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();
}
}
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();
}
}

13 changes: 9 additions & 4 deletions src/main/java/com/coveo/testlocally/TestingLocally.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down