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 2015 ForgeRock AS.
016 */
017
018package org.opends.server.authorization.dseecompat;
019
020/**
021 *  This class provides an enumeration of the valid ACI target keywords.
022 */
023public enum EnumTargetKeyword {
024
025    /**
026     * This enumeration is returned when the target keyword is
027     * "target".
028     */
029    KEYWORD_TARGET      ("target"),
030    /**
031     * This enumeration is returned when the target keyword is
032     * "targetattr".
033     */
034    KEYWORD_TARGETATTR  ("targetattr"),
035    /**
036     * This enumeration is returned when the target keyword  is
037     * "targetscope".
038     */
039    KEYWORD_TARGETSCOPE ("targetscope"),
040    /**
041     * This enumeration is returned when the target keyword is
042     * "targetfilter".
043     */
044    KEYWORD_TARGETFILTER ("targetfilter"),
045    /**
046     * This enumeration is returned when the target keyword is
047     * "targattrfilters".
048     */
049    KEYWORD_TARGATTRFILTERS ("targattrfilters"),
050    /**
051     * This enumeration is returned when the target keyword is
052     * "targetcontrol".
053     */
054    KEYWORD_TARGETCONTROL ("targetcontrol"),
055      /**
056     * This enumeration is returned when the target keyword is
057     * "extop".
058     */
059    KEYWORD_EXTOP ("extop");
060
061    /** The target keyword name. */
062    private final String keyword;
063
064    /**
065     * Create a target keyword enumeration of the specified name.
066     * @param keyword    The keyword name.
067     */
068    EnumTargetKeyword(String keyword){
069        this.keyword = keyword;
070    }
071
072    /**
073     * Checks if the keyword name is equal to the enumeration name.
074     * @param keyword The keyword name to check.
075     * @return  True if the keyword name is equal to the enumeration.
076     */
077    public boolean isKeyword(String keyword){
078        return keyword.equalsIgnoreCase(this.keyword);
079    }
080
081    /**
082     * Create an enumeration of the provided keyword name.
083     * @param keyword The keyword name to create.
084     * @return  An enumeration of the specified keyword name or null
085     * if the keyword name is invalid.
086     */
087    public static EnumTargetKeyword createKeyword(String keyword){
088        if (keyword != null){
089            for (EnumTargetKeyword t : EnumTargetKeyword.values()){
090                if (t.isKeyword(keyword)){
091                    return t;
092                }
093            }
094        }
095        return null;
096    }
097
098    /**
099     * Return the enumeration keyword name.
100     * @return The keyword name.
101     */
102    public String getKeyword() {
103      return keyword;
104    }
105}