-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support attributes in
AuthZResource
(#1656)
Include attributes in the authorization request payload so PDP can implement Attribute-based access control for more complex authorization logic. The first usage is the BUILD resource type. In Rodimus we will use this change to indicate if the authorization request is for a SOX environment.
- Loading branch information
1 parent
c9ed0fb
commit 33288ad
Showing
15 changed files
with
365 additions
and
65 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
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
58 changes: 58 additions & 0 deletions
58
...rc/main/java/com/pinterest/teletraan/universal/security/AuthZResourceAttributesUtils.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,58 @@ | ||
/** | ||
* Copyright (c) 2024 Pinterest, Inc. | ||
* | ||
* 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.pinterest.teletraan.universal.security; | ||
|
||
import com.pinterest.teletraan.universal.security.bean.AuthZResource; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import javax.ws.rs.container.ContainerRequestContext; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE) | ||
public class AuthZResourceAttributesUtils { | ||
@SuppressWarnings("unchecked") | ||
public static Map<String, String> insertAuthZResourceAttributes( | ||
ContainerRequestContext requestContext, AuthZResource.AttributeKeys key, String value) { | ||
if (requestContext == null) { | ||
return new HashMap<>(); | ||
} | ||
|
||
Object attributes = requestContext.getProperty(Constants.AUTHZ_ATTR_REQ_CXT_KEY); | ||
Map<String, String> attributesMap; | ||
if (attributes instanceof Map<?, ?>) { | ||
attributesMap = (Map<String, String>) attributes; | ||
attributesMap.put(key.name(), value); | ||
} else { | ||
attributesMap = new HashMap<>(); | ||
attributesMap.put(key.name(), value); | ||
requestContext.setProperty(Constants.AUTHZ_ATTR_REQ_CXT_KEY, attributesMap); | ||
} | ||
return attributesMap; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static Map<String, String> getAuthZResourceAttributes( | ||
ContainerRequestContext requestContext) { | ||
if (requestContext == null) { | ||
return new HashMap<>(); | ||
} | ||
Object attributes = requestContext.getProperty(Constants.AUTHZ_ATTR_REQ_CXT_KEY); | ||
if (attributes instanceof Map<?, ?>) { | ||
return (Map<String, String>) attributes; | ||
} | ||
return new HashMap<>(); | ||
} | ||
} |
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.