All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xacml4j.v30.ExpectedAttributeResolverBuilder Maven / Gradle / Ivy

package org.xacml4j.v30;

/*
 * #%L
 * Xacml4J Policy Unit Test Support
 * %%
 * Copyright (C) 2009 - 2014 Xacml4J.org
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import java.util.Map;

import org.xacml4j.v30.spi.pip.AttributeResolver;
import org.xacml4j.v30.spi.pip.AttributeResolverDescriptorBuilder;
import org.xacml4j.v30.spi.pip.BaseAttributeResolver;
import org.xacml4j.v30.spi.pip.ResolverContext;

import com.google.common.collect.ImmutableMap;


public class ExpectedAttributeResolverBuilder
{
	private AttributeResolverDescriptorBuilder b;
	private ImmutableMap.Builder values;

	private ExpectedAttributeResolverBuilder(AttributeResolverDescriptorBuilder b){
		this.b = b;
		this.values = ImmutableMap.builder();
	}

	public static ExpectedAttributeResolverBuilder builder(String id, CategoryId category, String issuer){
		return new ExpectedAttributeResolverBuilder(AttributeResolverDescriptorBuilder.builder(id, 
				"ExpectedAttributeResolver " + id, issuer, category));
	}

	public static ExpectedAttributeResolverBuilder builder(String id, CategoryId category){
		return builder(id, category, null);
	}

	public ExpectedAttributeResolverBuilder designatorKeyRef(
			CategoryId category, String attributeId, AttributeExpType type)
	{
		b.requestContextKey(category, attributeId, type);
		return this;
	}
	public ExpectedAttributeResolverBuilder value(String id, AttributeExp value){
		b.attribute(id, value.getType());
		this.values.put(id, value.toBag());
		return this;
	}

	public ExpectedAttributeResolverBuilder value(String id, BagOfAttributeExp value){
		b.attribute(id, value.getDataType());
		this.values.put(id, value);
		return this;
	}

	public AttributeResolver build(){
		return new BaseAttributeResolver(b.build()) {

			@Override
			protected Map doResolve(ResolverContext context)
					throws Exception {
				return values.build();
			}
		};
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy