001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 * Portions Copyright 2013-2016 ForgeRock AS. 016 */ 017package org.opends.server.authorization.dseecompat; 018 019import static org.opends.messages.AccessControlMessages.*; 020 021import java.util.Set; 022 023/** This class represents an ACI's extop keyword rule. */ 024public class ExtOp { 025 /** Set of OID strings parsed from the decode. */ 026 private final Set<String> extOpOIDs; 027 /** Enumeration representing the extop operator. */ 028 private final EnumTargetOperator op; 029 030 /** 031 * Creates a class that can be used to evaluate a extop rule. 032 * 033 * @param op The operator of the extop expression (=, !=). 034 * @param extOpOIDs Set of extended operation OIDS to use in the evaluation 035 * (wild-card '*' allowed). 036 */ 037 private ExtOp(EnumTargetOperator op, Set<String> extOpOIDs) 038 { 039 this.extOpOIDs=extOpOIDs; 040 this.op=op; 041 } 042 043 /** 044 * Decode an extop expression string. 045 * 046 * @param operator An enumeration representing the operator type. 047 * @param expr A string representing the extop expression. 048 * @return A class representing the extop expression that can be 049 * used to evaluate an ACI. 050 * 051 * @throws AciException If the specified expression string is invalid. 052 */ 053 public static ExtOp decode(EnumTargetOperator operator, String expr) 054 throws AciException { 055 Set<String> extOpOIDs = Aci.decodeOID(expr, 056 WARN_ACI_SYNTAX_INVALID_TARGEXTOP_EXPRESSION.get(expr)); 057 return new ExtOp(operator, extOpOIDs); 058 } 059 060 /** 061 * Check if a extop is applicable based on the provided target match 062 * context. 063 * 064 * @param matchCtx The target match context to use in the check. 065 * @return True if the extop is applicable based on the context. 066 */ 067 public boolean isApplicable(AciTargetMatchContext matchCtx) { 068 if(matchCtx.getExtOpOID() == null) 069 { 070 return false; 071 } 072 boolean ret = isApplicable(matchCtx.getExtOpOID()); 073 if (EnumTargetOperator.NOT_EQUALITY.equals(op)) 074 { 075 return !ret; 076 } 077 return ret; 078 } 079 080 private boolean isApplicable(String matchOID) 081 { 082 for(String oid : extOpOIDs) 083 { 084 if ("*".equals(oid) || matchOID.equals(oid)) 085 { 086 return true; 087 } 088 } 089 return false; 090 } 091}