-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide interface for external validation checks before adding princi…
…pals to roles and groups Signed-off-by: Henry Avetisyan <[email protected]>
- Loading branch information
1 parent
167965a
commit 937911e
Showing
11 changed files
with
555 additions
and
92 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...a/server_common/src/main/java/com/yahoo/athenz/common/server/store/ResourceValidator.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,41 @@ | ||
/* | ||
* Copyright The Athenz Authors | ||
* | ||
* 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.yahoo.athenz.common.server.store; | ||
|
||
/** | ||
* External validator for resources managed by Athenz | ||
*/ | ||
public interface ResourceValidator { | ||
|
||
/** | ||
* Validate the member for the given role and/or group | ||
* @param domainName domain name | ||
* @param roleName role name | ||
* @param memberName member name | ||
* @return true if the member is valid, false otherwise | ||
*/ | ||
boolean validateRoleMember(String domainName, String roleName, String memberName); | ||
|
||
/** | ||
* Validate the member for the given group | ||
* @param domainName domain name | ||
* @param groupName group name | ||
* @param memberName member name | ||
* @return true if the member is valid, false otherwise | ||
*/ | ||
boolean validateGroupMember(String domainName, String groupName, String memberName); | ||
} |
29 changes: 29 additions & 0 deletions
29
...r_common/src/main/java/com/yahoo/athenz/common/server/store/ResourceValidatorFactory.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,29 @@ | ||
/* | ||
* Copyright The Athenz Authors | ||
* | ||
* 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.yahoo.athenz.common.server.store; | ||
|
||
import com.yahoo.athenz.common.server.ServerResourceException; | ||
|
||
public interface ResourceValidatorFactory { | ||
|
||
/** | ||
* Create a resource validator instance | ||
* @return ResourceValidator instance | ||
* @throws ServerResourceException in case of any errors | ||
*/ | ||
ResourceValidator create() throws ServerResourceException; | ||
} |
36 changes: 36 additions & 0 deletions
36
...common/src/main/java/com/yahoo/athenz/common/server/store/impl/NoOpResourceValidator.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,36 @@ | ||
/* | ||
* Copyright The Athenz Authors | ||
* | ||
* 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.yahoo.athenz.common.server.store.impl; | ||
|
||
import com.yahoo.athenz.common.server.store.ResourceValidator; | ||
|
||
/** | ||
* NoOpResourceValidator is a no-op implementation of the ResourceValidator interface. | ||
* It returns true for all validation requests. | ||
*/ | ||
public class NoOpResourceValidator implements ResourceValidator { | ||
|
||
@Override | ||
public boolean validateRoleMember(String domainName, String roleName, String memberName) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean validateGroupMember(String domainName, String groupName, String memberName) { | ||
return true; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...src/main/java/com/yahoo/athenz/common/server/store/impl/NoOpResourceValidatorFactory.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,32 @@ | ||
/* | ||
* Copyright The Athenz Authors | ||
* | ||
* 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.yahoo.athenz.common.server.store.impl; | ||
|
||
import com.yahoo.athenz.common.server.store.ResourceValidator; | ||
import com.yahoo.athenz.common.server.store.ResourceValidatorFactory; | ||
|
||
/** | ||
* NoOpResourceValidatorFactory is a no-op implementation of the ResourceValidatorFactory interface. | ||
* It creates a NoOpResourceValidator that returns true for all validation requests. | ||
*/ | ||
public class NoOpResourceValidatorFactory implements ResourceValidatorFactory { | ||
|
||
@Override | ||
public ResourceValidator create() { | ||
return new NoOpResourceValidator(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...test/java/com/yahoo/athenz/common/server/store/impl/NoOpResourceValidatorFactoryTest.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,37 @@ | ||
/* | ||
* Copyright The Athenz Authors | ||
* | ||
* 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.yahoo.athenz.common.server.store.impl; | ||
|
||
import com.yahoo.athenz.common.server.store.ResourceValidator; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.assertNotNull; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
public class NoOpResourceValidatorFactoryTest { | ||
|
||
@Test | ||
public void testCreate() { | ||
NoOpResourceValidatorFactory factory = new NoOpResourceValidatorFactory(); | ||
ResourceValidator validator = factory.create(); | ||
assertNotNull(validator); | ||
|
||
// validate some members - we should always return true | ||
|
||
assertTrue(validator.validateRoleMember("domain", "role", "user")); | ||
assertTrue(validator.validateGroupMember("domain", "group", "user")); | ||
} | ||
} |
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.