Java Code Examples for org.apache.directory.api.ldap.model.name.Dn#isValid()
The following examples show how to use
org.apache.directory.api.ldap.model.name.Dn#isValid() .
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: ProxiedAuthzImpl.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * The authzId syntax is given by the RFC 2829 : * * <pre> * authzId = dnAuthzId / uAuthzId / <empty> * dnAuthzId = "dn:" dn * dn = utf8string * uAuthzId = "u:" userid * userid = utf8string * </pre> * @param authzId the authzId to set */ @Override public void setAuthzId( String authzId ) { // We should have a valid authzId if ( authzId == null ) { throw new RuntimeException( I18n.err( I18n.ERR_13511_INVALID_PROXIED_AUTHZ_NULL ) ); } if ( !Strings.isEmpty( authzId ) ) { String lowercaseAuthzId = Strings.toLowerCaseAscii( authzId ); if ( lowercaseAuthzId.startsWith( "dn:" ) ) { String dn = authzId.substring( 3 ); if ( !Dn.isValid( dn ) ) { throw new RuntimeException( I18n.err( I18n.ERR_13512_INVALID_PROXIED_AUTHZ_BAD_DN ) ); } } else if ( !lowercaseAuthzId.startsWith( "u:" ) ) { throw new RuntimeException( I18n.err( I18n.ERR_13513_INVALID_PROXIED_AUTHZ_NO_DN_OR_U ) ); } } this.authzId = authzId; }
Example 2
Source File: LdifReader.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Parse the Dn of an entry * * @param line The line to parse * @return A Dn * @throws LdapLdifException If the Dn is invalid */ protected String parseDn( String line ) throws LdapLdifException { String dn; String lowerLine = Strings.toLowerCaseAscii( line ); if ( lowerLine.startsWith( "dn:" ) || lowerLine.startsWith( "Dn:" ) ) { // Ok, we have a Dn. Is it base 64 encoded ? int length = line.length(); if ( length == 3 ) { // The Dn is empty : it's a rootDSE dn = ""; } else if ( line.charAt( 3 ) == ':' ) { if ( length > 4 ) { // This is a base 64 encoded Dn. String trimmedLine = line.substring( 4 ).trim(); dn = Strings.utf8ToString( Base64.decode( trimmedLine.toCharArray() ) ); } else { // The Dn is empty : error LOG.error( I18n.err( I18n.ERR_13404_EMPTY_DN_NOT_ALLOWED, lineNumber ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13445_NO_DN ) ); } } else { dn = line.substring( 3 ).trim(); } } else { LOG.error( I18n.err( I18n.ERR_13405_DN_EXPECTED, lineNumber ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13445_NO_DN ) ); } // Check that the Dn is valid. If not, an exception will be thrown if ( validateDn && !Dn.isValid( dn ) ) { String message = I18n.err( I18n.ERR_13446_INVALID_DN, dn, lineNumber ); LOG.error( message ); throw new LdapLdifException( message ); } return dn; }
Example 3
Source File: DnSyntaxChecker.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * {@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(); } if ( strValue.length() == 0 ) { // TODO: this should be a false, but for // some reason, the principal is empty in // some cases. if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, value ) ); } return true; } // Check that the value is a valid Dn boolean result = Dn.isValid( strValue ); if ( LOG.isDebugEnabled() ) { if ( result ) { LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, value ) ); } else { LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) ); } } return result; }