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