-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
845 additions
and
41 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
91 changes: 91 additions & 0 deletions
91
clients/client-java/src/main/java/org/apache/gravitino/client/GenericRole.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,91 @@ | ||
/* | ||
* 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 org.apache.gravitino.client; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
import org.apache.gravitino.Audit; | ||
import org.apache.gravitino.authorization.Role; | ||
import org.apache.gravitino.authorization.SecurableObject; | ||
import org.apache.gravitino.dto.authorization.RoleDTO; | ||
|
||
/** Represents a generic role. This class is used for lazily requesting securable objects. */ | ||
class GenericRole implements Role { | ||
|
||
private final RoleDTO roleDTO; | ||
private final Supplier<List<SecurableObject>> securableObjectsSupplier; | ||
|
||
GenericRole(RoleDTO roleDTO, GravitinoMetalake gravitinoMetalake) { | ||
this.roleDTO = roleDTO; | ||
this.securableObjectsSupplier = | ||
new Supplier<List<SecurableObject>>() { | ||
private boolean waitToRequest = true; | ||
private List<SecurableObject> securableObjects; | ||
|
||
@Override | ||
public List<SecurableObject> get() { | ||
if (waitToRequest) { | ||
securableObjects = gravitinoMetalake.getRole(roleDTO.name()).securableObjects(); | ||
waitToRequest = false; | ||
} | ||
|
||
return securableObjects; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Audit auditInfo() { | ||
return roleDTO.auditInfo(); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return roleDTO.name(); | ||
} | ||
|
||
@Override | ||
public Map<String, String> properties() { | ||
return roleDTO.properties(); | ||
} | ||
|
||
@Override | ||
public List<SecurableObject> securableObjects() { | ||
return securableObjectsSupplier.get(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (!(obj instanceof GenericRole)) { | ||
return false; | ||
} | ||
|
||
GenericRole that = (GenericRole) obj; | ||
return roleDTO.equals(that.roleDTO); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return roleDTO.hashCode(); | ||
} | ||
} |
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
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
Oops, something went wrong.