protected static BasicControl[] convertControls( final ChaiRequestControl[] controls ) { if ( controls == null ) { return null; } final BasicControl[] newControls = new BasicControl[controls.length]; for ( int i = 0; i < controls.length; i++ ) { newControls[i] = new BasicControl( controls[i].getId(), controls[i].isCritical(), controls[i].getValue() ); } return newControls; }
/** * {@inheritDoc} */ @Override public javax.naming.ldap.Control toJndiControl( Control control ) throws EncoderException { CodecControl<? extends Control> decorator = newControl( control ); ByteBuffer bb = ByteBuffer.allocate( decorator.computeLength() ); decorator.encode( bb ); bb.flip(); return new BasicControl( control.getOid(), control.isCritical(), bb.array() ); }
/** * <p> * Test method for 'javax.naming.ldap.BasicControl.BasicControl' * </p> */ public void testBasicControl() { // no exceptions expected new BasicControl(null); new BasicControl(""); new BasicControl("1.2.3.333"); new BasicControl("", true, null); new BasicControl("", false, new byte[0]); new BasicControl(null, false, null); }
/** * @tests javax.naming.ldap.BasicControl#getID() */ public void testGetID() { String ID = "somestring"; assertSame(ID, new BasicControl(ID).getID()); assertNull(new BasicControl(null).getID()); assertNull(new BasicControl(null, false, new byte[1]).getID()); }
public void test_encodeValues_$LObject() { LdapControl control = new LdapControl(new BasicControl("id", true, new byte[10])); ASN1TestUtils.checkEncode(control, LdapASN1Constant.Control); //controlValue is optional, so it could be null control = new LdapControl(new BasicControl("id2", false, null)); ASN1TestUtils.checkEncode(control, LdapASN1Constant.Control); }
public final void writeStringAttributes( final String entryDN, final Map<String, String> attributeValueProps, final boolean overwrite, final BasicControl[] controls ) throws ChaiUnavailableException, ChaiOperationException { activityPreCheck(); getInputValidator().writeStringAttributes( entryDN, attributeValueProps, overwrite ); // Determine the modification type, if replace, only replace on the first attribute, the rest just get added. final int modType = overwrite ? DirContext.REPLACE_ATTRIBUTE : DirContext.ADD_ATTRIBUTE; // Create the ModificationItem final List<ModificationItem> modificationItems = new ArrayList<>(); for ( final Map.Entry<String, String> entry : attributeValueProps.entrySet() ) { // Create a BasicAttribute for the object. final BasicAttribute attributeToReplace = new BasicAttribute( entry.getKey(), entry.getValue() ); // Populate the ModificationItem object with the flag & the attribute to replace. modificationItems.add( new ModificationItem( modType, attributeToReplace ) ); } // convert to array final ModificationItem[] modificationItemArray = modificationItems.toArray( new ModificationItem[modificationItems.size()] ); // get ldap connection final LdapContext ldapConnection = getLdapConnection(); // Modify the Attributes. try { ldapConnection.modifyAttributes( addJndiEscape( entryDN ), modificationItemArray ); } catch ( NamingException e ) { convertNamingException( e ); } }
public void decodeValues(Object[] values) { String id = Utils.getString((byte[]) values[0]); boolean isCritical = ((Boolean) values[1]).booleanValue(); byte[] encoded = (byte[]) values[2]; control = new BasicControl(id, isCritical, encoded); }
public void test_setRequestControls() throws Exception { MockLdapClient client = new MockLdapClient(); Hashtable<Object, Object> env = new Hashtable<Object, Object>(); env.put(Context.REFERRAL, "follow"); context = new LdapContextImpl(client, env, "cn=test"); context.setRequestControls(null); assertNull(context.getRequestControls()); Control[] controls = new Control[] { new BasicControl("0"), new BasicControl("1"), new BasicControl("2"), new BasicControl("3") }; context.setRequestControls(controls); Control[] actual = context.getRequestControls(); assertEquals(controls.length, actual.length); assertNotSame(controls, actual); // Context.REFERRAL is 'ignore' add ManageDsaIT Control env.put(Context.REFERRAL, "ignore"); context = new LdapContextImpl(client, env, "cn=test"); context.setRequestControls(null); actual = context.getRequestControls(); assertEquals(1, actual.length); assertEquals("2.16.840.1.113730.3.4.2", actual[0].getID()); assertNull(actual[0].getEncodedValue()); assertFalse(actual[0].isCritical()); context.setRequestControls(controls); actual = context.getRequestControls(); assertEquals(controls.length + 1, actual.length); // Context.REFERRAL is 'ignore', add ManageDsaIT Control context = new LdapContextImpl(client, new Hashtable<Object, Object>(), "cn=test"); context.setRequestControls(null); actual = context.getRequestControls(); assertEquals(1, actual.length); assertEquals("2.16.840.1.113730.3.4.2", actual[0].getID()); assertNull(actual[0].getEncodedValue()); assertFalse(actual[0].isCritical()); context.setRequestControls(controls); actual = context.getRequestControls(); assertEquals(controls.length + 1, actual.length); }
/** * <p> * Test method for 'javax.naming.ldap.Rdn.Rdn(String, Object)' * </p> * <p> * This is a test for the constructor of the class Rdn. Here we are testing * with a non-null String and a non-null object but the type here has a * special character like "+", which should be permited. * </p> * <p> * The expected result is an instance not null of Rdn. * </p> */ public void testRdnStringObject007() throws Exception { new Rdn("y=asd+t=test", "a=asd"); new Rdn("y=asd", "a=asd+t=test"); new Rdn("t", new ArrayList()); new Rdn("t=t=t", new Object()); new Rdn("t=t=t", "test"); new Rdn("t", new BasicControl("test")); }
/** * <p> * Test method for 'javax.naming.ldap.BasicControl.getEncodedValue()' * </p> * <p> * Here we are testing the return method of the encoded value of * BasicControl. In this case we send an encoded value null. * </p> * <p> * The expected result is a null encoded value. * </p> */ public void testGetEncodedValue() { assertNull(new BasicControl("control", true, null).getEncodedValue()); // spec says the byte[] is NOT copied byte[] test = new byte[15]; BasicControl bc = new BasicControl("control", true, test); assertSame(test, bc.getEncodedValue()); }
/** * <p> * Test method for 'javax.naming.ldap.Rdn.Rdn(String, Object)' * </p> * <p> * This is the test method for the constructor of the class Rdn, in this * case we are testing to construct an Rdn from the given String and Object. * Here we are testing if we send a non null String with a non null object * but the type here has a special character like "+" this must be permited. * </p> * <p> * The expected result is an instance not null of Rdn. * </p> */ public void testRdnStringObject007() throws Exception { new Rdn("y=asd+t=test", "a=asd"); new Rdn("y=asd", "a=asd+t=test"); new Rdn("t", new ArrayList()); new Rdn("t=t=t", new Object()); new Rdn("t=t=t", "test"); new Rdn("t", new BasicControl("test")); }
/** * <p> * Test method for 'javax.naming.ldap.Rdn.Rdn(String, Object)' * </p> * <p> * This is a test for the constructor of the class Rdn. Here we are testing * with a non-empty String and different objects. * </p> * <p> * The expected result is an instance of the class with the different * arguments because the arguments are not parsed. * </p> */ public void testRdnStringObject018() throws Exception { new Rdn(new String("t===T"), new ArrayList()); new Rdn(new String("t=+=T"), new Object()); new Rdn(new String("t=,33,=T"), new BasicControl("test")); }
/** * <p> * Test method for 'javax.naming.ldap.Rdn.Rdn(String, Object)' * </p> * <p> * This is a test for the constructor of the class Rdn. Here we are testing * with a non-empty String and different objects. * </p> * <p> * The expected result is an instance of the class with the different * arguments because the arguments are not parsed. * </p> */ public void testRdnStringObject019() throws Exception { new Rdn(new String("t===T"), new char[] { 'a', 'v' }); new Rdn(new String("t=+=T"), new int[] { 1, 2, 3 }); new Rdn(new String("t=,33,=T"), new BasicControl("test")); }
/** * <p> * Test method for 'javax.naming.ldap.Rdn.Rdn(String, Object)' * </p> * <p> * This is the test method for the constructor of the class Rdn, in this * case we are testing to construct an Rdn from the given String and Object. * Here we are testing if we send a non empty String and this one not ok * with diferents objects. * </p> * <p> * The expected result is an instance of the class with the diferents * arguments because the arguments are not parsed. * </p> */ public void testRdnStringObject018() throws Exception { new Rdn(new String("t===T"), new ArrayList()); new Rdn(new String("t=+=T"), new Object()); new Rdn(new String("t=,33,=T"), new BasicControl("test")); }
/** * <p> * Test method for 'javax.naming.ldap.Rdn.Rdn(String, Object)' * </p> * <p> * This is the test method for the constructor of the class Rdn, in this * case we are testing to construct an Rdn from the given String and Object. * Here we are testing if we send a non empty String and this one not ok * with diferents objects. * </p> * <p> * The expected result is an instance of the class with the diferents * arguments because the arguments are not parsed. * </p> */ public void testRdnStringObject019() throws Exception { new Rdn(new String("t===T"), new char[] { 'a', 'v' }); new Rdn(new String("t=+=T"), new int[] { 1, 2, 3 }); new Rdn(new String("t=,33,=T"), new BasicControl("test")); }