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 /** 031 * A class representing a permission-bind rule pair. There can be multiple 032 * of these in an ACI. 033 */ 034 public class PermBindRulePair { 035 036 /* 037 * The Bind Rule part. 038 */ 039 private BindRule bindRule; 040 041 /* 042 * The permission part. 043 */ 044 private Permission perm=null; 045 046 /** 047 * This constructor calls the permission and bind rule decodes 048 * with the appropriate strings. 049 * @param perm A string representing the permissions. 050 * @param rights A string representing the rights. 051 * @param bindRule A string representing the bind rule. 052 * @throws AciException If any of the strings fail to decode. 053 */ 054 private PermBindRulePair(String perm, String rights, String bindRule) 055 throws AciException { 056 this.perm=Permission.decode(perm, rights); 057 this.bindRule=BindRule.decode(bindRule); 058 } 059 060 /** 061 * Decodes a permission bind rule pair. 062 * @param perm A string representing the permissions. 063 * @param rights A string representing the rights. 064 * @param bRule A string representing the bind rule. 065 * @return An permission bind rule pair class representing this pair. 066 * @throws AciException If any of the strings fail to decode. 067 */ 068 public static PermBindRulePair decode(String perm, String rights, 069 String bRule) throws AciException { 070 return new PermBindRulePair(perm, rights, bRule); 071 } 072 073 /** 074 * Gets the bind rule part of this pair. 075 * @return The bind rule part of this pair. 076 */ 077 public BindRule getBindRule () { 078 return bindRule; 079 } 080 081 /** 082 * Checks the permission to see if it has this access type. 083 * @param accessType An enumeration of the desired access type. 084 * @return True if the access type equals the permission access type. 085 */ 086 public boolean hasAccessType(EnumAccessType accessType) { 087 return perm.hasAccessType(accessType); 088 } 089 090 /** 091 * Try and match one or more of the specified rights against a rights set 092 * of the permission class. 093 * @param right The rights to match. 094 * @return True if one or more of the specified rights match a right in 095 * the rights set of the permission class. 096 */ 097 public boolean hasRights(int right) { 098 return perm.hasRights(right); 099 } 100 }