Skip to content

Commit

Permalink
b/325372861 Add client for Cloud Identity Groups API (#289)
Browse files Browse the repository at this point in the history
The client isn't used yet, but will be needed in the future.
  • Loading branch information
jpassing authored Feb 26, 2024
1 parent e25dc70 commit edbb831
Show file tree
Hide file tree
Showing 13 changed files with 1,342 additions and 11 deletions.
6 changes: 6 additions & 0 deletions sources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
<artifactId>google-api-services-admin-directory</artifactId>
<version>directory_v1-rev20240220-2.0.0</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-cloudidentity</artifactId>
<version>v1-rev20240206-2.0.0</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
package com.google.solutions.jitaccess.core;

public abstract class AccessException extends Exception {
public AccessException(String message) {
super(message);
}

public AccessException(String message, Exception inner) {
super(message, inner);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// Copyright 2024 Google LLC
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

package com.google.solutions.jitaccess.core;

import com.google.common.base.Preconditions;

import java.util.Objects;

/**
* Email address of a group.
*/
public class GroupEmail implements Comparable<GroupEmail> {
public final String email;

public GroupEmail(String email) {
Preconditions.checkNotNull(email, "email");
this.email = email;
}

@Override
public String toString() {
return this.email;
}

// -------------------------------------------------------------------------
// Equality.
// -------------------------------------------------------------------------

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
return false;
}

GroupEmail GroupEmail = (GroupEmail) o;
return email.equals(GroupEmail.email);
}

@Override
public int hashCode() {
return Objects.hash(email);
}

@Override
public int compareTo(GroupEmail o) {
return this.email.compareTo(o.email);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// Copyright 2024 Google LLC
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

package com.google.solutions.jitaccess.core;

import com.google.common.base.Preconditions;

import java.util.Objects;

/**
* Primary email address and unique ID of a group.
*/
public class GroupId extends UserEmail {
private static final String GROUPS_PREFIX = "groups/";

public final transient String id;

public GroupId(String id, String email) {
super(email);

Preconditions.checkNotNull(id, "id");

if (id.startsWith(GROUPS_PREFIX)) {
id = id.substring(GROUPS_PREFIX.length());
}

this.id = id;
}

public GroupId(String id, GroupEmail email) {
this(id, email.email);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
return false;
}

if (!super.equals(o)) {
return false;
}

GroupId GroupId = (GroupId) o;
return this.id.equals(GroupId.id);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), id);
}

/**
* @return ID in groups/ID format.
*/
@Override
public String toString() {
return String.format("%s%s", GROUPS_PREFIX, this.id); //TODO: test
}
}
Loading

0 comments on commit edbb831

Please sign in to comment.