-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
b/325372861 Add client for Cloud Identity Groups API (#289)
The client isn't used yet, but will be needed in the future.
- Loading branch information
Showing
13 changed files
with
1,342 additions
and
11 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
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
71 changes: 71 additions & 0 deletions
71
sources/src/main/java/com/google/solutions/jitaccess/core/GroupEmail.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,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); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
sources/src/main/java/com/google/solutions/jitaccess/core/GroupId.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,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 | ||
} | ||
} |
Oops, something went wrong.