use of io.kubernetes.client.models.V1SubjectAccessReview in project weblogic-kubernetes-operator by oracle.
the class AuthorizationProxy method prepareSubjectAccessReview.
/**
* Prepares an instance of SubjectAccessReview and returns same.
*
* @param principal The user, group or service account.
* @param groups The groups that principal is a member of.
* @param operation The operation to be authorized.
* @param resource The kind of resource on which the operation is to be authorized.
* @param resourceName The name of the resource instance on which the operation is to be authorized.
* @param scope The scope of the operation (cluster or namespace).
* @param namespaceName name of the namespace if scope is namespace else null.
* @return an instance of SubjectAccessReview.
*/
private V1SubjectAccessReview prepareSubjectAccessReview(String principal, final List<String> groups, Operation operation, Resource resource, String resourceName, Scope scope, String namespaceName) {
LOGGER.entering();
V1SubjectAccessReviewSpec subjectAccessReviewSpec = new V1SubjectAccessReviewSpec();
subjectAccessReviewSpec.setUser(principal);
subjectAccessReviewSpec.setGroups(groups);
subjectAccessReviewSpec.setResourceAttributes(prepareResourceAttributes(operation, resource, resourceName, scope, namespaceName));
V1SubjectAccessReview subjectAccessReview = new V1SubjectAccessReview();
subjectAccessReview.setApiVersion("authorization.k8s.io/v1");
subjectAccessReview.setKind("SubjectAccessReview");
subjectAccessReview.setMetadata(new V1ObjectMeta());
subjectAccessReview.setSpec(subjectAccessReviewSpec);
LOGGER.exiting(subjectAccessReview);
return subjectAccessReview;
}
use of io.kubernetes.client.models.V1SubjectAccessReview in project java by kubernetes-client.
the class AuthorizationV1Api method createSubjectAccessReviewWithHttpInfo.
/**
* create a SubjectAccessReview
* @param body (required)
* @param pretty If 'true', then the output is pretty printed. (optional)
* @return ApiResponse<V1SubjectAccessReview>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse<V1SubjectAccessReview> createSubjectAccessReviewWithHttpInfo(V1SubjectAccessReview body, String pretty) throws ApiException {
com.squareup.okhttp.Call call = createSubjectAccessReviewValidateBeforeCall(body, pretty, null, null);
Type localVarReturnType = new TypeToken<V1SubjectAccessReview>() {
}.getType();
return apiClient.execute(call, localVarReturnType);
}
use of io.kubernetes.client.models.V1SubjectAccessReview in project java by kubernetes-client.
the class AuthorizationV1Api method createSubjectAccessReviewAsync.
/**
* (asynchronously)
* create a SubjectAccessReview
* @param body (required)
* @param pretty If 'true', then the output is pretty printed. (optional)
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
*/
public com.squareup.okhttp.Call createSubjectAccessReviewAsync(V1SubjectAccessReview body, String pretty, final ApiCallback<V1SubjectAccessReview> callback) throws ApiException {
ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}
com.squareup.okhttp.Call call = createSubjectAccessReviewValidateBeforeCall(body, pretty, progressListener, progressRequestListener);
Type localVarReturnType = new TypeToken<V1SubjectAccessReview>() {
}.getType();
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
}
use of io.kubernetes.client.models.V1SubjectAccessReview in project java by kubernetes-client.
the class AuthorizationV1ApiTest method createSubjectAccessReviewTest.
/**
* create a SubjectAccessReview
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void createSubjectAccessReviewTest() throws ApiException {
V1SubjectAccessReview body = null;
String pretty = null;
V1SubjectAccessReview response = api.createSubjectAccessReview(body, pretty);
// TODO: test validations
}
use of io.kubernetes.client.models.V1SubjectAccessReview in project weblogic-kubernetes-operator by oracle.
the class AuthorizationProxy method check.
/**
* Check if the specified principal is allowed to perform the specified operation on the
* specified resource in the specified scope.
*
* @param principal The user, group or service account.
* @param groups The groups that principal is a member of.
* @param operation The operation to be authorized.
* @param resource The kind of resource on which the operation is to be authorized.
* @param resourceName The name of the resource instance on which the operation is to be authorized.
* @param scope The scope of the operation (cluster or namespace).
* @param namespaceName name of the namespace if scope is namespace else null.
* @return true if the operation is allowed, or false if not.
*/
public boolean check(String principal, final List<String> groups, Operation operation, Resource resource, String resourceName, Scope scope, String namespaceName) {
LOGGER.entering();
V1SubjectAccessReview subjectAccessReview = prepareSubjectAccessReview(principal, groups, operation, resource, resourceName, scope, namespaceName);
try {
CallBuilderFactory factory = ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
subjectAccessReview = factory.create().createSubjectAccessReview(subjectAccessReview);
} catch (ApiException e) {
LOGGER.severe(MessageKeys.APIEXCEPTION_FROM_SUBJECT_ACCESS_REVIEW, e);
LOGGER.exiting(Boolean.FALSE);
return Boolean.FALSE;
}
V1SubjectAccessReviewStatus subjectAccessReviewStatus = subjectAccessReview.getStatus();
Boolean result = subjectAccessReviewStatus.isAllowed();
LOGGER.exiting(result);
return result;
}
Aggregations