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
28 changes: 28 additions & 0 deletions src/main/java/org/kohsuke/github/GHEnterpriseExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ GHEnterpriseExt wrapUp(GitHub root) {
}

public SCIMEMUUser createSCIMEMUUser(SCIMEMUUser newUser) throws IOException {
newUser.schemas = new String[]{SCIMConstants.SCIM_USER_SCHEMA};

String json = mapper.writeValueAsString(newUser);
byte[] jsonBytes = json.getBytes();

try (InputStream inputStream = new ByteArrayInputStream(jsonBytes)) {
SCIMEMUUser u = root.createRequest()
.method("POST")
.withHeader(SCIMConstants.HEADER_CONTENT_TYPE, SCIMConstants.SCIM_CONTENT_TYPE)
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.with(inputStream)
.withUrlPath(String.format("/scim/v2/enterprises/%s/Users", login))
.fetch(SCIMEMUUser.class);
Expand All @@ -40,6 +45,9 @@ public SCIMEMUUser updateSCIMEMUUser(String scimUserId, SCIMPatchOperations oper
try (InputStream inputStream = new ByteArrayInputStream(jsonBytes)) {
SCIMEMUUser u = root.createRequest()
.method("PATCH")
.withHeader(SCIMConstants.HEADER_CONTENT_TYPE, SCIMConstants.SCIM_CONTENT_TYPE)
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.with(inputStream)
.withUrlPath(String.format("/scim/v2/enterprises/%s/Users/%s", login, scimUserId))
.fetch(SCIMEMUUser.class);
Expand All @@ -49,13 +57,17 @@ public SCIMEMUUser updateSCIMEMUUser(String scimUserId, SCIMPatchOperations oper

public SCIMEMUUser getSCIMEMUUser(String scimUserId) throws IOException {
SCIMEMUUser u = root.createRequest()
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.withUrlPath(String.format("/scim/v2/enterprises/%s/Users/%s", login, scimUserId))
.fetch(SCIMEMUUser.class);
return u;
}

public SCIMEMUUser getSCIMEMUUserByUserName(String scimUserName) throws IOException {
SCIMEMUUser u = root.createRequest()
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.withUrlPath(String.format("/scim/v2/enterprises/%s/Users?filter=userName eq \"%s\"", login, scimUserName))
.fetch(SCIMEMUUser.class);
return u;
Expand All @@ -78,17 +90,24 @@ public SCIMPagedSearchIterable<SCIMEMUUser> listSCIMUsers(int pageSize, int page
public void deleteSCIMUser(String scimUserId) throws IOException {
root.createRequest()
.method("DELETE")
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.withUrlPath(String.format("/scim/v2/enterprises/%s/Users/%s", login, scimUserId))
.send();
}

public SCIMEMUGroup createSCIMEMUGroup(SCIMEMUGroup newGroup) throws IOException {
newGroup.schemas = new String[]{SCIMConstants.SCIM_GROUP_SCHEMA};

String json = mapper.writeValueAsString(newGroup);
byte[] jsonBytes = json.getBytes();

try (InputStream inputStream = new ByteArrayInputStream(jsonBytes)) {
SCIMEMUGroup g = root.createRequest()
.method("POST")
.withHeader(SCIMConstants.HEADER_CONTENT_TYPE, SCIMConstants.SCIM_CONTENT_TYPE)
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.with(inputStream)
.withUrlPath(String.format("/scim/v2/enterprises/%s/Groups", login))
.fetch(SCIMEMUGroup.class);
Expand All @@ -103,6 +122,9 @@ public SCIMEMUGroup updateSCIMEMUGroup(String scimGroupId, SCIMPatchOperations o
try (InputStream inputStream = new ByteArrayInputStream(jsonBytes)) {
SCIMEMUGroup g = root.createRequest()
.method("PATCH")
.withHeader(SCIMConstants.HEADER_CONTENT_TYPE, SCIMConstants.SCIM_CONTENT_TYPE)
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.with(inputStream)
.withUrlPath(String.format("/scim/v2/enterprises/%s/Groups/%s", login, scimGroupId))
.fetch(SCIMEMUGroup.class);
Expand All @@ -112,13 +134,17 @@ public SCIMEMUGroup updateSCIMEMUGroup(String scimGroupId, SCIMPatchOperations o

public SCIMEMUGroup getSCIMEMUGroup(String scimGroupId) throws IOException {
SCIMEMUGroup g = root.createRequest()
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.withUrlPath(String.format("/scim/v2/enterprises/%s/Groups/%s", login, scimGroupId))
.fetch(SCIMEMUGroup.class);
return g;
}

public SCIMEMUGroup getSCIMEMUGroupByDisplayName(String scimGroupDisplayName) throws IOException {
SCIMEMUGroup g = root.createRequest()
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.withUrlPath(String.format("/scim/v2/enterprises/%s/Groups?filter=displayName eq \"%s\"", login, scimGroupDisplayName))
.fetch(SCIMEMUGroup.class);
return g;
Expand All @@ -141,6 +167,8 @@ public SCIMPagedSearchIterable<SCIMEMUGroup> listSCIMGroups(int pageSize, int pa
public void deleteSCIMGroup(String scimGroupId) throws IOException {
root.createRequest()
.method("DELETE")
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.withUrlPath(String.format("/scim/v2/enterprises/%s/Groups/%s", login, scimGroupId))
.send();
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/kohsuke/github/GHOrganizationExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public SCIMUser createSCIMUser(SCIMUser newUser) throws IOException {

SCIMUser u = root.createRequest()
.method("POST")
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.GITHUB_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.with(map)
.withUrlPath(String.format("/scim/v2/organizations/%s/Users", login))
.fetch(SCIMUser.class);
Expand Down Expand Up @@ -81,6 +83,8 @@ public SCIMUser updateSCIMUser(String scimUserId, String scimUserName, String sc

SCIMUser u = root.createRequest()
.method("PATCH")
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.GITHUB_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.with(map)
.withUrlPath(String.format("/scim/v2/organizations/%s/Users/%s", login, scimUserId))
.fetch(SCIMUser.class);
Expand All @@ -89,13 +93,17 @@ public SCIMUser updateSCIMUser(String scimUserId, String scimUserName, String sc

public SCIMUser getSCIMUser(String scimUserId) throws IOException {
SCIMUser u = root.createRequest()
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.GITHUB_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.withUrlPath(String.format("/scim/v2/organizations/%s/Users/%s", login, scimUserId))
.fetch(SCIMUser.class);
return u;
}

public SCIMUser getSCIMUserByUserName(String scimUserName) throws IOException {
SCIMUser u = root.createRequest()
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.GITHUB_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.withUrlPath(String.format("/scim/v2/organizations/%s/Users?filter=userName eq \"%s\"", login, scimUserName))
.fetch(SCIMUser.class);
return u;
Expand Down Expand Up @@ -132,6 +140,8 @@ public GraphQLPagedSearchIterable<GraphQLOrganization, GraphQLExternalIdentityEd
public void deleteSCIMUser(String scimUserId) throws IOException {
root.createRequest()
.method("DELETE")
.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT)
.withHeader(SCIMConstants.GITHUB_API_VERSION, SCIMConstants.GITHUB_API_VERSION)
.withUrlPath(String.format("/scim/v2/organizations/%s/Users/%s", login, scimUserId))
.send();
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/kohsuke/github/SCIMConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.kohsuke.github;

/**
* Constants for SCIM API operations.
*
* @author Hiroyuki Wada
*/
public final class SCIMConstants {

public static final String SCIM_CONTENT_TYPE = "application/scim+json";
public static final String SCIM_ACCEPT = "application/scim+json";
public static final String GITHUB_API_VERSION = "2022-11-28";

public static final String HEADER_CONTENT_TYPE = "Content-Type";
public static final String HEADER_ACCEPT = "Accept";
public static final String HEADER_API_VERSION = "X-GitHub-Api-Version";

public static final String SCIM_USER_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:User";
public static final String SCIM_GROUP_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:Group";
}
3 changes: 3 additions & 0 deletions src/main/java/org/kohsuke/github/SCIMEMUGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

@JsonInclude(JsonInclude.Include.NON_NULL)
public class SCIMEMUGroup {
@JsonProperty("schemas")
public String[] schemas;

@JsonProperty("meta")
public SCIMMeta meta;

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/kohsuke/github/SCIMEMUUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

@JsonInclude(JsonInclude.Include.NON_NULL)
public class SCIMEMUUser {
@JsonProperty("schemas")
public String[] schemas;

@JsonProperty("meta")
public SCIMMeta meta;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/kohsuke/github/SCIMPatchOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class SCIMPatchOperations {
private static final String PATCH_OP = "urn:ietf:params:scim:api:messages:2.0:PatchOp";

@JsonProperty("schemas")
public List<String> schemas = Collections.singletonList(PATCH_OP);

@JsonProperty("Operations")
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/kohsuke/github/SCIMSearchBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public abstract class SCIMSearchBuilder<T> extends GHQueryBuilder<T> {
this.organization = org;
this.receiverType = receiverType;
req.withUrlPath(getApiUrl());
req.rateLimit(RateLimitTarget.SEARCH);
req.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT);
req.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION);
}

SCIMSearchBuilder(GitHub root, GHEnterpriseExt enterprise, Class<? extends SCIMSearchResult<T>> receiverType) {
Expand All @@ -32,7 +33,8 @@ public abstract class SCIMSearchBuilder<T> extends GHQueryBuilder<T> {
this.organization = null;
this.receiverType = receiverType;
req.withUrlPath(getApiUrl());
req.rateLimit(RateLimitTarget.SEARCH);
req.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT);
req.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION);
}

/**
Expand Down