Skip to content

Commit

Permalink
refactor(auth): models for RbacRaw access
Browse files Browse the repository at this point in the history
  • Loading branch information
vkrizan committed Jul 21, 2023
1 parent 1248e1a commit 4a8df1b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2023 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed 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.redhat.cloud.policies.app.auth.models;

import java.util.List;

public class Access {

public String permission;
public List<ResourceDefinition> resourceDefinitions;

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class RbacRaw {

public Map<String, String> links;
public Map<String, Integer> meta;
public List<Map<String, Object>> data;
public List<Access> data;

public boolean canRead(String path) {
return findPermission(path, "read");
Expand Down Expand Up @@ -53,7 +53,7 @@ private boolean findPermission(String path, String what) {
return false;
}

for (Map<String, Object> permissionEntry : data) {
for (Access permissionEntry : data) {
String[] fields = getPermissionFields(permissionEntry);
if (fields[1].equals(path) || fields[1].equals(ANY)) {
if (fields[2].equals(what) || fields[2].equals(ANY)) {
Expand All @@ -64,8 +64,7 @@ private boolean findPermission(String path, String what) {
return false;
}

private String[] getPermissionFields(Map<String, Object> map) {
String perms = (String) map.get("permission");
return perms.split(":");
private String[] getPermissionFields(Access map) {
return map.permission.split(":");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2023 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed 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.redhat.cloud.policies.app.auth.models;

public class ResourceDefinition {
public ResourceDefinitionFilter attributeFilter;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2023 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed 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.redhat.cloud.policies.app.auth.models;

import java.util.List;

public class ResourceDefinitionFilter {
public String key;
public String operation;
public Object value;
}

0 comments on commit 4a8df1b

Please sign in to comment.