⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matchfunction.java

📁 sunxacml源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

/*
 * @(#)MatchFunction.java
 *
 * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistribution of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 * 
 *   2. Redistribution in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 * Neither the name of Sun Microsystems, Inc. or the names of contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 * 
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN")
 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that this software is not designed or intended for use in
 * the design, construction, operation or maintenance of any nuclear facility.
 */

package com.sun.xacml.cond;

import com.sun.xacml.EvaluationCtx;

import com.sun.xacml.attr.AnyURIAttribute;
import com.sun.xacml.attr.AttributeValue;
import com.sun.xacml.attr.BooleanAttribute;
import com.sun.xacml.attr.DNSNameAttribute;
import com.sun.xacml.attr.IPAddressAttribute;
import com.sun.xacml.attr.RFC822NameAttribute;
import com.sun.xacml.attr.StringAttribute;
import com.sun.xacml.attr.X500NameAttribute;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import java.util.regex.Pattern;

import javax.security.auth.x500.X500Principal;


/**
 * Implements the standard matching and regular expression functions.
 *
 * @since 1.0
 * @author Seth Proctor
 * @author Yassir Elley
 */
public class MatchFunction extends FunctionBase
{

    /**
     * Standard identifier for the regexp-string-match function.
     */
    public static final String NAME_REGEXP_STRING_MATCH =
        FUNCTION_NS + "regexp-string-match";

    /**
     * Standard identifier for the x500Name-match function.
     */
    public static final String NAME_X500NAME_MATCH =
        FUNCTION_NS + "x500Name-match";

    /**
     * Standard identifier for the rfc822Name-match function.
     */
    public static final String NAME_RFC822NAME_MATCH =
        FUNCTION_NS + "rfc822Name-match";

    /**
     * Standard identifier for the string-regexp-match function. NOTE: this
     * in the 1.0 namespace right now because of a bug in the XACML 2.0
     * specification, but this will be changed to the 2.0 namespace as soon
     * as the errata is recognized.
     */
    public static final String NAME_STRING_REGEXP_MATCH =
        FUNCTION_NS + "string-regexp-match";
    
    /**
     * Standard identifier for the anyURI-regexp-match function.
     */
    public static final String NAME_ANYURI_REGEXP_MATCH =
        FUNCTION_NS_2 + "anyURI-regexp-match";

    /**
     * Standard identifier for the ipAddress-regexp-match function.
     */
    public static final String NAME_IPADDRESS_REGEXP_MATCH =
        FUNCTION_NS_2 + "ipAddress-regexp-match";

    /**
     * Standard identifier for the dnsName-regexp-match function.
     */
    public static final String NAME_DNSNAME_REGEXP_MATCH =
        FUNCTION_NS_2 + "dnsName-regexp-match";

    /**
     * Standard identifier for the rfc822Name-regexp-match function.
     */
    public static final String NAME_RFC822NAME_REGEXP_MATCH =
        FUNCTION_NS_2 + "rfc822Name-regexp-match";

    /**
     * Standard identifier for the x500Name-regexp-match function.
     */
    public static final String NAME_X500NAME_REGEXP_MATCH =
        FUNCTION_NS_2 + "x500Name-regexp-match";

    // private identifiers for the supported functions
    private static final int ID_REGEXP_STRING_MATCH = 0;
    private static final int ID_X500NAME_MATCH = 1;
    private static final int ID_RFC822NAME_MATCH = 2;
    private static final int ID_STRING_REGEXP_MATCH = 3;
    private static final int ID_ANYURI_REGEXP_MATCH = 4;
    private static final int ID_IPADDRESS_REGEXP_MATCH = 5;
    private static final int ID_DNSNAME_REGEXP_MATCH = 6;
    private static final int ID_RFC822NAME_REGEXP_MATCH = 7;
    private static final int ID_X500NAME_REGEXP_MATCH = 8;

    // private mappings for the input arguments
    private static final String regexpParams [] = {
        StringAttribute.identifier,
        StringAttribute.identifier };
    private static final String x500Params [] = {
        X500NameAttribute.identifier,
        X500NameAttribute.identifier };
    private static final String rfc822Params [] = {
        StringAttribute.identifier,
        RFC822NameAttribute.identifier};
    private static final String stringRegexpParams [] = {
        StringAttribute.identifier,
        StringAttribute.identifier};
    private static final String anyURIRegexpParams [] = {
        StringAttribute.identifier,
        AnyURIAttribute.identifier};
    private static final String ipAddressRegexpParams [] = {
        StringAttribute.identifier,
        IPAddressAttribute.identifier};
    private static final String dnsNameRegexpParams [] = {
        StringAttribute.identifier,
        DNSNameAttribute.identifier};
    private static final String rfc822NameRegexpParams [] = {
        StringAttribute.identifier,
        RFC822NameAttribute.identifier};
    private static final String x500NameRegexpParams [] = {
        StringAttribute.identifier,
        X500NameAttribute.identifier};

    // private mapping for bag input options
    private static final boolean bagParams [] = { false, false };

    /**
     * Creates a new <code>MatchFunction</code> based on the given name.
     *
     * @param functionName the name of the standard match function, including
     *                     the complete namespace
     *
     * @throws IllegalArgumentException if the function is unknown
     */
    public MatchFunction(String functionName) {
        super(functionName, getId(functionName),
              getArgumentTypes(functionName), bagParams,
              BooleanAttribute.identifier, false);
    }

    /**
     * Private helper that returns the internal identifier used for the
     * given standard function.
     */
    private static int getId(String functionName) {
        if (functionName.equals(NAME_REGEXP_STRING_MATCH))
            return ID_REGEXP_STRING_MATCH;
        else if (functionName.equals(NAME_X500NAME_MATCH))
            return ID_X500NAME_MATCH;
        else if (functionName.equals(NAME_RFC822NAME_MATCH))
            return ID_RFC822NAME_MATCH;
        else if (functionName.equals(NAME_STRING_REGEXP_MATCH))
            return ID_STRING_REGEXP_MATCH;
        else if (functionName.equals(NAME_ANYURI_REGEXP_MATCH))
            return ID_ANYURI_REGEXP_MATCH;
        else if (functionName.equals(NAME_IPADDRESS_REGEXP_MATCH))
            return ID_IPADDRESS_REGEXP_MATCH;
        else if (functionName.equals(NAME_DNSNAME_REGEXP_MATCH))
            return ID_DNSNAME_REGEXP_MATCH;
        else if (functionName.equals(NAME_RFC822NAME_REGEXP_MATCH))
            return ID_RFC822NAME_REGEXP_MATCH;
        else if (functionName.equals(NAME_X500NAME_REGEXP_MATCH))
            return ID_X500NAME_REGEXP_MATCH;

        throw new IllegalArgumentException("unknown match function: " +
                                           functionName);
    }

    /**
     * Private helper that returns the types used for the given standard
     * function. Note that this doesn't check on the return value since the
     * method always is called after getId, so we assume that the function
     * is present.
     */
    private static String [] getArgumentTypes(String functionName) {
        if (functionName.equals(NAME_REGEXP_STRING_MATCH))
            return regexpParams;
        else if (functionName.equals(NAME_X500NAME_MATCH))
            return x500Params;
        else if (functionName.equals(NAME_RFC822NAME_MATCH))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -