Search in sources :

Example 1 with Attribute

use of org.glassfish.security.services.api.common.Attribute in project Payara by payara.

the class AttributeTest method testAttributeNullValue1.

@Test
public void testAttributeNullValue1() {
    String attName = "testnull1";
    Attribute att = new AttributeImpl(attName);
    att.addValue(null);
    att.addValue("value1");
    Set<String> vs = att.getValues();
    Assert.assertEquals(1, att.getValueCount());
    Assert.assertTrue(vs.contains("value1"));
}
Also used : Attribute(org.glassfish.security.services.api.common.Attribute) Test(org.junit.Test)

Example 2 with Attribute

use of org.glassfish.security.services.api.common.Attribute in project Payara by payara.

the class AttributeTest method testAttribute.

@Test
public void testAttribute() {
    String attName = "test";
    Attribute att = new AttributeImpl(attName);
    att.addValue("value1");
    att.addValue("value2");
    Set<String> vs = att.getValues();
    Assert.assertEquals(2, att.getValueCount());
    Assert.assertTrue(vs.contains("value1"));
    Assert.assertTrue(vs.contains("value2"));
}
Also used : Attribute(org.glassfish.security.services.api.common.Attribute) Test(org.junit.Test)

Example 3 with Attribute

use of org.glassfish.security.services.api.common.Attribute in project Payara by payara.

the class AttributeTest method testAttributeNullValue.

@Test
public void testAttributeNullValue() {
    String attName = "testnull";
    Attribute att = new AttributeImpl(attName);
    att.addValue(null);
    Set<String> vs = att.getValues();
    Assert.assertTrue(vs.isEmpty());
}
Also used : Attribute(org.glassfish.security.services.api.common.Attribute) Test(org.junit.Test)

Example 4 with Attribute

use of org.glassfish.security.services.api.common.Attribute in project Payara by payara.

the class AzResourceImplTest method testAddAttributesFromUriQuery.

@Test
public void testAddAttributesFromUriQuery() throws Exception {
    URI uri = new URI("admin:///tenants/tenant/zirka?locked=true");
    Attributes attributes = new AttributesImpl();
    Attribute attribute;
    Set<String> values;
    Iterator<String> iter;
    BitSet bitset;
    final boolean REPLACE = true;
    // Null
    try {
        addAttributesFromUriQuery(null, attributes, REPLACE);
        fail("Expected IllegalArgumentException from null URI.");
    } catch (IllegalArgumentException e) {
    }
    try {
        addAttributesFromUriQuery(uri, null, REPLACE);
        fail("Expected IllegalArgumentException from null Attributes.");
    } catch (IllegalArgumentException e) {
    }
    assertEquals("Empty attributes", 0, attributes.getAttributeCount());
    // No params
    uri = new URI("admin:///tenants/tenant/zirka");
    addAttributesFromUriQuery(uri, attributes, !REPLACE);
    assertEquals("Empty attributes", 0, attributes.getAttributeCount());
    // 1 param
    uri = new URI("admin:///tenants/tenant/zirka?name1=value1");
    addAttributesFromUriQuery(uri, attributes, !REPLACE);
    assertEquals("Attributes count", 1, attributes.getAttributeCount());
    assertNotNull("attribute", attribute = attributes.getAttribute("name1"));
    values = attribute.getValues();
    assertEquals("Values count", 1, values.size());
    iter = values.iterator();
    assertTrue(iter.hasNext());
    assertEquals("Values value", "value1", iter.next());
    assertFalse(iter.hasNext());
    // Repeat, no dup value
    addAttributesFromUriQuery(uri, attributes, !REPLACE);
    assertEquals("Attributes count", 1, attributes.getAttributeCount());
    assertNotNull("attribute", attribute = attributes.getAttribute("name1"));
    values = attribute.getValues();
    assertEquals("Values count", 1, values.size());
    iter = values.iterator();
    assertTrue("iterator", iter.hasNext());
    assertEquals("Values value", "value1", iter.next());
    assertFalse("iterator", iter.hasNext());
    // New value
    uri = new URI("admin:///tenants/tenant/boris?name1=value2");
    addAttributesFromUriQuery(uri, attributes, !REPLACE);
    assertEquals("Attributes count", 1, attributes.getAttributeCount());
    assertNotNull("attribute", attribute = attributes.getAttribute("name1"));
    values = attribute.getValues();
    assertEquals("Values count", 2, values.size());
    bitset = new BitSet(2);
    for (String v : values) {
        if ("value1".equals(v) && !bitset.get(0)) {
            bitset.set(0);
        } else if ("value2".equals(v) && !bitset.get(1)) {
            bitset.set(1);
        } else {
            fail("Unexpected attribute value " + v);
        }
    }
    // Replace attribute
    uri = new URI("admin:///tenants/tenant/lucky?name1=value3");
    addAttributesFromUriQuery(uri, attributes, REPLACE);
    assertEquals("Attributes count", 1, attributes.getAttributeCount());
    assertNotNull("attribute", attribute = attributes.getAttribute("name1"));
    values = attribute.getValues();
    assertEquals("Values count", 1, values.size());
    iter = values.iterator();
    assertTrue("iterator", iter.hasNext());
    assertEquals("Values value", "value3", iter.next());
    assertFalse("iterator", iter.hasNext());
    // New attribute
    uri = new URI("admin:///tenants/tenant/lucky?name2=value21&name2=value22");
    addAttributesFromUriQuery(uri, attributes, !REPLACE);
    assertEquals("Attributes count", 2, attributes.getAttributeCount());
    assertNotNull("attribute", attributes.getAttribute("name1"));
    assertNotNull("attribute", attribute = attributes.getAttribute("name2"));
    values = attribute.getValues();
    assertEquals("Values count", 2, values.size());
    bitset = new BitSet(2);
    for (String v : values) {
        if ("value21".equals(v) && !bitset.get(0)) {
            bitset.set(0);
        } else if ("value22".equals(v) && !bitset.get(1)) {
            bitset.set(1);
        } else {
            fail("Unexpected attribute value " + v);
        }
    }
    // Encoded attribute
    attributes = new AttributesImpl();
    uri = new URI("admin:///tenants/tenant/lucky?na%3Dme2=val%26ue1&na%3Dme2=val%3Due2");
    addAttributesFromUriQuery(uri, attributes, !REPLACE);
    assertEquals("Attributes count", 1, attributes.getAttributeCount());
    assertNotNull("attribute", attribute = attributes.getAttribute("na=me2"));
    values = attribute.getValues();
    assertEquals("Values count", 2, values.size());
    bitset = new BitSet(2);
    for (String v : values) {
        if ("val&ue1".equals(v) && !bitset.get(0)) {
            bitset.set(0);
        } else if ("val=ue2".equals(v) && !bitset.get(1)) {
            bitset.set(1);
        } else {
            fail("Unexpected attribute value " + v);
        }
    }
}
Also used : AttributesImpl(org.glassfish.security.services.impl.common.AttributesImpl) Attribute(org.glassfish.security.services.api.common.Attribute) Attributes(org.glassfish.security.services.api.common.Attributes) BitSet(java.util.BitSet) URI(java.net.URI) AzResourceImpl.decodeURI(org.glassfish.security.services.impl.authorization.AzResourceImpl.decodeURI) Test(org.junit.Test)

Example 5 with Attribute

use of org.glassfish.security.services.api.common.Attribute in project Payara by payara.

the class AttributeTest method testAttributeEmptyValue.

@Test
public void testAttributeEmptyValue() {
    String attName = "testEmpty";
    Attribute att = new AttributeImpl(attName);
    att.addValue("");
    Set<String> vs = att.getValues();
    Assert.assertTrue(vs.isEmpty());
}
Also used : Attribute(org.glassfish.security.services.api.common.Attribute) Test(org.junit.Test)

Aggregations

Attribute (org.glassfish.security.services.api.common.Attribute)5 Test (org.junit.Test)5 URI (java.net.URI)1 BitSet (java.util.BitSet)1 Attributes (org.glassfish.security.services.api.common.Attributes)1 AzResourceImpl.decodeURI (org.glassfish.security.services.impl.authorization.AzResourceImpl.decodeURI)1 AttributesImpl (org.glassfish.security.services.impl.common.AttributesImpl)1