org.apache.directory.api.util.Strings Java Examples

The following examples show how to use org.apache.directory.api.util.Strings. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PasswordUtil.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * generates a hash based on the <a href="http://en.wikipedia.org/wiki/PBKDF2">PKCS5S2 spec</a>
 * 
 * Note: this has been implemented to generate hashes compatible with what JIRA generates.
 *       See the <a href="http://pythonhosted.org/passlib/lib/passlib.hash.atlassian_pbkdf2_sha1.html">JIRA's passlib</a>
 *       
 * @param credentials the credentials
 * @param algorithm the algorithm to use
 * @param salt the optional salt
 * @return the digested credentials
 */
private static byte[] generatePbkdf2Hash( byte[] credentials, LdapSecurityConstants algorithm, byte[] salt )
{
    try
    {
        SecretKeyFactory sk = SecretKeyFactory.getInstance( algorithm.getAlgorithm() );
        char[] password = Strings.utf8ToString( credentials ).toCharArray();
        KeySpec keySpec = new PBEKeySpec( password, salt, 10000, PKCS5S2_LENGTH * 8 );
        Key key = sk.generateSecret( keySpec );
        return key.getEncoded();
    }
    catch ( Exception e )
    {
        throw new RuntimeException( e );
    }
}
 
Example #2
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for userCertificate;binary AT
 */
@Test
public void testUserCertificateBinary() throws LdapException
{
    Entry entry = new DefaultEntry( schemaManager );
    entry.add( "objectClass", "top", "person", "inetorgPerson" );
    entry.add( "cn", "test1", "test2" );
    entry.add( "sn", "Test1", "Test2" );
    entry.add( "userPassword", BYTES1, BYTES2 );

    entry.add( "userCertificate;binary", Strings.getBytesUtf8( "secret" ) );
    assertTrue( entry.containsAttribute( "userCertificate;binary" ) );
    assertTrue( entry.containsAttribute( "userCertificate" ) );

    entry.removeAttributes( "userCertificate;binary" );
    assertFalse( entry.containsAttribute( "userCertificate;binary" ) );
    assertFalse( entry.containsAttribute( "userCertificate" ) );

    entry.add( "userCertificate", Strings.getBytesUtf8( "secret" ) );
    assertTrue( entry.containsAttribute( "userCertificate;binary" ) );
    assertTrue( entry.containsAttribute( "userCertificate" ) );
}
 
Example #3
Source File: SchemaAwareValueSerializationTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize OIDs maps for normalization
 */
@BeforeAll
public static void setup() throws Exception
{
    schemaManager = new DefaultSchemaManager();
    cn = schemaManager.getAttributeType( "cn" );
    dc = schemaManager.getAttributeType( "dc" );
    userCertificate = schemaManager.getAttributeType( "userCertificate" );

    bv1 = new Value( userCertificate, DATA );
    bv2 = new Value( userCertificate, Strings.EMPTY_BYTES );
    bv3 = new Value( userCertificate, ( byte[] ) null );
    bv1n = new Value( userCertificate, DATA );
    bv2n = new Value( userCertificate, Strings.EMPTY_BYTES );
    bv3n = new Value( userCertificate, ( byte[] ) null );
    sv1 = new Value( cn, "test" );
    sv2 = new Value( dc, "" );
    sv3 = new Value( dc, ( String ) null );
    sv1n = new Value( cn, "test" );
    sv2n = new Value( dc, "" );
    sv3n = new Value( dc, ( String ) null );
}
 
Example #4
Source File: SubtreeSpecificationParser.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a subtree specification without exhausting the parser.
 * 
 * @param spec
 *            the specification to be parsed
 * @return the specification bean
 * @throws ParseException
 *             if there are any recognition errors (bad syntax)
 */
public synchronized SubtreeSpecification parse( String spec ) throws ParseException
{
    SubtreeSpecification ss;

    if ( ( spec == null ) || Strings.isEmpty( spec.trim() ) )
    {
        return null;
    }

    // reset and initialize the parser / lexer pair
    reset( spec );

    try
    {
        ss = this.parser.wrapperEntryPoint();
    }
    catch ( TokenStreamException | RecognitionException e )
    {
        String msg = I18n.err( I18n.ERR_13028_SUBTREE_SPEC_PARSER_FAILURE, spec, e.getLocalizedMessage() );
        throw new ParseException( msg, 0 );
    }

    return ss;
}
 
Example #5
Source File: ApiLdapSchemaConverterOsgiTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Override
protected void useBundleClasses() throws Exception
{
    List<Schema> schemas = new ArrayList<Schema>();

    Schema schema = new Schema();
    schema.setName( "foo" );
    schema.setInput( new ByteArrayInputStream(
        Strings.getBytesUtf8( "attributetype ( 1.3.6.1.4.1.18060.0.4.2.3.14 NAME ( 'at' 'attribute' ) )" ) ) );

    Writer out = new StringWriter( 2048 );
    schema.setOutput( out );
    schemas.add( schema );

    SchemaToLdif.transform( schemas );
}
 
Example #6
Source File: AbstractSchemaObject.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<String> getExtension( String extension )
{
    String name = Strings.toUpperCaseAscii( extension );
    
    if ( hasExtension( name ) )
    {
        for ( Map.Entry<String, List<String>> entry : extensions.entrySet() )
        {
            String key = entry.getKey();
            
            if ( name.equalsIgnoreCase( key ) )
            {
                return entry.getValue();
            }
        }
    }

    return null;
}
 
Example #7
Source File: StandaloneLdapApiService.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the system properties to obtain the intermediate responses.
 * Such intermediate responses are stored in the <b>apacheds.intermediateResponses</b>
 * and <b>default.intermediateResponses.requests</b> system properties.
 *
 * @return a list of intermediate responses
 */
private static List<String> getIntermediateResponsesFromSystemProperties()
{
    List<String> intermediateResponsesList = new ArrayList<>();

    // Loading extended operations from command line properties if it exists
    String defaultIntermediateResponsesList = System.getProperty( INTERMEDIATE_RESPONSES_LIST );

    if ( !Strings.isEmpty( defaultIntermediateResponsesList ) )
    {
        for ( String intermediateResponse : defaultIntermediateResponsesList.split( "," ) )
        {
            intermediateResponsesList.add( intermediateResponse );
        }
    }

    return intermediateResponsesList;
}
 
Example #8
Source File: StandaloneLdapCodecServiceTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test an extended operation.
 */
@Test
public void testLoadingExtendedOperation() throws Exception
{
    LdapApiService codec = LdapApiServiceFactory.getSingleton();
    StoredProcedureRequest req = new StoredProcedureRequestImpl();
    req.setLanguage( "Java" );
    req.setProcedure( Strings.getBytesUtf8( "bogusProc" ) );

    assertNotNull( req );
    assertNotNull( codec );
    
    StoredProcedureFactory factory = ( StoredProcedureFactory ) codec.getExtendedRequestFactories().get( 
        StoredProcedureRequest.EXTENSION_OID );
    
    req = factory.newRequest();
    assertNotNull( req );
}
 
Example #9
Source File: StartTransactionResponseImpl.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * @see Object#toString()
 */
@Override
public String toString()
{
    StringBuilder sb = new StringBuilder();

    sb.append( "StartTransactionResponse :" );
    sb.append( "\n    transactionID : " );

    if ( transactionId != null )
    {
        sb.append( Strings.dumpBytes( transactionId ) );
    }
    else
    {
        sb.append( "null" );
    }

    return sb.toString();
}
 
Example #10
Source File: RegExUtil.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 *  Perform safe text validation on character string.
 *
 * @param  value Contains the string to check.
 * @exception org.apache.directory.fortress.core.ValidationException  In the event the data validation fails.
 */
void safeText( String value ) throws ValidationException
{
    if ( Strings.isEmpty( SAFE_TEXT_PATTERN_STRING ) )
    {
        LOG.debug( "safeText can't find safeText regular expression pattern.  Check your Fortress cfg" );
    }
    else
    {
        Matcher safeTextMatcher = safeTextPattern.matcher( value );
        
        if ( !safeTextMatcher.find() )
        {
            String error = "safeText has detected invalid value [" + value + "]";
            throw new ValidationException( GlobalErrIds.CONST_INVLD_TEXT, error );
        }
    }
}
 
Example #11
Source File: StoreMatchingRuleId.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void action( LdapMessageContainer<SearchRequest> container ) throws DecoderException
{
    TLV tlv = container.getCurrentTLV();

    // Store the value.
    ExtensibleMatchFilter extensibleMatchFilter = ( ExtensibleMatchFilter )
        container.getTerminalFilter();

    if ( tlv.getLength() == 0 )
    {
        String msg = I18n.err( I18n.ERR_05001_EMPTY_MATCHING_RULE );
        LOG.error( msg );

        // It will generate a PROTOCOL_ERROR
        throw new DecoderException( msg );
    }
    else
    {
        extensibleMatchFilter.setMatchingRule( Strings.utf8ToString( tlv.getValue().getData() ) );
    }
}
 
Example #12
Source File: SchemaElementImpl.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * @return The description as a ldif line
 * @throws org.apache.directory.api.ldap.model.exception.LdapException If the conversion goes wrong
 */
private String descToLdif() throws LdapException
{
    if ( Strings.isEmpty( description ) )
    {
        return "";
    }
    else
    {
        Entry entry = new DefaultEntry();
        Attribute attribute = new DefaultAttribute( "m-description", description );

        entry.put( attribute );

        return LdifUtils.convertAttributesToLdif( entry );
    }
}
 
Example #13
Source File: ExtendedRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with a RequestValue element with Base64 value
 */
@Test
public void testRequestWithBase64RequestValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( ExtendedRequestTest.class.getResource( "request_with_base64_requestValue.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    ExtendedRequestDsml<?, ?> extendedRequest =
        ( ExtendedRequestDsml<?, ?> ) parser.getBatchRequest().getCurrentRequest();

    assertEquals( "DSMLv2.0 rocks!!", Strings.utf8ToString( extendedRequest.getRequestValue() ) );
}
 
Example #14
Source File: StoreMatchingRuleType.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void action( LdapMessageContainer<SearchRequest> container ) throws DecoderException
{
    TLV tlv = container.getCurrentTLV();

    if ( tlv.getLength() == 0 )
    {
        String msg = I18n.err( I18n.ERR_05141_NULL_MATCHING_RULE_ASSERTION_TYPE );
        LOG.error( msg );
        throw new DecoderException( msg );
    }
    else
    {
        // Store the value.
        ExtensibleMatchFilter extensibleMatchFilter = ( ExtensibleMatchFilter ) container.getTerminalFilter();

        String type = Strings.utf8ToString( tlv.getValue().getData() );
        extensibleMatchFilter.setType( type );

        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.msg( I18n.MSG_05166_STORED_TYPE_MATCHING_RULE, type ) );
        }
    }
}
 
Example #15
Source File: BindResponseImpl.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Get a String representation of a BindResponse
 * 
 * @return A BindResponse String
 */
@Override
public String toString()
{
    StringBuilder sb = new StringBuilder();

    sb.append( "    BindResponse\n" );
    sb.append( super.toString() );

    if ( serverSaslCreds != null )
    {
        sb.append( "        Server sasl credentials : '" ).append( Strings.dumpBytes( serverSaslCreds ) )
            .append( "'\n" );
    }

    return super.toString( sb.toString() );
}
 
Example #16
Source File: Hier.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * Set the child and parent into the collection of valid relationships stored in this entity.
 *
 * @param role   attribute maps to the 'ftRels' attribute on 'ftHier' object class.
 * @param parent attribute maps to the 'ftRels' attribute on 'ftHier' object class.
 */
public void setRelationship( String role, String parent )
{
    if ( relationships == null )
    {
        relationships = new ArrayList<Relationship>();
    }

    relationships.add(
        new Relationship( Strings.toUpperCase( role ), Strings.toUpperCase( parent ) ) );
}
 
Example #17
Source File: SyncInfoValueControlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test the decoding of a SyncInfoValue control, refreshDelete choice,
 * no cookie, no refreshDone
 */
@Test
public void testDecodeSyncInfoValueControlRefreshDeleteNoCookieNoRefreshDone() throws Exception
{
    ByteBuffer bb = ByteBuffer.allocate( 0x02 );
    bb.put( new byte[]
        {
            ( byte ) 0xA1, 0x00 // syncInfoValue ::= CHOICE {
        } );
    bb.flip();

    SyncInfoValueFactory factory = ( SyncInfoValueFactory ) codec.getIntermediateResponseFactories().
        get( SyncInfoValue.OID );
    SyncInfoValue syncInfoValue = factory.newResponse();
    factory.decodeValue( syncInfoValue, bb.array() );

    assertEquals( SynchronizationInfoEnum.REFRESH_DELETE, syncInfoValue.getSyncInfoValueType() );
    assertEquals( "", Strings.utf8ToString( syncInfoValue.getCookie() ) );
    assertTrue( syncInfoValue.isRefreshDone() );

    // Check the revert encoding
    Asn1Buffer asn1Buffer = new Asn1Buffer();

    factory.encodeValue( asn1Buffer, syncInfoValue );
    
    assertArrayEquals( bb.array(), asn1Buffer.getBytes().array() );
}
 
Example #18
Source File: ExtendedRequestFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Encode the ExtendedRequest message to a PDU.
 * <br>
 * ExtendedRequest :
 * <pre>
 * 0x77 L1
 *  |
 *  +--&gt; 0x80 LL abcd requestName
 * [+--&gt; 0x81 LL abcd requestValue]
 * </pre>
 *
 * @param codec The LdapApiService instance
 * @param buffer The buffer where to put the PDU
 * @param message the DeleteResponse to encode
 */
@Override
public void encodeReverse( LdapApiService codec, Asn1Buffer buffer, Message message )
{
    int start = buffer.getPos();
    ExtendedRequest extendedRequest = ( ExtendedRequest ) message;
    
    // The responseValue, if any
    ExtendedOperationFactory factory = codec.getExtendedRequestFactories().
        get( extendedRequest.getRequestName() );
    
    if ( factory != null )
    {
        factory.encodeValue( buffer, extendedRequest );

        if ( buffer.getPos() > start )
        {
            BerValue.encodeSequence( buffer, 
                ( byte ) LdapCodecConstants.EXTENDED_REQUEST_VALUE_TAG,
                start );
        }
    }
    
    // The responseName, if any
    if ( !Strings.isEmpty( extendedRequest.getRequestName() ) )
    {
        BerValue.encodeOctetString( buffer, 
            ( byte ) LdapCodecConstants.EXTENDED_REQUEST_NAME_TAG,
            extendedRequest.getRequestName() );
    }
    
    // The sequence
    BerValue.encodeSequence( buffer, LdapCodecConstants.EXTENDED_REQUEST_TAG, start );
}
 
Example #19
Source File: StoreAny.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void action( LdapMessageContainer<SearchRequest> container ) throws DecoderException
{
    TLV tlv = container.getCurrentTLV();

    // Store the value.
    SubstringFilter substringFilter = ( SubstringFilter ) container.getTerminalFilter();

    if ( tlv.getLength() == 0 )
    {
        String msg = I18n.err( I18n.ERR_05139_EMPTY_SUBSTRING_ANY_FILTER_PDU );
        LOG.error( msg );
        throw new DecoderException( msg );
    }

    String any = Strings.utf8ToString( tlv.getValue().getData() );
    substringFilter.addAnySubstrings( any );

    // We now have to get back to the nearest filter which is
    // not terminal.
    container.unstackFilters();

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05153_STORED_ANY_SUBSTRING, any ) );
    }
}
 
Example #20
Source File: DefaultAttribute.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setUpId( String upId, AttributeType attributeType )
{
    String trimmed = Strings.trim( upId );

    if ( Strings.isEmpty( trimmed ) && ( attributeType == null ) )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_13235_NULL_ID_WITH_NULL_AT_NOT_ALLOWED ) );
    }

    String newId = Strings.toLowerCaseAscii( trimmed );

    setUpIdInternal( upId, newId, attributeType );
}
 
Example #21
Source File: AdDirSyncRequestImpl.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setCookie( byte[] cookie )
{
    if ( cookie != null )
    {
        this.cookie = new byte[cookie.length];
        System.arraycopy( cookie, 0, this.cookie, 0, cookie.length );
    }
    else
    {
        this.cookie = Strings.EMPTY_BYTES;
    }
}
 
Example #22
Source File: DefaultEntry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean contains( String upId, String... values )
{
    if ( Strings.isEmpty( upId ) )
    {
        return false;
    }

    String id = getId( upId );

    if ( schemaManager != null )
    {
        try
        {
            return contains( schemaManager.lookupAttributeTypeRegistry( id ), values );
        }
        catch ( LdapException le )
        {
            return false;
        }
    }

    Attribute attribute = attributes.get( id );

    if ( attribute == null )
    {
        return false;
    }

    return attribute.contains( values );
}
 
Example #23
Source File: DefaultConfigurableBinaryAttributeDetector.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void addBinaryAttribute( String... binaryAttributes )
{
    if ( binaryAttributes != null )
    {
        for ( String binaryAttribute : binaryAttributes )
        {
            String attrId = Strings.toLowerCaseAscii( binaryAttribute );
            this.binaryAttributes.add( attrId );
        }
    }
}
 
Example #24
Source File: ModifyDNResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with a (optional) Control element
 */
@Test
public void testResponseWith1Control()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( ModifyDNResponseTest.class.getResource( "response_with_1_control.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    ModifyDnResponse modifyDNResponse = ( ModifyDnResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = modifyDNResponse.getControls();

    assertEquals( 1, modifyDNResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertEquals( "Some text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #25
Source File: AdDirSyncResponseImpl.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setCookie( byte[] cookie )
{
    if ( cookie != null )
    {
        this.cookie = new byte[cookie.length];
        System.arraycopy( cookie, 0, this.cookie, 0, cookie.length );
    }
    else
    {
        this.cookie = Strings.EMPTY_BYTES;
    }
}
 
Example #26
Source File: ModifyRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a (optional) Control element with Base64 Value
 */
@Test
public void testRequestWith1ControlBase64Value()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( ModifyRequestTest.class.getResource( "request_with_1_control_base64_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = modifyRequest.getControls();

    assertEquals( 1, modifyRequest.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertEquals( "DSMLv2.0 rocks!!", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #27
Source File: AdDirSyncResponseControlTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdDirSyncControlNoCookie() throws DecoderException, EncoderException
{
    ByteBuffer bb = ByteBuffer.allocate( 0x0A );

    bb.put( new byte[]
        {
            0x30, 0x08,
              0x02, 0x01, 0x01,  // flag (LDAP_DIRSYNC_OBJECT_SECURITY)
              0x02, 0x01, 0x00,  // maxReturnLength (no limit)
              0x04, 0x00         // the cookie
        } );

    bb.flip();

    AdDirSyncResponseFactory factory = ( AdDirSyncResponseFactory ) codec.getResponseControlFactories().
        get( AdDirSyncResponse.OID );
    AdDirSyncResponse adDirSyncResponse = factory.newControl();
    factory.decodeValue( adDirSyncResponse, bb.array() );

    assertEquals( EnumSet.of( AdDirSyncResponseFlag.LDAP_DIRSYNC_OBJECT_SECURITY ), adDirSyncResponse.getFlags() );
    assertEquals( 0, adDirSyncResponse.getMaxReturnLength() );
    assertEquals( "", Strings.utf8ToString( adDirSyncResponse.getCookie() ) );

    // Check the reverse encoding
    Asn1Buffer asn1Buffer = new Asn1Buffer();

    factory.encodeValue( asn1Buffer, adDirSyncResponse );

    assertArrayEquals( bb.array(),  asn1Buffer.getBytes().array() );
}
 
Example #28
Source File: PasswordModifyRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test the decoding of a PasswordModifyRequest with a user identity
 */
@Test
public void testDecodePasswordModifyRequestUserIdentityValueOldPasswordValue() throws DecoderException
{
    byte[] bb = new byte[]
        { 
            0x30, 0x0C,                 // PasswordModifyRequest ::= SEQUENCE {
              ( byte ) 0x80, 0x04,      // userIdentity    [0]  OCTET STRING OPTIONAL
                'a', 'b', 'c', 'd',
              ( byte ) 0x81, 0x04,      // oldPassword    [1]  OCTET STRING OPTIONAL
                'e', 'f', 'g', 'h'
        };

    PasswordModifyFactory factory = ( PasswordModifyFactory ) codec.getExtendedRequestFactories().
        get( PasswordModifyRequest.EXTENSION_OID );
    PasswordModifyRequest passwordModifyRequest = ( PasswordModifyRequest ) factory.newRequest( bb );
    
    assertNotNull( passwordModifyRequest.getUserIdentity() );
    assertEquals( "abcd", Strings.utf8ToString( passwordModifyRequest.getUserIdentity() ) );
    assertNotNull( passwordModifyRequest.getOldPassword() );
    assertEquals( "efgh", Strings.utf8ToString( passwordModifyRequest.getOldPassword() ) );
    assertNull( passwordModifyRequest.getNewPassword() );

    // Check the reverse decoding
    Asn1Buffer asn1Buffer = new Asn1Buffer();

    factory.encodeValue( asn1Buffer, passwordModifyRequest );

    assertArrayEquals( bb,  asn1Buffer.getBytes().array() );
}
 
Example #29
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean contains( String upId, Value<?>... values )
{
    if ( Strings.isEmpty( upId ) )
    {
        return false;
    }

    String id = getId( upId );

    if ( schemaManager != null )
    {
        try
        {
            return contains( schemaManager.lookupAttributeTypeRegistry( id ), values );
        }
        catch ( LdapException le )
        {
            return false;
        }
    }

    Attribute attribute = attributes.get( id );

    if ( attribute == null )
    {
        return false;
    }

    return attribute.contains( values );
}
 
Example #30
Source File: BitStringSyntaxChecker.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isValidSyntax( Object value )
{
    String strValue;

    if ( value == null )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, "null" ) );
        }
        
        return false;
    }

    if ( value instanceof String )
    {
        strValue = ( String ) value;
    }
    else if ( value instanceof byte[] )
    {
        strValue = Strings.utf8ToString( ( byte[] ) value );
    }
    else
    {
        strValue = value.toString();
    }

    return isValid( strValue );
}