-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support API V2 : Get / Create / Delete Permission targets
- Loading branch information
Showing
19 changed files
with
773 additions
and
0 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
15 changes: 15 additions & 0 deletions
15
api/src/main/java/org/jfrog/artifactory/client/model/Actions.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,15 @@ | ||
package org.jfrog.artifactory.client.model; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public interface Actions { | ||
Map<String, Set<PrivilegeV2>> getUsers(); | ||
Map<String, Set<PrivilegeV2>> getGroups(); | ||
|
||
boolean isUserAllowedTo(String user, PrivilegeV2 privilege); | ||
boolean isGroupAllowedTo(String group, PrivilegeV2 privilege); | ||
@Override | ||
boolean equals(Object o); | ||
} |
13 changes: 13 additions & 0 deletions
13
api/src/main/java/org/jfrog/artifactory/client/model/PermissionTargetV2.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 org.jfrog.artifactory.client.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public interface PermissionTargetV2 { | ||
String getName(); | ||
PermissionV2 getRepo(); | ||
PermissionV2 getBuild(); | ||
PermissionV2 getReleaseBundle(); | ||
@Override | ||
boolean equals(Object o); | ||
} |
15 changes: 15 additions & 0 deletions
15
api/src/main/java/org/jfrog/artifactory/client/model/PermissionV2.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,15 @@ | ||
package org.jfrog.artifactory.client.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public interface PermissionV2 { | ||
List<String> getIncludePatterns(); | ||
List<String> getExcludePatterns(); | ||
List<String> getRepositories(); | ||
Actions getActions(); | ||
@Override | ||
boolean equals(Object o); | ||
} |
27 changes: 27 additions & 0 deletions
27
api/src/main/java/org/jfrog/artifactory/client/model/PrivilegeV2.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,27 @@ | ||
package org.jfrog.artifactory.client.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
public enum PrivilegeV2 { | ||
READ("read"),WRITE("write"),ANNOTATE("annotate"),DELETE("delete"),MANAGE("manage"),MANAGED_XRAY_META("managedXrayMeta"),DISTRIBUTE("distribute"); | ||
|
||
@JsonValue | ||
private String privilege; | ||
|
||
PrivilegeV2(String privilege) { | ||
this.privilege = privilege; | ||
} | ||
|
||
public String getPrivilege() { | ||
return privilege; | ||
} | ||
|
||
public static PrivilegeV2 fromPrivilege(String privilege){ | ||
for (PrivilegeV2 privilegeV2 : values()) { | ||
if (privilegeV2.privilege.equals(privilege)) { | ||
return privilegeV2; | ||
} | ||
} | ||
throw new IllegalArgumentException("No Privilege for "+privilege+" found."); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
api/src/main/java/org/jfrog/artifactory/client/model/builder/ActionsBuilder.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 org.jfrog.artifactory.client.model.builder; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import org.jfrog.artifactory.client.model.Actions; | ||
import org.jfrog.artifactory.client.model.PrivilegeV2; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public interface ActionsBuilder { | ||
|
||
ActionsBuilder addUser(String user, PrivilegeV2... privileges); | ||
ActionsBuilder addGroup(String group, PrivilegeV2... privileges); | ||
Actions build(); | ||
} |
16 changes: 16 additions & 0 deletions
16
api/src/main/java/org/jfrog/artifactory/client/model/builder/PermissionTargetV2Builder.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 org.jfrog.artifactory.client.model.builder; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import org.jfrog.artifactory.client.model.PermissionTargetV2; | ||
import org.jfrog.artifactory.client.model.PermissionV2; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public interface PermissionTargetV2Builder { | ||
|
||
PermissionTargetV2Builder name(String name); | ||
PermissionTargetV2Builder repo(PermissionV2 repo); | ||
PermissionTargetV2Builder build(PermissionV2 build); | ||
PermissionTargetV2Builder releaseBundle(PermissionV2 releaseBundle); | ||
PermissionTargetV2 build(); | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
api/src/main/java/org/jfrog/artifactory/client/model/builder/PermissionV2Builder.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,15 @@ | ||
package org.jfrog.artifactory.client.model.builder; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import org.jfrog.artifactory.client.model.Actions; | ||
import org.jfrog.artifactory.client.model.PermissionV2; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public interface PermissionV2Builder { | ||
|
||
PermissionV2Builder includePatterns(String... includePatterns); | ||
PermissionV2Builder excludePatterns(String... excludePatterns); | ||
PermissionV2Builder repositories(String... repositories); | ||
PermissionV2Builder actions(Actions actions); | ||
PermissionV2 build(); | ||
} |
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
35 changes: 35 additions & 0 deletions
35
services/src/main/java/org/jfrog/artifactory/client/model/impl/ActionsBuilderImpl.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,35 @@ | ||
package org.jfrog.artifactory.client.model.impl; | ||
|
||
import org.jfrog.artifactory.client.model.Actions; | ||
import org.jfrog.artifactory.client.model.PrivilegeV2; | ||
import org.jfrog.artifactory.client.model.builder.ActionsBuilder; | ||
|
||
import java.util.*; | ||
|
||
public class ActionsBuilderImpl implements ActionsBuilder { | ||
private Map<String, Set<PrivilegeV2>> usersGrantedActions; | ||
private Map<String, Set<PrivilegeV2>> groupsGrantedActions; | ||
|
||
public ActionsBuilderImpl() { | ||
this.usersGrantedActions= new HashMap<>(); | ||
this.groupsGrantedActions = new HashMap<>(); | ||
} | ||
@Override | ||
public ActionsBuilder addUser(String user, PrivilegeV2... privileges) { | ||
Set<PrivilegeV2> userPrivileges = new HashSet<>(Arrays.asList(privileges)); | ||
usersGrantedActions.put(user, userPrivileges); | ||
return this; | ||
} | ||
|
||
@Override | ||
public ActionsBuilder addGroup(String group, PrivilegeV2... privileges) { | ||
Set<PrivilegeV2> groupPrivileges = new HashSet<>(Arrays.asList(privileges)); | ||
groupsGrantedActions.put(group, groupPrivileges); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Actions build() { | ||
return new ActionsImpl(usersGrantedActions, groupsGrantedActions); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
services/src/main/java/org/jfrog/artifactory/client/model/impl/ActionsImpl.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,76 @@ | ||
package org.jfrog.artifactory.client.model.impl; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.jfrog.artifactory.client.model.Actions; | ||
import org.jfrog.artifactory.client.model.PrivilegeV2; | ||
|
||
import java.util.*; | ||
|
||
public class ActionsImpl implements Actions { | ||
|
||
private Map<String, Set<PrivilegeV2>> users; | ||
|
||
private Map<String, Set<PrivilegeV2>> groups; | ||
|
||
public ActionsImpl() { | ||
super(); | ||
this.users=new HashMap<>(); | ||
this.groups=new HashMap<>(); | ||
} | ||
|
||
public ActionsImpl(Map<String, Set<PrivilegeV2>> users, Map<String, Set<PrivilegeV2>> groups) { | ||
this.users = Optional.ofNullable(users).orElse(Collections.emptyMap()); | ||
this.groups = Optional.ofNullable(groups).orElse(Collections.emptyMap()); | ||
} | ||
|
||
@Override | ||
public boolean isUserAllowedTo(String user, PrivilegeV2 privilege) { | ||
if(StringUtils.isBlank(user) || privilege == null) { | ||
return false; | ||
} | ||
return users.containsKey(user) && users.get(user).contains(privilege); | ||
} | ||
|
||
@Override | ||
public boolean isGroupAllowedTo(String group, PrivilegeV2 privilege) { | ||
if(StringUtils.isBlank(group) || privilege == null) { | ||
return false; | ||
} | ||
return groups.containsKey(group) && groups.get(group).contains(privilege); | ||
} | ||
|
||
@Override | ||
public Map<String, Set<PrivilegeV2>> getUsers() { | ||
return users; | ||
} | ||
|
||
@Override | ||
public Map<String, Set<PrivilegeV2>> getGroups() { | ||
return groups; | ||
} | ||
|
||
public void setUsers(Map<String, Set<PrivilegeV2>> users) { | ||
this.users = users; | ||
} | ||
|
||
public void setGroups(Map<String, Set<PrivilegeV2>> groups) { | ||
this.groups = groups; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if(!(obj instanceof Actions)) { | ||
return false; | ||
} | ||
Actions other = (Actions) obj; | ||
boolean areEquals = (users==null && other.getUsers()==null) || | ||
(users==null && other.getUsers().isEmpty()) || | ||
(users.isEmpty() && other.getUsers()==null) || | ||
(users!=null && users.equals(other.getUsers())); | ||
areEquals &= (groups==null && other.getGroups()==null) || | ||
(groups==null && other.getGroups().isEmpty()) || | ||
(groups.isEmpty() && other.getGroups()==null) || | ||
(groups!=null && groups.equals(other.getGroups())); | ||
return areEquals; | ||
} | ||
} |
Oops, something went wrong.