|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). |
| 3 | + * |
| 4 | + * WSO2 LLC. licenses this file to you under the Apache License, |
| 5 | + * Version 2.0 (the "License"); you may not use this file except |
| 6 | + * in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, |
| 12 | + * software distributed under the License is distributed on an |
| 13 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | + * KIND, either express or implied. See the License for the |
| 15 | + * specific language governing permissions and limitations |
| 16 | + * under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.wso2.carbon.identity.authz.spicedb.handler.model; |
| 20 | + |
| 21 | +import com.google.gson.annotations.Expose; |
| 22 | +import com.google.gson.annotations.SerializedName; |
| 23 | +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 24 | +import org.wso2.carbon.identity.authorization.framework.model.SearchSubjectsRequest; |
| 25 | +import org.wso2.carbon.identity.authz.spicedb.constants.SpiceDbModelConstants; |
| 26 | + |
| 27 | +import java.util.Map; |
| 28 | + |
| 29 | +/** |
| 30 | + * The {@code LookupSubjectsRequest} class represents the request body of a lookup subjects request sent to SpiceDB. |
| 31 | + */ |
| 32 | +@SuppressFBWarnings(value = "URF_UNREAD_FIELD", |
| 33 | + justification = "All fields are accessed via Gson serialization") |
| 34 | +public class LookupSubjectsRequest { |
| 35 | + |
| 36 | + @SerializedName(SpiceDbModelConstants.SUBJECT_OBJECT_TYPE) |
| 37 | + @Expose |
| 38 | + private String subjectType; |
| 39 | + @SerializedName(SpiceDbModelConstants.PERMISSION) |
| 40 | + @Expose |
| 41 | + private String permission; |
| 42 | + @SerializedName(SpiceDbModelConstants.RESOURCE) |
| 43 | + @Expose |
| 44 | + private Resource resource; |
| 45 | + @SerializedName(SpiceDbModelConstants.CONTEXT) |
| 46 | + @Expose |
| 47 | + private Map<String, Object> context; |
| 48 | + @SerializedName(SpiceDbModelConstants.OPTIONAL_SUBJECT_RELATION) |
| 49 | + @Expose |
| 50 | + private String optionalSubjectRelation; |
| 51 | + @SerializedName(SpiceDbModelConstants.OPTIONAL_CONCRETE_LIMIT) |
| 52 | + @Expose |
| 53 | + private long optionalConcreteLimit; |
| 54 | + @SerializedName(SpiceDbModelConstants.OPTIONAL_CURSOR) |
| 55 | + @Expose |
| 56 | + private String optionalCursor; |
| 57 | + @SerializedName(SpiceDbModelConstants.WILD_CARD_OPTION) |
| 58 | + @Expose |
| 59 | + private String wildCardOption; |
| 60 | + |
| 61 | + public LookupSubjectsRequest(SearchSubjectsRequest searchSubjectsRequest) { |
| 62 | + |
| 63 | + if (searchSubjectsRequest.getResource() == null || |
| 64 | + searchSubjectsRequest.getAction() == null || |
| 65 | + searchSubjectsRequest.getSubject() == null) { |
| 66 | + throw new IllegalArgumentException("Invalid request. Resource, action, and subject with type " + |
| 67 | + "must be provided to lookup subjects."); |
| 68 | + } |
| 69 | + if (searchSubjectsRequest.getResource().getResourceId() == null) { |
| 70 | + throw new IllegalArgumentException("Invalid request. Resource id must be provided to lookup subjects."); |
| 71 | + } |
| 72 | + this.subjectType = searchSubjectsRequest.getSubject().getSubjectType(); |
| 73 | + this.permission = searchSubjectsRequest.getAction().getAction(); |
| 74 | + this.resource = new Resource(searchSubjectsRequest.getResource().getResourceType(), |
| 75 | + searchSubjectsRequest.getResource().getResourceId()); |
| 76 | + } |
| 77 | + |
| 78 | + public void setContext(Map<String, Object> context) { |
| 79 | + |
| 80 | + this.context = context; |
| 81 | + } |
| 82 | + |
| 83 | + public void setOptionalSubjectRelation (String optionalSubjectRelation) { |
| 84 | + |
| 85 | + this.optionalSubjectRelation = optionalSubjectRelation; |
| 86 | + } |
| 87 | + |
| 88 | + public void setOptionalConcreteLimit (Long optionalConcreteLimit) { |
| 89 | + |
| 90 | + this.optionalConcreteLimit = optionalConcreteLimit; |
| 91 | + } |
| 92 | + |
| 93 | + public void setOptionalCursor (String optionalCursor) { |
| 94 | + |
| 95 | + this.optionalCursor = optionalCursor; |
| 96 | + } |
| 97 | + |
| 98 | + public void setWildCardOption (String wildCardOption) { |
| 99 | + |
| 100 | + this.wildCardOption = wildCardOption; |
| 101 | + } |
| 102 | +} |
0 commit comments