From 63fd1ddc75155d02044a0970053d80b79fb80835 Mon Sep 17 00:00:00 2001 From: cosminghitea Date: Tue, 30 Jan 2018 11:22:44 +0200 Subject: [PATCH 1/8] Add the typescript files --- .gitignore | 4 + index.ts | 10 + ldapWrapTs/errors/error_dispenser.ts | 96 ++++ .../errors/ldap_errors/ldap_access_error.ts | 13 + .../ldap_errors/ldap_admin_limit_error.ts | 13 + .../ldap_errors/ldap_alias_deref_error.ts | 13 + .../errors/ldap_errors/ldap_alias_error.ts | 13 + .../ldap_errors/ldap_already_exists_error.ts | 13 + .../ldap_attribute_exists_error.ts | 13 + .../ldap_auth_method_unsupported.ts | 14 + .../errors/ldap_errors/ldap_busy_error.ts | 13 + .../ldap_errors/ldap_confidentiality_error.ts | 13 + .../ldap_errors/ldap_constraint_error.ts | 13 + .../errors/ldap_errors/ldap_dsas_error.ts | 13 + ldapWrapTs/errors/ldap_errors/ldap_error.ts | 12 + .../ldap_inappropriate_auth_error.ts | 15 + .../ldap_inappropriate_matching_error.ts | 14 + .../ldap_invalid_credentials_error.ts | 14 + .../ldap_errors/ldap_invalid_dn_error.ts | 13 + .../ldap_errors/ldap_invalid_syntax_error.ts | 13 + .../errors/ldap_errors/ldap_leaf_error.ts | 13 + .../errors/ldap_errors/ldap_loop_error.ts | 13 + .../errors/ldap_errors/ldap_naming_error.ts | 15 + .../ldap_no_such_attribute_error.ts | 13 + .../errors/ldap_errors/ldap_non_leaf_error.ts | 15 + .../ldap_errors/ldap_object_class_error.ts | 16 + .../ldap_object_class_mods_error.ts | 13 + .../ldap_object_not_found_error.ts | 13 + .../ldap_errors/ldap_operation_error.ts | 16 + .../errors/ldap_errors/ldap_other_error.ts | 13 + .../errors/ldap_errors/ldap_protocol_error.ts | 13 + .../errors/ldap_errors/ldap_rdn_error.ts | 13 + .../errors/ldap_errors/ldap_referral_error.ts | 14 + .../ldap_errors/ldap_sasl_bind_error.ts | 14 + .../ldap_errors/ldap_size_limit_error.ts | 14 + .../ldap_errors/ldap_strong_auth_error.ts | 16 + .../ldap_errors/ldap_time_limit_error.ts | 14 + .../ldap_unavailable_critical_ext.ts | 14 + .../ldap_errors/ldap_unavailable_error.ts | 13 + .../ldap_errors/ldap_undefined_type_error.ts | 13 + .../ldap_errors/ldap_unwilling_error.ts | 13 + ldapWrapTs/errors/ldap_errors/login_error.ts | 5 + .../errors/ldap_errors/operational_error.ts | 6 + ldapWrapTs/errors/ldap_errors/server_error.ts | 6 + ldapWrapTs/errors/state_error.ts | 9 + ldapWrapTs/errors/validation_error.ts | 15 + ldapWrapTs/ldap_async_wrap.ts | 461 ++++++++++++++++++ ldapWrapTs/messages.json | 23 + ldapWrapTs/messages.ts | 22 + ldapWrapTs/schemas/add_entry_schema.json | 18 + ldapWrapTs/schemas/add_entry_schema.ts | 4 + ldapWrapTs/schemas/change_schema.json | 23 + ldapWrapTs/schemas/change_schema.ts | 10 + ldapWrapTs/schemas/control_schema.json | 23 + ldapWrapTs/schemas/control_schema.ts | 5 + ldapWrapTs/schemas/update_attr_schema.json | 18 + ldapWrapTs/schemas/update_attr_schema.ts | 4 + ldapWrapTs/stream_interface.ts | 73 +++ ldapWrapTs/utils/check_variable_format.ts | 132 +++++ ldapWrapTs/utils/construct_ldif.ts | 70 +++ package.json | 19 +- tsconfig.json | 67 +++ tslint.json | 10 + 63 files changed, 1644 insertions(+), 5 deletions(-) create mode 100644 index.ts create mode 100644 ldapWrapTs/errors/error_dispenser.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_access_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_admin_limit_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_alias_deref_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_alias_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_already_exists_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_attribute_exists_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_auth_method_unsupported.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_busy_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_confidentiality_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_constraint_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_dsas_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_inappropriate_auth_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_inappropriate_matching_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_invalid_credentials_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_invalid_dn_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_invalid_syntax_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_leaf_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_loop_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_naming_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_no_such_attribute_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_non_leaf_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_object_class_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_object_class_mods_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_object_not_found_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_operation_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_other_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_protocol_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_rdn_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_referral_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_sasl_bind_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_size_limit_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_strong_auth_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_time_limit_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_unavailable_critical_ext.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_unavailable_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_undefined_type_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/ldap_unwilling_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/login_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/operational_error.ts create mode 100644 ldapWrapTs/errors/ldap_errors/server_error.ts create mode 100644 ldapWrapTs/errors/state_error.ts create mode 100644 ldapWrapTs/errors/validation_error.ts create mode 100644 ldapWrapTs/ldap_async_wrap.ts create mode 100644 ldapWrapTs/messages.json create mode 100644 ldapWrapTs/messages.ts create mode 100644 ldapWrapTs/schemas/add_entry_schema.json create mode 100644 ldapWrapTs/schemas/add_entry_schema.ts create mode 100644 ldapWrapTs/schemas/change_schema.json create mode 100644 ldapWrapTs/schemas/change_schema.ts create mode 100644 ldapWrapTs/schemas/control_schema.json create mode 100644 ldapWrapTs/schemas/control_schema.ts create mode 100644 ldapWrapTs/schemas/update_attr_schema.json create mode 100644 ldapWrapTs/schemas/update_attr_schema.ts create mode 100644 ldapWrapTs/stream_interface.ts create mode 100644 ldapWrapTs/utils/check_variable_format.ts create mode 100644 ldapWrapTs/utils/construct_ldif.ts create mode 100644 tsconfig.json create mode 100644 tslint.json diff --git a/.gitignore b/.gitignore index 570534b..cc6cab3 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ npm-debug.log **/npm-debug.log **/npm-debug.log* **/node_modules +**/docs .idea **/logs/*.log **/pids/*.pid @@ -22,6 +23,7 @@ static_server_npm_helper.pid */out **/.jscsrc **/.jshintrc +**/docs/* !**/docs/.gitkeep **/coverage/* !**/coverage/.gitkeep @@ -37,3 +39,5 @@ modify.ldif ./build/** .vscode/settings.json build/* +libBuildTLS/* +TSdeclaration/* diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..93f10c6 --- /dev/null +++ b/index.ts @@ -0,0 +1,10 @@ + +import * as LdapClient from './libs/ldap_async_wrap'; +import * as errorHandler from './ldapWrapTs/errors/error_dispenser'; +import * as errorList from './ldapWrapTs/errors/error_dispenser'; + +module.exports = { + Client: LdapClient, + errorHandler: errorHandler.errorSelection, + errorList: errorList.errors, +}; diff --git a/ldapWrapTs/errors/error_dispenser.ts b/ldapWrapTs/errors/error_dispenser.ts new file mode 100644 index 0000000..559180c --- /dev/null +++ b/ldapWrapTs/errors/error_dispenser.ts @@ -0,0 +1,96 @@ +import LdapInvalidDnError from './ldap_errors/ldap_invalid_dn_error'; +import LdapSizeLimitError from './ldap_errors/ldap_size_limit_error'; +import LdapTimeLimitError from './ldap_errors/ldap_time_limit_error'; +import LdapProtocolError from './ldap_errors/ldap_protocol_error'; +import LdapInvalidSyntaxError from './ldap_errors/ldap_invalid_syntax_error'; +import LdapOperationError from './ldap_errors/ldap_operation_error'; +import LdapAuthUnsupportedError from './ldap_errors/ldap_auth_method_unsupported'; +import LdapStrongAuthError from './ldap_errors/ldap_strong_auth_error'; +import LdapReferralError from './ldap_errors/ldap_referral_error'; +import LdapAdminLimitError from './ldap_errors/ldap_admin_limit_error'; +import LdapCriticalExtensionError from './ldap_errors/ldap_unavailable_critical_ext'; +import LdapConfidentialityError from './ldap_errors/ldap_confidentiality_error'; +import LdapSaslBindError from './ldap_errors/ldap_sasl_bind_error'; +import LdapNoSuchAttribute from './ldap_errors/ldap_no_such_attribute_error'; +import LdapUndefinedTypeError from './ldap_errors/ldap_undefined_type_error'; +import LdapMatchingError from './ldap_errors/ldap_inappropriate_matching_error'; +import LdapConstraintError from './ldap_errors/ldap_constraint_error'; +import LdapTypeOrValueAlreadyExistsError from './ldap_errors/ldap_attribute_exists_error'; +import LdapNoSuchObjectError from './ldap_errors/ldap_object_not_found_error'; +import LdapAliasError from './ldap_errors/ldap_alias_error'; +import LdapLeafError from './ldap_errors/ldap_leaf_error'; +import LdapAliasDerefError from './ldap_errors/ldap_alias_deref_error'; +import LdapInappropriateAuthError from './ldap_errors/ldap_inappropriate_auth_error'; +import LdapCredentialsError from './ldap_errors/ldap_invalid_credentials_error'; +import LdapAccessError from './ldap_errors/ldap_access_error'; +import LdapBusyError from './ldap_errors/ldap_busy_error'; +import LdapUnavailable from './ldap_errors/ldap_unavailable_error'; +import LdapUnWillingError from './ldap_errors/ldap_unwilling_error'; +import LdapLoopError from './ldap_errors/ldap_loop_error'; +import LdapNamingError from './ldap_errors/ldap_naming_error'; +import LdapObjectClassError from './ldap_errors/ldap_object_class_error'; +import LdapNonLeafError from './ldap_errors/ldap_non_leaf_error'; +import LdapRdnError from './ldap_errors/ldap_rdn_error'; +import LdapAlreadyExists from './ldap_errors/ldap_already_exists_error'; +import LdapClassModsError from './ldap_errors/ldap_object_class_mods_error'; +import LdapDsasError from './ldap_errors/ldap_dsas_error'; +import LdapOtherError from './ldap_errors/ldap_other_error'; + +export const errors: any = { + LdapInvalidDnError: (LdapInvalidDnError), + LdapSizeLimitError: (LdapSizeLimitError), + LdapTimeLimitError: (LdapTimeLimitError), + LdapProtocolError: (LdapProtocolError), + LdapInvalidSyntaxError: (LdapInvalidSyntaxError), + LdapOperationError: (LdapOperationError), + LdapAuthUnsupportedError: (LdapAuthUnsupportedError), + LdapStrongAuthError: (LdapStrongAuthError), + LdapReferralError: (LdapReferralError), + LdapAdminLimitError: (LdapAdminLimitError), + LdapCriticalExtensionError: (LdapCriticalExtensionError), + LdapConfidentialityError: (LdapConfidentialityError), + LdapSaslBindError: (LdapSaslBindError), + LdapNoSuchAttribute: (LdapNoSuchAttribute), + LdapUndefinedTypeError: (LdapUndefinedTypeError), + LdapMatchingError: (LdapMatchingError), + LdapConstraintError: (LdapConstraintError), + LdapTypeOrValueAlreadyExistsError: (LdapTypeOrValueAlreadyExistsError), + LdapNoSuchObjectError: (LdapNoSuchObjectError), + LdapAliasError: (LdapAliasError), + LdapLeafError: (LdapLeafError), + LdapAliasDerefError: (LdapAliasDerefError), + LdapInappropriateAuthError: (LdapInappropriateAuthError), + LdapCredentialsError: (LdapCredentialsError), + LdapAccessError: (LdapAccessError), + LdapBusyError: (LdapBusyError), + LdapUnavailable: (LdapUnavailable), + LdapUnWillingError: (LdapUnWillingError), + LdapLoopError: (LdapLoopError), + LdapNamingError: (LdapNamingError), + LdapObjectClassError: (LdapObjectClassError), + LdapNonLeafError: (LdapNonLeafError), + LdapRdnError: (LdapRdnError), + LdapAlreadyExists: (LdapAlreadyExists), + LdapClassModsError: (LdapClassModsError), + LdapDsasError: (LdapDsasError), + LdapOtherError: (LdapOtherError), +}; +/** + * Function that returns the error class corresponding to the LDAP error code. + * @param {Number} code Ldap error code ranging from 1 to 80 or negative for API errors. + * @return {Error} DesiredErrorClass Custom error class corresponding to the ldap error code. + */ +export function errorSelection(code: number): Error { + + const foundErrorClassKey: string | undefined = Object.keys(errors) + .find(key => { + const classCandidate = errors[key]; + return code === classCandidate.code; + }); + + const desiredErrorClass: Error = foundErrorClassKey === undefined + ? LdapOtherError + : errors[foundErrorClassKey]; + + return desiredErrorClass; +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_access_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_access_error.ts new file mode 100644 index 0000000..7975396 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_access_error.ts @@ -0,0 +1,13 @@ +import LoginError from './login_error'; + +export default class LdapAccessError extends LoginError { + + static get code(): number { + return 50; + } + + static get description(): string { + return 'Indicates that the caller does not have sufficient rights to perform the requested operation.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_admin_limit_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_admin_limit_error.ts new file mode 100644 index 0000000..4730f6f --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_admin_limit_error.ts @@ -0,0 +1,13 @@ +import ServerError from './server_error'; + +export default class LdapAdminLimitError extends ServerError { + + static get code(): number { + return 11; + } + + static get description(): string { + return 'Indicates that an LDAP server limit set by an administrative authority has been exceeded.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_alias_deref_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_alias_deref_error.ts new file mode 100644 index 0000000..4acdac7 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_alias_deref_error.ts @@ -0,0 +1,13 @@ +import ServerError from './server_error'; + +export default class LdapAliasDerefError extends ServerError { + + static get code(): number { + return 36; + } + + static get description(): string { + return 'Indicates that during a search operation, either the client does not have access rights to read the aliased object\'s name or dereferencing is not allowed.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_alias_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_alias_error.ts new file mode 100644 index 0000000..53f94cf --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_alias_error.ts @@ -0,0 +1,13 @@ +import ServerError from './server_error'; + +export default class LdapAliasError extends ServerError { + + static get code(): number { + return 33; + } + + static get description(): string { + return 'Indicates that an error occurred when an alias was dereferenced.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_already_exists_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_already_exists_error.ts new file mode 100644 index 0000000..5cd4f9f --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_already_exists_error.ts @@ -0,0 +1,13 @@ +import OperationalError from './operational_error'; + +export default class LdapAlreadyExistsError extends OperationalError { + + static get code(): number { + return 68; + } + + static get description(): string { + return 'Indicates that the add operation attempted to add an entry that already exists, or that the modify operation attempted to rename an entry to the name of an entry that already exists.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_attribute_exists_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_attribute_exists_error.ts new file mode 100644 index 0000000..52f12d0 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_attribute_exists_error.ts @@ -0,0 +1,13 @@ +import OperationalError from './operational_error'; + +export default class LdapAttributeExists extends OperationalError { + + static get code(): number { + return 20; + } + + static get description(): string { + return 'Indicates that the attribute value specified in a modify or add operation already exists as a value for that attribute.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_auth_method_unsupported.ts b/ldapWrapTs/errors/ldap_errors/ldap_auth_method_unsupported.ts new file mode 100644 index 0000000..83049d2 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_auth_method_unsupported.ts @@ -0,0 +1,14 @@ +import LoginError from './login_error'; + +export default class LdapAuthError extends LoginError { + + static get code(): number { + return 7; + } + + static get description(): string { + return 'Indicates that during a bind operation the client requested ' + + ' an authentication method not supported by the LDAP server.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_busy_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_busy_error.ts new file mode 100644 index 0000000..50a221e --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_busy_error.ts @@ -0,0 +1,13 @@ +import ServerError from './server_error'; + +export default class LdapBusyError extends ServerError { + + static get code(): number { + return 51; + } + + static get description(): string { + return 'Indicates that the LDAP server is too busy to process the client request at this time but if the client waits and resubmits the request, the server may be able to process it then.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_confidentiality_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_confidentiality_error.ts new file mode 100644 index 0000000..6fbf1e8 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_confidentiality_error.ts @@ -0,0 +1,13 @@ +import LdapError from './ldap_error'; + +export default class LdapConfidentialityError extends LdapError { + + static get code(): number { + return 13; + } + + static get description(): string { + return 'Indicates that the session is not protected by a protocol such as Transport Layer Security (TLS), which provides session confidentiality.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_constraint_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_constraint_error.ts new file mode 100644 index 0000000..eaa0582 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_constraint_error.ts @@ -0,0 +1,13 @@ +import OperationalError from './operational_error'; + +export default class LdapConstraintError extends OperationalError { + + static get code(): number { + return 19; + } + + static get description(): string { + return 'Indicates that the attribute value specified in a modify, add, or modify DN operation violates constraints placed on the attribute. The constraint can be one of size or content (string only, no binary).'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_dsas_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_dsas_error.ts new file mode 100644 index 0000000..9d25839 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_dsas_error.ts @@ -0,0 +1,13 @@ +import OperationalError from './operational_error'; + +export default class LdapDsasError extends OperationalError { + + static get code(): number { + return 71; + } + + static get description(): string { + return 'Indicates that the modify DN operation moves the entry from one LDAP server to another and requires more than one LDAP server.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_error.ts new file mode 100644 index 0000000..c94a593 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_error.ts @@ -0,0 +1,12 @@ +export default class LdapError extends Error { + + message:string; + name:string; + constructor(message:string) { + super(message); + this.message = message; + this.name = this.constructor.name; + Error.captureStackTrace(this, (this).constructor.name); + } + +} \ No newline at end of file diff --git a/ldapWrapTs/errors/ldap_errors/ldap_inappropriate_auth_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_inappropriate_auth_error.ts new file mode 100644 index 0000000..360261a --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_inappropriate_auth_error.ts @@ -0,0 +1,15 @@ +import LoginError from'./login_error'; + +export default class LdapInappropriateAuthError extends LoginError { + + static get code(): number { + return 48; + } + + static get description(): string { + return 'Indicates that during a bind operation, the client is attempting to use an authentication method that the client cannot use correctly.' + + ' For example, either of the following cause this error: The client returns simple credentials when strong credentials are required' + + '...OR...The client returns a DN and a password for a simple bind when the entry does not have a password defined.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_inappropriate_matching_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_inappropriate_matching_error.ts new file mode 100644 index 0000000..7fc608b --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_inappropriate_matching_error.ts @@ -0,0 +1,14 @@ +import OperationalError from './operational_error'; + + +export default class LdapMatchingError extends OperationalError { + + static get code(): number { + return 18; + } + + static get description(): string { + return 'Indicates that the matching rule specified in the search filter does not match a rule defined for the attribute\'s syntax.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_invalid_credentials_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_invalid_credentials_error.ts new file mode 100644 index 0000000..917c774 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_invalid_credentials_error.ts @@ -0,0 +1,14 @@ +import LoginError from './login_error'; + +export default class LdapCredentialsError extends LoginError { + + static get code(): number { + return 49; + } + + static get description(): string { + return 'Indicates that during a bind operation one of the following occurred: The client passed either an incorrect DN or password,' + + ' or the password is incorrect because it has expired, intruder detection has locked the account, or another similar reason. See the data code for more information.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_invalid_dn_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_invalid_dn_error.ts new file mode 100644 index 0000000..a71b387 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_invalid_dn_error.ts @@ -0,0 +1,13 @@ +import OperationalError from './operational_error'; + +export default class LdapInvalidDnError extends OperationalError { + + static get code(): number { + return 34; + } + + static get description(): string { + return 'Indicates that the syntax of the DN is incorrect. (If the DN syntax is correct, but the LDAP server\'s structure rules do not permit the operation, the server returns LDAP_UNWILLING_TO_PERFORM.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_invalid_syntax_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_invalid_syntax_error.ts new file mode 100644 index 0000000..39bcbcd --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_invalid_syntax_error.ts @@ -0,0 +1,13 @@ +import OperationalError from './operational_error'; + +export default class LdapInvalidSyntaxError extends OperationalError { + + static get code(): number { + return 21; + } + + static get description(): string { + return 'Indicates that the attribute value specified in an add, compare, or modify operation is an unrecognized or invalid syntax for the attribute.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_leaf_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_leaf_error.ts new file mode 100644 index 0000000..84e4565 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_leaf_error.ts @@ -0,0 +1,13 @@ +import OperationalError from './operational_error'; + +export default class LdapLeafError extends OperationalError { + + static get code(): number { + return 35; + } + + static get description(): string { + return 'Indicates that the specified operation cannot be performed on a leaf entry. (This code is not currently in the LDAP specifications, but is reserved for this constant.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_loop_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_loop_error.ts new file mode 100644 index 0000000..5eaf275 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_loop_error.ts @@ -0,0 +1,13 @@ +import ServerError from './server_error'; + +export default class LdapLoopError extends ServerError { + + static get code(): number { + return 54; + } + + static get description(): string { + return 'Indicates that the client discovered an alias or referral loop, and is thus unable to complete this request.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_naming_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_naming_error.ts new file mode 100644 index 0000000..fa64d57 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_naming_error.ts @@ -0,0 +1,15 @@ +import OperationalError from './operational_error'; + +export default class LdapNamingError extends OperationalError { + + static get code(): number { + return 64; + } + + static get description(): string { + return 'Indicates that the add or modify DN operation violates the schema\'s structure rules.' + + ' For example,the request places the entry subordinate to an alias.' + + ' The request places the entry subordinate to a container that is forbidden by the containment rules. The RDN for the entry uses a forbidden attribute type.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_no_such_attribute_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_no_such_attribute_error.ts new file mode 100644 index 0000000..e75fb56 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_no_such_attribute_error.ts @@ -0,0 +1,13 @@ +import OperationalError from './operational_error'; + +export default class LdapNoSuchAttributeError extends OperationalError { + + static get code(): number { + return 16; + } + + static get description(): string { + return 'Indicates that the attribute specified in the modify or compare operation does not exist in the entry.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_non_leaf_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_non_leaf_error.ts new file mode 100644 index 0000000..bd2989b --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_non_leaf_error.ts @@ -0,0 +1,15 @@ +import OperationalError from './operational_error'; + +export default class LdapNonLeafError extends OperationalError { + + static get code(): number { + return 66; + } + + static get description(): string { + return 'Indicates that the requested operation is permitted only on leaf entries.' + + ' For example, the following types of requests return this error:The client requests a delete operation on a parent entry.' + + ' The client request a modify DN operation on a parent entry.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_object_class_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_object_class_error.ts new file mode 100644 index 0000000..4d2ae6d --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_object_class_error.ts @@ -0,0 +1,16 @@ +import OperationalError from './operational_error'; + +export default class LdapObjectClassError extends OperationalError { + + static get code(): number { + return 65; + } + + static get description(): string { + return 'Indicates that the add, modify, or modify DN operation violates the object class rules for the entry.' + + ' For example, the following types of request return this error: The add or modify operation tries to add an entry without a value for a required attribute.' + + ' The add or modify operation tries to add an entry with a value for an attribute which the class definition does not contain.' + + ' The modify operation tries to remove a required attribute without removing the auxiliary class that defines the attribute as required.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_object_class_mods_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_object_class_mods_error.ts new file mode 100644 index 0000000..4be04d8 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_object_class_mods_error.ts @@ -0,0 +1,13 @@ +import OperationalError from './operational_error'; + +export default class LdapObjectClassModsError extends OperationalError { + + static get code(): number { + return 69; + } + + static get description(): string { + return 'Indicates that the modify operation attempted to modify the structure rules of an object class.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_object_not_found_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_object_not_found_error.ts new file mode 100644 index 0000000..10d0c55 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_object_not_found_error.ts @@ -0,0 +1,13 @@ +import OperationalError from './operational_error'; + +export default class LdapNotFoundError extends OperationalError { + + static get code(): number { + return 32; + } + + static get description(): string { + return 'Indicates the target object cannot be found. This code is not returned on following operations: Search operations that find the search base but cannot find any entries that match the search filter. Bind operations.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_operation_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_operation_error.ts new file mode 100644 index 0000000..2d4c290 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_operation_error.ts @@ -0,0 +1,16 @@ +import LdapError from './ldap_error'; + +export default class LdapOperationError extends LdapError { + + static get code(): number { + return 1; + } + + static get description(): string { + return 'Indicates an internal error. The server is unable to respond with a more specific error and is also unable to properly respond to a request.' + + ' It does not indicate that the client has sent an erroneous message.' + + ' In NDS 8.3x through NDS 7.xx, this was the default error for NDS errors that did not map to an LDAP error code.' + + ' To conform to the new LDAP drafts, NDS 8.5 uses 80 (0x50) for such errors.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_other_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_other_error.ts new file mode 100644 index 0000000..ea18dcb --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_other_error.ts @@ -0,0 +1,13 @@ +import LdapError from './ldap_error'; + +export default class LdapOtherError extends LdapError { + + static get code(): number { + return 80; + } + + static get description(): string { + return 'Indicates an unknown error condition. This is the default value for NDS error codes which do not map to other LDAP error codes.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_protocol_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_protocol_error.ts new file mode 100644 index 0000000..12e4751 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_protocol_error.ts @@ -0,0 +1,13 @@ +import OperationalError from './operational_error'; + +export default class LdapProtocolError extends OperationalError { + + static get code(): number { + return 2; + } + + static get description(): string { + return 'Indicates that the server has received an invalid or malformed request from the client.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_rdn_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_rdn_error.ts new file mode 100644 index 0000000..d8a3024 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_rdn_error.ts @@ -0,0 +1,13 @@ +import OperationalError from './operational_error'; + +export default class LdapRdnError extends OperationalError { + + static get code(): number { + return 67; + } + + static get description(): string { + return 'Indicates that the modify operation attempted to remove an attribute value that forms the entry\'s relative distinguished name.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_referral_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_referral_error.ts new file mode 100644 index 0000000..1e87692 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_referral_error.ts @@ -0,0 +1,14 @@ +import LdapError from './ldap_error'; + +export default class LdapReferralError extends LdapError { + + static get code(): number { + return 10; + } + + static get description(): string { + return 'Does not indicate an error condition. In LDAPv3, indicates that the server' + + ' does not hold the target entry of the request, but that the servers in the referral field may.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_sasl_bind_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_sasl_bind_error.ts new file mode 100644 index 0000000..7750c17 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_sasl_bind_error.ts @@ -0,0 +1,14 @@ +import LdapError from './ldap_error'; + +export default class LdapBindInProgressError extends LdapError { + + static get code(): number { + return 14; + } + + static get description(): string { + return 'Does not indicate an error condition, but indicates that the server is ready for the next step in the process.' + + ' The client must send the server the same SASL mechanism to continue the process.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_size_limit_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_size_limit_error.ts new file mode 100644 index 0000000..65780ce --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_size_limit_error.ts @@ -0,0 +1,14 @@ +import OperationalError from './operational_error'; + +export default class LdapSizeLimitError extends OperationalError { + + static get code(): number { + return 4; + } + + static get description(): string { + return 'Indicates that in a search operation, the size limit specified by the client or the server' + + ' has been exceeded. Incomplete results are returned.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_strong_auth_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_strong_auth_error.ts new file mode 100644 index 0000000..5fd9677 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_strong_auth_error.ts @@ -0,0 +1,16 @@ +import LoginError from './login_error'; + +export default class LdapStrongAuthRequired extends LoginError { + + static get code(): number { + return 8; + } + + static get description(): string { + return 'Indicates one of the following: In bind requests, the LDAP server accepts only strong authentication.' + + ' In a client request, the client requested an operation such as delete that requires strong authentication.' + + ' In an unsolicited notice of disconnection, the LDAP server discovers the security protecting the communication' + + ' between the client and server has unexpectedly failed or been compromised.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_time_limit_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_time_limit_error.ts new file mode 100644 index 0000000..907292d --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_time_limit_error.ts @@ -0,0 +1,14 @@ +import OperationalError from './operational_error'; + +export default class LdapTimeLimitError extends OperationalError { + + static get code(): number { + return 3; + } + + static get description(): string { + return 'Indicates that the operation\'s time limit specified by either the client or the server' + + ' has been exceeded. On search operations, incomplete results are returned.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_unavailable_critical_ext.ts b/ldapWrapTs/errors/ldap_errors/ldap_unavailable_critical_ext.ts new file mode 100644 index 0000000..3577b52 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_unavailable_critical_ext.ts @@ -0,0 +1,14 @@ +import ServerError from './server_error'; + +export default class LdapCriticalExtensionError extends ServerError { + + static get code(): number { + return 12; + } + + static get description(): string { + return 'Indicates that the LDAP server was unable to satisfy a request because one or more critical' + + ' extensions were not available. Either the server does not support the control or the control is not appropriate for the operation type.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_unavailable_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_unavailable_error.ts new file mode 100644 index 0000000..efc3097 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_unavailable_error.ts @@ -0,0 +1,13 @@ +import ServerError from './server_error'; + +export default class LdapUnavailableError extends ServerError { + + static get code(): number { + return 52; + } + + static get description(): string { + return 'Indicates that the LDAP server cannot process the client\'s bind request, usually because it is shutting down.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_undefined_type_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_undefined_type_error.ts new file mode 100644 index 0000000..003a373 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_undefined_type_error.ts @@ -0,0 +1,13 @@ +import OperationalError from './operational_error'; + +export default class LdapUndefinedTypeError extends OperationalError { + + static get code(): number { + return 17; + } + + static get description(): string { + return 'Indicates that the attribute specified in the modify or add operation does not exist in the LDAP server\'s schema.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_unwilling_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_unwilling_error.ts new file mode 100644 index 0000000..b5957d0 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/ldap_unwilling_error.ts @@ -0,0 +1,13 @@ +import ServerError from './server_error'; + +export default class LdapUnwillingError extends ServerError { + + static get code(): number { + return 53; + } + + static get description(): string { + return 'Indicates that the LDAP server cannot process the client\'s bind request, usually because it is shutting down.'; + } + +} diff --git a/ldapWrapTs/errors/ldap_errors/login_error.ts b/ldapWrapTs/errors/ldap_errors/login_error.ts new file mode 100644 index 0000000..2cc70cf --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/login_error.ts @@ -0,0 +1,5 @@ +import LdapError from './ldap_error'; + +export default class LoginError extends LdapError { + +} diff --git a/ldapWrapTs/errors/ldap_errors/operational_error.ts b/ldapWrapTs/errors/ldap_errors/operational_error.ts new file mode 100644 index 0000000..616bc25 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/operational_error.ts @@ -0,0 +1,6 @@ +import LdapError from './ldap_error'; + +export default class OperationalError extends LdapError { + + +} diff --git a/ldapWrapTs/errors/ldap_errors/server_error.ts b/ldapWrapTs/errors/ldap_errors/server_error.ts new file mode 100644 index 0000000..e2abd01 --- /dev/null +++ b/ldapWrapTs/errors/ldap_errors/server_error.ts @@ -0,0 +1,6 @@ +import LdapError from './ldap_error'; + +export default class ServerError extends LdapError { + + +} diff --git a/ldapWrapTs/errors/state_error.ts b/ldapWrapTs/errors/state_error.ts new file mode 100644 index 0000000..e6f4c51 --- /dev/null +++ b/ldapWrapTs/errors/state_error.ts @@ -0,0 +1,9 @@ +export default class StateError extends Error { + + constructor(message: string) { + super(message); + Error.captureStackTrace(this, this.constructor); + this.name = this.constructor.name; + } + +} diff --git a/ldapWrapTs/errors/validation_error.ts b/ldapWrapTs/errors/validation_error.ts new file mode 100644 index 0000000..b39fdf8 --- /dev/null +++ b/ldapWrapTs/errors/validation_error.ts @@ -0,0 +1,15 @@ +import { ErrorObject } from 'ajv'; + +export default class ValidationError extends Error { + + error: Error | ErrorObject[] | undefined; + + constructor(message: string, error: Error | undefined ,errors: ErrorObject[] | undefined) { + super(message); + Error.captureStackTrace(this, this.constructor); + this.name = this.constructor.name; + this.error = error || errors; + } + +} + diff --git a/ldapWrapTs/ldap_async_wrap.ts b/ldapWrapTs/ldap_async_wrap.ts new file mode 100644 index 0000000..ddc3f09 --- /dev/null +++ b/ldapWrapTs/ldap_async_wrap.ts @@ -0,0 +1,461 @@ +import * as path from 'path'; +import * as Promise from 'bluebird'; +import * as _ from 'underscore'; + +import checkParameters from './utils/check_variable_format'; + +import SearchStream from './stream_interface'; +import StateError from './errors/state_error'; +import ldifConstruct, { IldifObject } from './utils/construct_ldif'; +import { RootObject } from './messages'; +import { IchangeSchema } from './schemas/change_schema'; +import { IcontrolSchema } from './schemas/control_schema'; +import { IaddEntrySchema } from './schemas/add_entry_schema'; + +import * as errorHandler from './errors/error_dispenser'; + +const ldif: any = require('ldif'); +const errorMessages: RootObject = require('./messages.json'); +const binary: any = require('node-pre-gyp'); +const bindingPath: string = binary.find(path.resolve(path.join(__dirname, '../package.json'))); +const binding = require(bindingPath); + +interface IObjectEState { + CREATED: number; + INITIALIZED: number; + BOUND: number; + UNBOUND: number; + [key: string]: number; +} + +interface IObjectScopeObject { + BASE: number; + ONE: number; + SUBTREE: number; + [key: string]: number; +} + +const E_STATES: IObjectEState = { + CREATED: 0, + INITIALIZED: 1, + BOUND: 2, + UNBOUND: 5, +}; + +const scopeObject: IObjectScopeObject = { + BASE: 0, + ONE: 1, + SUBTREE: 2, +}; + +/** + * @module LDAPTransition + * @class LDAPAsyncWrap + */ + +export default class LDAPAsyncWrap { + private _hostAddress: string; + _binding = new binding.LDAPClient(); + _stateClient: number; + _searchID: number; + constructor(public host: string) { + this._hostAddress = host; + this._stateClient = E_STATES.CREATED; + } + + /** + * Initialize to an LDAP server. + * + * @method initialize + * @return {Promise} That resolves if ldap_initialize succeeds + ** Rejects if client was not created or ldap_initialize fails. + * */ + + initialize(): Promise { + return new Promise((resolve, reject) => { + if (this._stateClient === E_STATES.CREATED) { + this._binding.initialize(this._hostAddress, (err: number) => { + if (err) { + const customError: any = errorHandler.errorSelection(err); + reject(new customError(errorMessages.ldapInitializeErrorMessage)); + } else { + this._stateClient = E_STATES.INITIALIZED; + resolve(); + } + }); + } else { + reject(new StateError(errorMessages.initErrorMessage)); + } + }); + } + + + /** + * Initiate a TLS processing on an LDAP session. + * + * @method startTLS + * @param {String} pathToCertFile The path to the certificate can be optional + * @return {Promise} Will reject if state is not Initialized or if the + * certificate is not good else will resolve If the certificate is not + * specified then the client will use the server certificate + * */ + + startTLS(pathToCertFile: string): Promise { + return new Promise((resolve, reject) => { + if (this._stateClient === E_STATES.INITIALIZED) { + const pathCert = pathToCertFile === undefined ? '' : pathToCertFile; + this._binding.startTls(pathCert, (err: number) => { + if (err) { + const customError: any = errorHandler.errorSelection(err); + reject(new customError(errorMessages.ldapStartTlsErrorMessage)); + } else { + resolve(); + } + }); + } else { + reject(new StateError(errorMessages.initErrorMessage)); + } + }); + } + + /** + * Authenticate to LDAP server. + * + * @method bind + * @param {String} bindDn The client user DN. + * @param {String} passwordUser The client's password. + * @return {Promise} That resolves if the credentials are correct. + * Rejects if dn or password are incorrect or the client did not initialize. + * */ + + bind(bindDn: string, passwordUser: string): Promise { + return new Promise((resolve, reject) => { + if (this._stateClient === E_STATES.INITIALIZED) { + this._binding.bind(bindDn, passwordUser, (err: number) => { + if (err) { + const customError: any = errorHandler.errorSelection(err); + this._stateClient = E_STATES.INITIALIZED; + reject(new customError(errorMessages.ldapBindErrorMessage)); + } else { + this._stateClient = E_STATES.BOUND; + resolve(); + } + }); + } else { + reject(new StateError(errorMessages.uninitializedErrorMessage)); + } + }); + } + + /** + * Search operation. + * + * @method search + * @param {String} searchBase the base for the search. + * @param {String} scope scope for the search, can be BASE, ONE or + * SUBTREE + * @param {String} searchFilter search filter.If not provided, + * the default filter, (objectClass=*), is used. + * @return {Promise} That resolves and returns a string with the search + * results. Rejects in case of error. + * */ + search(searchBase: string, scope: string, searchFilter: string): Promise { + return new Promise((resolve, reject) => { + if (this._stateClient !== E_STATES.BOUND) { + reject(new StateError(errorMessages.bindErrorMessage)); + } else { + checkParameters.validateStrings(searchBase, searchFilter, scope); + + if (scopeObject[scope] === undefined) { + throw new Error(errorMessages.scopeSearchErrorMessage); + } + + this._binding.search( + searchBase, scopeObject[scope], searchFilter, (err: number, result: string) => { + if (err) { + const customError: any = errorHandler.errorSelection(err); + reject(new customError(errorMessages.ldapSearchErrorMessage)); + } else { + let resJSON: string | JSON | IldifObject; + try { + resJSON = result === '' ? result : ldif.parse(result); + } catch (ldifErr) { + resJSON = ldifConstruct(result); + } + resolve(resJSON); + } + }); + } + }); + } + + /** + * Search operation with results displayed page by page. + * + * @method pagedSearch + * @param {String} searchBase the base for the search. + * @param {String} scope scope for the search, can be BASE, ONE or + * SUBTREE + * @param {String} searchFilter search filter. + * @param {int} pageSize The number of entries per LDAP page + * @return {Promise} that resolves to a readable stream or rejects to a + * Error; + */ + pagedSearch(searchBase: string, scope: string, searchFilter: string, pageSize: number) + : Promise { + return new Promise((resolve, reject) => { + if (this._stateClient === E_STATES.BOUND) { + checkParameters.validateStrings(searchBase, searchFilter, scope); + + if (scopeObject[scope] === undefined) { + throw new Error(errorMessages.scopeSearchErrorMessage); + } + + if (!_.isNumber(pageSize)) { + throw new TypeError(errorMessages.typeErrorMessage); + } + this._searchID += 1; + resolve( + new SearchStream( + searchBase, scopeObject[scope], searchFilter, pageSize, + this._searchID, this._binding)); + } + reject(new StateError(errorMessages.bindErrorMessage)); + }); + } + + + /** + * Compare operation. + * + * @method compare + * @param {String} dn The dn of the entry to compare. + * @param {String} attr The attribute given for comparison. + * @param {String} value Value sent to compare. + * @return {Promise} That resolves and returns True if the elements are + * equal + * or + * False otherwise. + * Rejects if an error occurs. + */ + + compare(dn: string, attr: string, value: string): Promise { + const LDAP_COMPARE_TRUE: number = 6; + return new Promise((resolve, reject) => { + if (this._stateClient !== E_STATES.BOUND) { + reject(new StateError(errorMessages.bindErrorMessage)); + } else { + checkParameters.validateStrings(dn, attr, value); + + this._binding.compare(dn, attr, value, (err: number, result: number) => { + if (err) { + const customError: any = errorHandler.errorSelection(err); + reject(new customError(errorMessages.ldapCompareErrorMessage)); + } else { + const res: boolean = result === LDAP_COMPARE_TRUE; + resolve(res); + } + }); + } + }); + } + + /** + * Perform an LDAP modify operation + * + * @method modify + * @param {String} dn The dn of the entry to modify + * @param {IchangeSchema} jsonChange The attribute and value to be changed + * @param {IcontrolSchema} [controls] Request to execute a specific control + * or + * multiple controls. This parameter is optional. + * @return {Promise} That resolves if LDAP modified successfully the + * entry. + * Reject if LDAP rejects the operation or the client's state is not + * BOUND + */ + modify(dn: string, jsonChange: IchangeSchema, controls: IcontrolSchema) + : Promise { + return new Promise((resolve, reject) => { + if (this._stateClient !== E_STATES.BOUND) { + reject(new StateError(errorMessages.bindErrorMessage)); + } else { + checkParameters.validateStrings(dn); + const changes: object[] = checkParameters.checkModifyChange(jsonChange); + const ctrls: object[] | null = checkParameters.checkControl(controls); + + this._binding.modify(dn, changes, ctrls, (err: number, result: string | number) => { + if (err) { + const customError: any = errorHandler.errorSelection(err); + reject(new customError(errorMessages.ldapModifyErrorMessage)); + } else { + const resJSON: string | number = result === 0 ? result : ldif.parse(result); + resolve(resJSON); + } + }); + } + }); + } + + /** + * Perform an LDAP rename operation + * + * @method rename + * @param {String} dn The dn of the entry to rename + * @param {String} newRdn The new rdn for the dn + * @param {String} newParent New parent for the rdn + * @param {IcontrolSchema} [controls] Request to execute a specific control + * or + * multiple controls. This parameter is optional. + * @return {Promise} Will fulfil with a result from a control if the + * operation is successful, else will reject with an LDAP error number. + * */ + rename(dn: string, newRdn: string, newParent: string, controls: IcontrolSchema) + : Promise { + return new Promise((resolve, reject) => { + if (this._stateClient !== E_STATES.BOUND) { + reject(new StateError(errorMessages.bindErrorMessage)); + } else { + checkParameters.validateStrings(dn, newRdn, newParent); + const ctrls: object[] | null = checkParameters.checkControl(controls); + + this._binding.rename(dn, newRdn, newParent, ctrls, (err:number, result:string | number) => { + if (err) { + const customError: any = errorHandler.errorSelection(err); + reject(new customError(errorMessages.ldapRenameErrorMessage)); + } else { + const resJSON: string | number = result === 0 ? result : ldif.parse(result); + resolve(resJSON); + } + }); + } + }); + } + + /** + * Perform an LDAP delete operation + * + * @method delete + * @param {String} dn the dn entry to be deleted. + * @param {IcontrolSchema} [controls] Request to execute a specific control + * or + * multiple controls. This parameter is optional. + * @return {Promise} promise that resolves if the element provided was + * deleted + * or rejects if not. + * */ + delete(dn: string, controls: IcontrolSchema): Promise { + return new Promise((resolve, reject) => { + if (this._stateClient !== E_STATES.BOUND) { + reject(new StateError(errorMessages.bindErrorMessage)); + } else { + checkParameters.validateStrings(dn); + const ctrls: object[] | null = checkParameters.checkControl(controls); + + this._binding.delete(dn, ctrls, (err: number, result: string | number) => { + if (err) { + const customError: any = errorHandler.errorSelection(err); + reject(new customError(errorMessages.ldapDeleteErrorMessage)); + } else { + const resJSON: string | number = result === 0 ? result : ldif.parse(result); + resolve(resJSON); + } + }); + } + }); + } + + /** + * Perform an LDAP password change operation + * + * @method changePassword + * @param {String} userDN The user dn which the password will be changed + * @param {String} oldPassword Old password of user + * @param {String} newPassword New password for user + * @return {Promise} Will fulfil with a result of success if the + * Old password is given correctly, the parameters are string type and + * the state of client is BOUND else will fail with type error or LDAP ERROR. + * */ + changePassword(userDN: string, oldPassword: string, newPassword: string): Promise { + return new Promise((resolve, reject) => { + if (this._stateClient !== E_STATES.BOUND) { + reject(new StateError(errorMessages.bindErrorMessage)); + } else { + checkParameters.validateStrings(userDN, oldPassword, newPassword); + + this._binding.changePassword( + userDN, oldPassword, newPassword, (err: number) => { + if (err) { + const customError: any = errorHandler.errorSelection(err); + reject( + new customError(errorMessages.ldapChangePasswordErrorMessage)); + } else { + resolve(); + } + }); + } + }); + } + /** + * Perform an LDAP add operation + * + * @method add + * @param {String} dn dn of the entry to add Ex: 'cn=foo, o=example.., + * NOTE:every entry except the first one,cn=foo in this case, must already + * exist' + * @param {IaddEntrySchema} entry ldif format to be added, needs to have a + * structure that is mappable to a LDAPMod structure + * @param {IcontrolSchema} [controls] Request to execute a specific control + * or + * multiple controls. This parameter is optional. + * @return {Promise} that fulfils if the add was successful, rejects + * otherwise. + * */ + add(dn: string, entry: IaddEntrySchema, controls: IcontrolSchema): Promise { + return new Promise((resolve, reject) => { + if (this._stateClient !== E_STATES.BOUND) { + reject(new StateError(errorMessages.bindErrorMessage)); + } else { + checkParameters.validateStrings(dn); + const entryAttr: object[] = checkParameters.checkEntryObject(entry); + const ctrls: object[] | null = checkParameters.checkControl(controls); + + this._binding.add(dn, entryAttr, ctrls, (err: number, result: string | number) => { + if (err) { + const customError: any = errorHandler.errorSelection(err); + reject(new customError(errorMessages.ldapAddErrorMessage)); + } else { + const resJSON: string | number = result === 0 ? result : ldif.parse(result); + resolve(resJSON); + } + }); + } + }); + } + + /** + * Unbind from a LDAP server. + * + * @method unbind + * @return {Promise} That resolves if the LDAP structure was unbound. + * Reject if the LDAP could not unbind. + */ + unbind(): Promise { + return new Promise((resolve, reject) => { + if (this._stateClient !== E_STATES.UNBOUND) { + this._binding.unbind((err: number) => { + if (err) { + const customError: any = errorHandler.errorSelection(err); + reject(new customError(errorMessages.ldapUnbindErrorMessage)); + } else { + this._stateClient = E_STATES.UNBOUND; + resolve(); + } + }); + } else { + resolve(); + } + }); + } + +} diff --git a/ldapWrapTs/messages.json b/ldapWrapTs/messages.json new file mode 100644 index 0000000..2d310d5 --- /dev/null +++ b/ldapWrapTs/messages.json @@ -0,0 +1,23 @@ +{ + "bindErrorMessage": "The operation failed. It could be done if the state of the client is BOUND", + "typeErrorMessage": "Expected Valid String parameter", + "entryObjectError": "Invalid entryObject array", + "controlArrayError": "The control is not an array", + "controlPropError": "Invalid control array", + "invalidJSONMessage":"Invalid JSON", + "scopeSearchErrorMessage": "Invalid scope", + "ldapStartTlsErrorMessage":"Ldap Start TLS operation failed, check description for additional info", + "ldapSearchErrorMessage":"Ldap Search operation failed, check description for additional info", + "ldapBindErrorMessage": "Ldap Bind operation failed, check description for additional info", + "ldapModifyErrorMessage":"Ldap Modify operation failed, check description for additional info", + "ldapCompareErrorMessage":"Ldap Compare operation failed, check description for additional info", + "ldapRenameErrorMessage":"Ldap Rename operation failed, check description for additional info", + "ldapDeleteErrorMessage":"Ldap Delete operation failed, check description for additional info", + "ldapUnbindErrorMessage":"Ldap Unbind operation failed, check description for additional info", + "ldapAddErrorMessage": "Ldap Add operation failed, check description for additional info", + "ldapChangePasswordErrorMessage": "Ldap Change password operation failed, check description for additional info", + "uninitializedErrorMessage": "Please initialize", + "initErrorMessage": "Initialize failed!", + "ldapInitializeErrorMessage":"Ldap Initialize operation failed, check description for additional info" + + } \ No newline at end of file diff --git a/ldapWrapTs/messages.ts b/ldapWrapTs/messages.ts new file mode 100644 index 0000000..deacb16 --- /dev/null +++ b/ldapWrapTs/messages.ts @@ -0,0 +1,22 @@ +export interface RootObject { + bindErrorMessage: string; + typeErrorMessage: string; + entryObjectError: string; + controlArrayError: string; + controlPropError: string; + invalidJSONMessage: string; + scopeSearchErrorMessage: string; + ldapStartTlsErrorMessage: string; + ldapSearchErrorMessage: string; + ldapBindErrorMessage: string; + ldapModifyErrorMessage: string; + ldapCompareErrorMessage: string; + ldapRenameErrorMessage: string; + ldapDeleteErrorMessage: string; + ldapUnbindErrorMessage: string; + ldapAddErrorMessage: string; + ldapChangePasswordErrorMessage: string; + uninitializedErrorMessage: string; + initErrorMessage: string; + ldapInitializeErrorMessage: string; +} diff --git a/ldapWrapTs/schemas/add_entry_schema.json b/ldapWrapTs/schemas/add_entry_schema.json new file mode 100644 index 0000000..8b39c5b --- /dev/null +++ b/ldapWrapTs/schemas/add_entry_schema.json @@ -0,0 +1,18 @@ +{ + "id": "https://www.hufsm.com/openldap/add_entry/", + "type": "object", + "properties": { + "attr": { + "id": "https://www.hufsm.com/openldap/add_entry/attr", + "type": "string" + }, + "vals": { + "id": "https://www.hufsm.com/openldap/add_entry/vals", + "type": "array" + } + }, + "required": [ + "attr", + "vals" + ] +} diff --git a/ldapWrapTs/schemas/add_entry_schema.ts b/ldapWrapTs/schemas/add_entry_schema.ts new file mode 100644 index 0000000..6a8d484 --- /dev/null +++ b/ldapWrapTs/schemas/add_entry_schema.ts @@ -0,0 +1,4 @@ +export interface IaddEntrySchema { + attr: string; + vals: string[]; +} diff --git a/ldapWrapTs/schemas/change_schema.json b/ldapWrapTs/schemas/change_schema.json new file mode 100644 index 0000000..27ba93f --- /dev/null +++ b/ldapWrapTs/schemas/change_schema.json @@ -0,0 +1,23 @@ +{ + "id": "https://www.hufsm.com/openldap/change/", + "type": "object", + "properties": { + "op": { + "id": "https://www.hufsm.com/openldap/change/op", + "type": "string" + }, + "attr": { + "id": "https://www.hufsm.com/openldap/change/attr", + "type": "string" + }, + "vals": { + "id": "https://www.hufsm.com/openldap/change/vals", + "type": "array" + } + }, + "required": [ + "op", + "attr", + "vals" + ] +} diff --git a/ldapWrapTs/schemas/change_schema.ts b/ldapWrapTs/schemas/change_schema.ts new file mode 100644 index 0000000..db13c22 --- /dev/null +++ b/ldapWrapTs/schemas/change_schema.ts @@ -0,0 +1,10 @@ +export interface Val { + oldVal: string; + newVal: string; +} + +export interface IchangeSchema { + op: string; + attr: string; + vals: Val[]; +} diff --git a/ldapWrapTs/schemas/control_schema.json b/ldapWrapTs/schemas/control_schema.json new file mode 100644 index 0000000..ee7bc42 --- /dev/null +++ b/ldapWrapTs/schemas/control_schema.json @@ -0,0 +1,23 @@ +{ + "id": "https://www.hufsm.com/openldap/controlJson/", + "type": "object", + "properties": { + "oid": { + "id": "https://www.hufsm.com/openldap/controlJson/oid", + "type": "string" + }, + "value": { + "id": "https://www.hufsm.com/openldap/controlJson/value", + "type": "array" + }, + "isCritical": { + "id": "https://www.hufsm.com/openldap/controlJson/isCritical", + "type": "boolean" + } + }, + "required": [ + "oid", + "value", + "isCritical" + ] +} \ No newline at end of file diff --git a/ldapWrapTs/schemas/control_schema.ts b/ldapWrapTs/schemas/control_schema.ts new file mode 100644 index 0000000..4e1359d --- /dev/null +++ b/ldapWrapTs/schemas/control_schema.ts @@ -0,0 +1,5 @@ +export interface IcontrolSchema { + oid: string; + value: string[]; + isCritical: boolean; +} diff --git a/ldapWrapTs/schemas/update_attr_schema.json b/ldapWrapTs/schemas/update_attr_schema.json new file mode 100644 index 0000000..1b935b2 --- /dev/null +++ b/ldapWrapTs/schemas/update_attr_schema.json @@ -0,0 +1,18 @@ +{ + "id": "https://www.hufsm.com/openldap/update/", + "type": "object", + "properties": { + "oldVal": { + "id": "https://www.hufsm.com/openldap/update/oldVal", + "type": "string" + }, + "attr": { + "id": "https://www.hufsm.com/openldap/update/newVal", + "type": "string" + } + }, + "required": [ + "oldVal", + "newVal" + ] +} diff --git a/ldapWrapTs/schemas/update_attr_schema.ts b/ldapWrapTs/schemas/update_attr_schema.ts new file mode 100644 index 0000000..a8d9182 --- /dev/null +++ b/ldapWrapTs/schemas/update_attr_schema.ts @@ -0,0 +1,4 @@ +export interface IupdateAttrSchema { + oldVal: string; + newVal: string; +} diff --git a/ldapWrapTs/stream_interface.ts b/ldapWrapTs/stream_interface.ts new file mode 100644 index 0000000..f947c18 --- /dev/null +++ b/ldapWrapTs/stream_interface.ts @@ -0,0 +1,73 @@ +import { Readable as Readable } from 'stream'; +import { RootObject } from './messages'; +import * as errorHandler from './errors/error_dispenser'; +import ldifConstruct, { IldifObject } from './utils/construct_ldif'; + +const errorMessages: RootObject = require('./messages.json'); +const ldif: any = require('ldif'); + +/** + * @class PagedSearchStream + * class that extends the readable stream class + */ +export default class PagedSearchStream extends Readable { + + /** + * + * @param {String} base the base for the search. + * @param {unsigned int} scope scope for the search, can be 0(BASE), 1(ONE) or + * 2(SUBTREE) + * @param {String} filter search filter. + * @param {unsigned int} pageSize number of results displayed per page. + * @param {unsigned int} searchId unique search id. + * @param {Object} ldapInstance the ldap instance the search belongs to. + */ + + objectMode: boolean; + _binding: any; + _base: string; + _scope: number; + _filter: string; + _pageSize: number; + _searchId: number; + _lastResult: boolean; + constructor(base: string, scope: number, filter: string, pageSize: number, + searchId: number, ldapInstance: any) { + super(); + this.objectMode = true; + this._binding = ldapInstance; + this._base = base; + this._scope = scope; + this._filter = filter; + this._pageSize = pageSize; + this._searchId = searchId; + this._lastResult = false; + } + + _read(): void { + if (this._lastResult) { + this.push(null); + } else { + this._binding.pagedSearch( + this._base, this._scope, this._filter, this._pageSize, this._searchId, + (err: number, page: string, morePages: boolean) => { + if (err) { + const customError: any = errorHandler.errorSelection(err); + this.emit('err', new customError(errorMessages.ldapSearchErrorMessage)); + this.push(null); + } else { + if (!morePages) this._lastResult = true; + let resJSON: string | JSON | IldifObject; + try { + resJSON = page === '' ? page : ldif.parse(page); + } catch (ldifErr) { + resJSON = ldifConstruct(page); + } + this.push(JSON.stringify(resJSON)); + } + + }); + } + } + +} diff --git a/ldapWrapTs/utils/check_variable_format.ts b/ldapWrapTs/utils/check_variable_format.ts new file mode 100644 index 0000000..3f564d5 --- /dev/null +++ b/ldapWrapTs/utils/check_variable_format.ts @@ -0,0 +1,132 @@ +import * as Ajv from 'ajv'; +import * as _ from 'underscore'; + +import { IchangeSchema } from '../schemas/change_schema'; +import { IcontrolSchema } from '../schemas/control_schema'; +import { IaddEntrySchema } from '../schemas/add_entry_schema'; +import { IupdateAttrSchema } from '../schemas/update_attr_schema'; +import ValidationError from '../errors/validation_error'; +import { RootObject } from '../messages'; + +const changeSchema: IchangeSchema = require('../schemas/change_schema.json'); +const controlSchema: IcontrolSchema = require('../schemas/control_schema.json'); +const addEntrySchema: IaddEntrySchema = require('../schemas/add_entry_schema.json'); +const updateAttrSchema: IupdateAttrSchema = require('../schemas/update_attr_schema.json'); +const errorMessages: RootObject = require('../messages.json'); + +const ajv: Ajv.Ajv = new Ajv(); + +/** + * @module checkVariableFormat + * @class CheckParam + */ +export default class CheckParam { + + /** + * Checks if the arguments provided are Strings. + * + * @method validateStrings + * @return Throws an error in case the provided parameters aren't valid + * strings + */ + + static validateStrings(...arg: string[]): void { + _.each(arg, element => { + if (!_.isString(element)) { + throw new TypeError(errorMessages.typeErrorMessage); + } + }); + } + + /** + * Verify the modify change parameter. + * + * @method checkModifyChange + * @param {Object || Array} changes parameter set for verification + * @return Throws error in case the changes is not valid. Return the changes as + * an array in case entry is valid + */ + static checkModifyChange(changes: IchangeSchema): object[] { + const changesAttr = !_.isArray(changes) ? [changes] : changes; + const changeBuildArr: object[] = []; + changesAttr.forEach(element => { + const valid = ajv.validate(changeSchema, element); + if (!valid) { + throw new ValidationError(errorMessages.invalidJSONMessage, undefined, ajv.errors); + } + if (element.op === 'update') { + const deleteVals: string[] = []; + const addVals: string[] = []; + + element.vals.forEach((val) => { + const validVal = ajv.validate(updateAttrSchema, val); + if (!validVal) { + throw new ValidationError(errorMessages.invalidJSONMessage, undefined, ajv.errors); + } else { + deleteVals.push(val.oldVal); + addVals.push(val.newVal); + } + }); + + const ldapDeleteObject = { + op: 'delete', + attr: element.attr, + vals: deleteVals, + }; + changeBuildArr.push(ldapDeleteObject); + const ldapAddObject = { + op: 'add', + attr: element.attr, + vals: addVals, + }; + changeBuildArr.push(ldapAddObject); + } else { + changeBuildArr.push(element); + } + }); + return changeBuildArr; + } + + /** + * Verify the control parameter. + * + * @method checkControl + * @param {Object || Array} controls parameter set for verification + * @return Throws error in case the controls is not valid with the schema + * members. Return the array of control or null if the control is undefined. + */ + static checkControl(controls: Object | Object[]): Object[] | null { + if (controls !== undefined) { + const ctrls = !_.isArray(controls) ? [controls] : controls; + ctrls.forEach(element => { + const valid = ajv.validate(controlSchema, element); + if (!valid) { + throw new ValidationError(errorMessages.controlPropError, undefined, ajv.errors); + } + }); + return ctrls; + } + return null; + } + + /** + * Verify the entry parameter. + * + * @method checkControlArray + * @param {Object || Array} entry parameter set for verification + * @return Throws error in case the entry is not valid. Return the entry as + * an array in case entry is valid + */ + static checkEntryObject(entry: Object | Object[]): Object[] { + const entryAttr = !_.isArray(entry) ? [entry] : entry; + + entryAttr.forEach(element => { + const valid = ajv.validate(addEntrySchema, element); + if (!valid) { + throw new ValidationError(errorMessages.entryObjectError, undefined, ajv.errors); + } + }); + return entryAttr; + } + +} \ No newline at end of file diff --git a/ldapWrapTs/utils/construct_ldif.ts b/ldapWrapTs/utils/construct_ldif.ts new file mode 100644 index 0000000..b564826 --- /dev/null +++ b/ldapWrapTs/utils/construct_ldif.ts @@ -0,0 +1,70 @@ + +export interface Iattribute { + type: string, + options: never[], + attribute: string, +} + +export interface Ivalue { + type: string, + value: string, +} + +export interface IattributeObject { + attribute: Iattribute, + value: Ivalue, +} + +export interface IentryObject { + type: string, + dn: string, + attributes: IattributeObject[], +} + +export interface IldifObject { + type: string, + version: null, + entries: IentryObject[], +} + +export default function constructLdif(ldifString: string) { + const ldifObject: IldifObject = { + type: 'content', + version: null, + entries: [], + }; + const resultArr: string[] = ldifString.split('\n'); + const entryObject: IentryObject = { + type: 'record', + dn: '', + attributes: [], + }; + + resultArr.forEach((element, index, array) => { + if (element.trim()) { + const elementArr = element.split(':'); + const objectKey = elementArr[0]; + const objectVal = elementArr[1]; + if (objectKey !== 'dn') { + const constructAttrObj = { + attribute: { + type: 'attribute', + options: [], + attribute: objectKey, + }, + value: + { + type: 'value', + value: objectVal, + }, + }; + entryObject.attributes.push(constructAttrObj); + } else { + entryObject.dn = objectVal; + } + } else if (index === array.length - 1) { + ldifObject.entries.push(entryObject); + } + }); + return ldifObject; +} diff --git a/package.json b/package.json index 043dbcb..6b244aa 100644 --- a/package.json +++ b/package.json @@ -8,22 +8,31 @@ "url": "https://github.com/hufsm/openldapjs.git" }, "dependencies": { + "@types/ajv": "^1.0.0", + "@types/bluebird": "^3.5.18", + "@types/lodash": "^4.14.88", + "@types/underscore": "^1.8.5", "ajv": "5.3.0", "bluebird": "3.4.3", "ldif": "0.5.1", "nan": "2.6.0", + "github": "^12.1.0", + "node-pre-gyp": "^0.6.39", + "tslint": "^5.8.0", "underscore": "1.8.3" }, "devDependencies": { - "istanbul": "0.4.5", - "mocha": "4.0.1", + "@types/node": "^8.0.58", "eslint": "4.7.1", "eslint-config-airbnb": "15.1.0", + "eslint-config-airbnb-base": "^12.1.0", "eslint-plugin-import": "2.7.0", "eslint-plugin-jsx-a11y": "5.1.1", + "eslint-plugin-react": "7.3.0", + "istanbul": "0.4.5", + "mocha": "4.0.1", "should": "11.2.0", - "eslint-plugin-react": "7.3.0" - + "typescript-eslint-parser": "^9.0.1" }, "scripts": { "coverage": "istanbul cover \"./node_modules/mocha/bin/_mocha\" ./test/*.js", @@ -45,4 +54,4 @@ "directories": { "test": "test" } -} +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..83e2399 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,67 @@ +{ + "compilerOptions": { + /* Basic Options */ + "target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation: */ + "allowJs": false, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ + "declarationDir": "./TSdeclaration/@types", + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "./libBuildTLS/libs", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + "noUnusedLocals": true, /* Report errors on unused locals. */ + "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + "typeRoots": ["@types", "./ldapWrapTs/@types"], /* List of folders to include type definitions from. */ + "types": ["node"], /* Type declaration files to be included in compilation. */ + "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + + /* Source Map Options */ + // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + "plugins": [ + { + "name": "tslint-language-service" + } + ] + }, + "include": [ + "./ldapWrapTs/**/*" + ], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..a8c425f --- /dev/null +++ b/tslint.json @@ -0,0 +1,10 @@ +{ + "extends": [ + "tslint-config-airbnb" + ], + "rules": { + "no-trailing-whitespace": true, + "whitespace": true, + "typedef-whitespace": true + } +} \ No newline at end of file From 571b5686a3a26919c56c9a037cd8fdbd1bf9370a Mon Sep 17 00:00:00 2001 From: cosminghitea Date: Tue, 30 Jan 2018 11:34:19 +0200 Subject: [PATCH 2/8] Remove the ts from this branch --- .gitignore | 6 +- index.ts | 10 - ldapWrapTs/errors/error_dispenser.ts | 96 ---- .../errors/ldap_errors/ldap_access_error.ts | 13 - .../ldap_errors/ldap_admin_limit_error.ts | 13 - .../ldap_errors/ldap_alias_deref_error.ts | 13 - .../errors/ldap_errors/ldap_alias_error.ts | 13 - .../ldap_errors/ldap_already_exists_error.ts | 13 - .../ldap_attribute_exists_error.ts | 13 - .../ldap_auth_method_unsupported.ts | 14 - .../errors/ldap_errors/ldap_busy_error.ts | 13 - .../ldap_errors/ldap_confidentiality_error.ts | 13 - .../ldap_errors/ldap_constraint_error.ts | 13 - .../errors/ldap_errors/ldap_dsas_error.ts | 13 - ldapWrapTs/errors/ldap_errors/ldap_error.ts | 12 - .../ldap_inappropriate_auth_error.ts | 15 - .../ldap_inappropriate_matching_error.ts | 14 - .../ldap_invalid_credentials_error.ts | 14 - .../ldap_errors/ldap_invalid_dn_error.ts | 13 - .../ldap_errors/ldap_invalid_syntax_error.ts | 13 - .../errors/ldap_errors/ldap_leaf_error.ts | 13 - .../errors/ldap_errors/ldap_loop_error.ts | 13 - .../errors/ldap_errors/ldap_naming_error.ts | 15 - .../ldap_no_such_attribute_error.ts | 13 - .../errors/ldap_errors/ldap_non_leaf_error.ts | 15 - .../ldap_errors/ldap_object_class_error.ts | 16 - .../ldap_object_class_mods_error.ts | 13 - .../ldap_object_not_found_error.ts | 13 - .../ldap_errors/ldap_operation_error.ts | 16 - .../errors/ldap_errors/ldap_other_error.ts | 13 - .../errors/ldap_errors/ldap_protocol_error.ts | 13 - .../errors/ldap_errors/ldap_rdn_error.ts | 13 - .../errors/ldap_errors/ldap_referral_error.ts | 14 - .../ldap_errors/ldap_sasl_bind_error.ts | 14 - .../ldap_errors/ldap_size_limit_error.ts | 14 - .../ldap_errors/ldap_strong_auth_error.ts | 16 - .../ldap_errors/ldap_time_limit_error.ts | 14 - .../ldap_unavailable_critical_ext.ts | 14 - .../ldap_errors/ldap_unavailable_error.ts | 13 - .../ldap_errors/ldap_undefined_type_error.ts | 13 - .../ldap_errors/ldap_unwilling_error.ts | 13 - ldapWrapTs/errors/ldap_errors/login_error.ts | 5 - .../errors/ldap_errors/operational_error.ts | 6 - ldapWrapTs/errors/ldap_errors/server_error.ts | 6 - ldapWrapTs/errors/state_error.ts | 9 - ldapWrapTs/errors/validation_error.ts | 15 - ldapWrapTs/ldap_async_wrap.ts | 461 ------------------ ldapWrapTs/messages.json | 23 - ldapWrapTs/messages.ts | 22 - ldapWrapTs/schemas/add_entry_schema.json | 18 - ldapWrapTs/schemas/add_entry_schema.ts | 4 - ldapWrapTs/schemas/change_schema.json | 23 - ldapWrapTs/schemas/change_schema.ts | 10 - ldapWrapTs/schemas/control_schema.json | 23 - ldapWrapTs/schemas/control_schema.ts | 5 - ldapWrapTs/schemas/update_attr_schema.json | 18 - ldapWrapTs/schemas/update_attr_schema.ts | 4 - ldapWrapTs/stream_interface.ts | 73 --- ldapWrapTs/utils/check_variable_format.ts | 132 ----- ldapWrapTs/utils/construct_ldif.ts | 70 --- package.json | 14 +- tsconfig.json | 67 --- tslint.json | 10 - 63 files changed, 2 insertions(+), 1644 deletions(-) delete mode 100644 index.ts delete mode 100644 ldapWrapTs/errors/error_dispenser.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_access_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_admin_limit_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_alias_deref_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_alias_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_already_exists_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_attribute_exists_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_auth_method_unsupported.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_busy_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_confidentiality_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_constraint_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_dsas_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_inappropriate_auth_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_inappropriate_matching_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_invalid_credentials_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_invalid_dn_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_invalid_syntax_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_leaf_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_loop_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_naming_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_no_such_attribute_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_non_leaf_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_object_class_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_object_class_mods_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_object_not_found_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_operation_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_other_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_protocol_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_rdn_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_referral_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_sasl_bind_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_size_limit_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_strong_auth_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_time_limit_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_unavailable_critical_ext.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_unavailable_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_undefined_type_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/ldap_unwilling_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/login_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/operational_error.ts delete mode 100644 ldapWrapTs/errors/ldap_errors/server_error.ts delete mode 100644 ldapWrapTs/errors/state_error.ts delete mode 100644 ldapWrapTs/errors/validation_error.ts delete mode 100644 ldapWrapTs/ldap_async_wrap.ts delete mode 100644 ldapWrapTs/messages.json delete mode 100644 ldapWrapTs/messages.ts delete mode 100644 ldapWrapTs/schemas/add_entry_schema.json delete mode 100644 ldapWrapTs/schemas/add_entry_schema.ts delete mode 100644 ldapWrapTs/schemas/change_schema.json delete mode 100644 ldapWrapTs/schemas/change_schema.ts delete mode 100644 ldapWrapTs/schemas/control_schema.json delete mode 100644 ldapWrapTs/schemas/control_schema.ts delete mode 100644 ldapWrapTs/schemas/update_attr_schema.json delete mode 100644 ldapWrapTs/schemas/update_attr_schema.ts delete mode 100644 ldapWrapTs/stream_interface.ts delete mode 100644 ldapWrapTs/utils/check_variable_format.ts delete mode 100644 ldapWrapTs/utils/construct_ldif.ts delete mode 100644 tsconfig.json delete mode 100644 tslint.json diff --git a/.gitignore b/.gitignore index cc6cab3..c7252d0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ npm-debug.log **/npm-debug.log **/npm-debug.log* **/node_modules -**/docs .idea **/logs/*.log **/pids/*.pid @@ -23,7 +22,6 @@ static_server_npm_helper.pid */out **/.jscsrc **/.jshintrc -**/docs/* !**/docs/.gitkeep **/coverage/* !**/coverage/.gitkeep @@ -38,6 +36,4 @@ modify.ldif ./.vscode/ ./build/** .vscode/settings.json -build/* -libBuildTLS/* -TSdeclaration/* +build/* \ No newline at end of file diff --git a/index.ts b/index.ts deleted file mode 100644 index 93f10c6..0000000 --- a/index.ts +++ /dev/null @@ -1,10 +0,0 @@ - -import * as LdapClient from './libs/ldap_async_wrap'; -import * as errorHandler from './ldapWrapTs/errors/error_dispenser'; -import * as errorList from './ldapWrapTs/errors/error_dispenser'; - -module.exports = { - Client: LdapClient, - errorHandler: errorHandler.errorSelection, - errorList: errorList.errors, -}; diff --git a/ldapWrapTs/errors/error_dispenser.ts b/ldapWrapTs/errors/error_dispenser.ts deleted file mode 100644 index 559180c..0000000 --- a/ldapWrapTs/errors/error_dispenser.ts +++ /dev/null @@ -1,96 +0,0 @@ -import LdapInvalidDnError from './ldap_errors/ldap_invalid_dn_error'; -import LdapSizeLimitError from './ldap_errors/ldap_size_limit_error'; -import LdapTimeLimitError from './ldap_errors/ldap_time_limit_error'; -import LdapProtocolError from './ldap_errors/ldap_protocol_error'; -import LdapInvalidSyntaxError from './ldap_errors/ldap_invalid_syntax_error'; -import LdapOperationError from './ldap_errors/ldap_operation_error'; -import LdapAuthUnsupportedError from './ldap_errors/ldap_auth_method_unsupported'; -import LdapStrongAuthError from './ldap_errors/ldap_strong_auth_error'; -import LdapReferralError from './ldap_errors/ldap_referral_error'; -import LdapAdminLimitError from './ldap_errors/ldap_admin_limit_error'; -import LdapCriticalExtensionError from './ldap_errors/ldap_unavailable_critical_ext'; -import LdapConfidentialityError from './ldap_errors/ldap_confidentiality_error'; -import LdapSaslBindError from './ldap_errors/ldap_sasl_bind_error'; -import LdapNoSuchAttribute from './ldap_errors/ldap_no_such_attribute_error'; -import LdapUndefinedTypeError from './ldap_errors/ldap_undefined_type_error'; -import LdapMatchingError from './ldap_errors/ldap_inappropriate_matching_error'; -import LdapConstraintError from './ldap_errors/ldap_constraint_error'; -import LdapTypeOrValueAlreadyExistsError from './ldap_errors/ldap_attribute_exists_error'; -import LdapNoSuchObjectError from './ldap_errors/ldap_object_not_found_error'; -import LdapAliasError from './ldap_errors/ldap_alias_error'; -import LdapLeafError from './ldap_errors/ldap_leaf_error'; -import LdapAliasDerefError from './ldap_errors/ldap_alias_deref_error'; -import LdapInappropriateAuthError from './ldap_errors/ldap_inappropriate_auth_error'; -import LdapCredentialsError from './ldap_errors/ldap_invalid_credentials_error'; -import LdapAccessError from './ldap_errors/ldap_access_error'; -import LdapBusyError from './ldap_errors/ldap_busy_error'; -import LdapUnavailable from './ldap_errors/ldap_unavailable_error'; -import LdapUnWillingError from './ldap_errors/ldap_unwilling_error'; -import LdapLoopError from './ldap_errors/ldap_loop_error'; -import LdapNamingError from './ldap_errors/ldap_naming_error'; -import LdapObjectClassError from './ldap_errors/ldap_object_class_error'; -import LdapNonLeafError from './ldap_errors/ldap_non_leaf_error'; -import LdapRdnError from './ldap_errors/ldap_rdn_error'; -import LdapAlreadyExists from './ldap_errors/ldap_already_exists_error'; -import LdapClassModsError from './ldap_errors/ldap_object_class_mods_error'; -import LdapDsasError from './ldap_errors/ldap_dsas_error'; -import LdapOtherError from './ldap_errors/ldap_other_error'; - -export const errors: any = { - LdapInvalidDnError: (LdapInvalidDnError), - LdapSizeLimitError: (LdapSizeLimitError), - LdapTimeLimitError: (LdapTimeLimitError), - LdapProtocolError: (LdapProtocolError), - LdapInvalidSyntaxError: (LdapInvalidSyntaxError), - LdapOperationError: (LdapOperationError), - LdapAuthUnsupportedError: (LdapAuthUnsupportedError), - LdapStrongAuthError: (LdapStrongAuthError), - LdapReferralError: (LdapReferralError), - LdapAdminLimitError: (LdapAdminLimitError), - LdapCriticalExtensionError: (LdapCriticalExtensionError), - LdapConfidentialityError: (LdapConfidentialityError), - LdapSaslBindError: (LdapSaslBindError), - LdapNoSuchAttribute: (LdapNoSuchAttribute), - LdapUndefinedTypeError: (LdapUndefinedTypeError), - LdapMatchingError: (LdapMatchingError), - LdapConstraintError: (LdapConstraintError), - LdapTypeOrValueAlreadyExistsError: (LdapTypeOrValueAlreadyExistsError), - LdapNoSuchObjectError: (LdapNoSuchObjectError), - LdapAliasError: (LdapAliasError), - LdapLeafError: (LdapLeafError), - LdapAliasDerefError: (LdapAliasDerefError), - LdapInappropriateAuthError: (LdapInappropriateAuthError), - LdapCredentialsError: (LdapCredentialsError), - LdapAccessError: (LdapAccessError), - LdapBusyError: (LdapBusyError), - LdapUnavailable: (LdapUnavailable), - LdapUnWillingError: (LdapUnWillingError), - LdapLoopError: (LdapLoopError), - LdapNamingError: (LdapNamingError), - LdapObjectClassError: (LdapObjectClassError), - LdapNonLeafError: (LdapNonLeafError), - LdapRdnError: (LdapRdnError), - LdapAlreadyExists: (LdapAlreadyExists), - LdapClassModsError: (LdapClassModsError), - LdapDsasError: (LdapDsasError), - LdapOtherError: (LdapOtherError), -}; -/** - * Function that returns the error class corresponding to the LDAP error code. - * @param {Number} code Ldap error code ranging from 1 to 80 or negative for API errors. - * @return {Error} DesiredErrorClass Custom error class corresponding to the ldap error code. - */ -export function errorSelection(code: number): Error { - - const foundErrorClassKey: string | undefined = Object.keys(errors) - .find(key => { - const classCandidate = errors[key]; - return code === classCandidate.code; - }); - - const desiredErrorClass: Error = foundErrorClassKey === undefined - ? LdapOtherError - : errors[foundErrorClassKey]; - - return desiredErrorClass; -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_access_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_access_error.ts deleted file mode 100644 index 7975396..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_access_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import LoginError from './login_error'; - -export default class LdapAccessError extends LoginError { - - static get code(): number { - return 50; - } - - static get description(): string { - return 'Indicates that the caller does not have sufficient rights to perform the requested operation.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_admin_limit_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_admin_limit_error.ts deleted file mode 100644 index 4730f6f..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_admin_limit_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import ServerError from './server_error'; - -export default class LdapAdminLimitError extends ServerError { - - static get code(): number { - return 11; - } - - static get description(): string { - return 'Indicates that an LDAP server limit set by an administrative authority has been exceeded.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_alias_deref_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_alias_deref_error.ts deleted file mode 100644 index 4acdac7..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_alias_deref_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import ServerError from './server_error'; - -export default class LdapAliasDerefError extends ServerError { - - static get code(): number { - return 36; - } - - static get description(): string { - return 'Indicates that during a search operation, either the client does not have access rights to read the aliased object\'s name or dereferencing is not allowed.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_alias_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_alias_error.ts deleted file mode 100644 index 53f94cf..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_alias_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import ServerError from './server_error'; - -export default class LdapAliasError extends ServerError { - - static get code(): number { - return 33; - } - - static get description(): string { - return 'Indicates that an error occurred when an alias was dereferenced.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_already_exists_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_already_exists_error.ts deleted file mode 100644 index 5cd4f9f..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_already_exists_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapAlreadyExistsError extends OperationalError { - - static get code(): number { - return 68; - } - - static get description(): string { - return 'Indicates that the add operation attempted to add an entry that already exists, or that the modify operation attempted to rename an entry to the name of an entry that already exists.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_attribute_exists_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_attribute_exists_error.ts deleted file mode 100644 index 52f12d0..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_attribute_exists_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapAttributeExists extends OperationalError { - - static get code(): number { - return 20; - } - - static get description(): string { - return 'Indicates that the attribute value specified in a modify or add operation already exists as a value for that attribute.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_auth_method_unsupported.ts b/ldapWrapTs/errors/ldap_errors/ldap_auth_method_unsupported.ts deleted file mode 100644 index 83049d2..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_auth_method_unsupported.ts +++ /dev/null @@ -1,14 +0,0 @@ -import LoginError from './login_error'; - -export default class LdapAuthError extends LoginError { - - static get code(): number { - return 7; - } - - static get description(): string { - return 'Indicates that during a bind operation the client requested ' + - ' an authentication method not supported by the LDAP server.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_busy_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_busy_error.ts deleted file mode 100644 index 50a221e..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_busy_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import ServerError from './server_error'; - -export default class LdapBusyError extends ServerError { - - static get code(): number { - return 51; - } - - static get description(): string { - return 'Indicates that the LDAP server is too busy to process the client request at this time but if the client waits and resubmits the request, the server may be able to process it then.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_confidentiality_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_confidentiality_error.ts deleted file mode 100644 index 6fbf1e8..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_confidentiality_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import LdapError from './ldap_error'; - -export default class LdapConfidentialityError extends LdapError { - - static get code(): number { - return 13; - } - - static get description(): string { - return 'Indicates that the session is not protected by a protocol such as Transport Layer Security (TLS), which provides session confidentiality.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_constraint_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_constraint_error.ts deleted file mode 100644 index eaa0582..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_constraint_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapConstraintError extends OperationalError { - - static get code(): number { - return 19; - } - - static get description(): string { - return 'Indicates that the attribute value specified in a modify, add, or modify DN operation violates constraints placed on the attribute. The constraint can be one of size or content (string only, no binary).'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_dsas_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_dsas_error.ts deleted file mode 100644 index 9d25839..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_dsas_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapDsasError extends OperationalError { - - static get code(): number { - return 71; - } - - static get description(): string { - return 'Indicates that the modify DN operation moves the entry from one LDAP server to another and requires more than one LDAP server.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_error.ts deleted file mode 100644 index c94a593..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_error.ts +++ /dev/null @@ -1,12 +0,0 @@ -export default class LdapError extends Error { - - message:string; - name:string; - constructor(message:string) { - super(message); - this.message = message; - this.name = this.constructor.name; - Error.captureStackTrace(this, (this).constructor.name); - } - -} \ No newline at end of file diff --git a/ldapWrapTs/errors/ldap_errors/ldap_inappropriate_auth_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_inappropriate_auth_error.ts deleted file mode 100644 index 360261a..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_inappropriate_auth_error.ts +++ /dev/null @@ -1,15 +0,0 @@ -import LoginError from'./login_error'; - -export default class LdapInappropriateAuthError extends LoginError { - - static get code(): number { - return 48; - } - - static get description(): string { - return 'Indicates that during a bind operation, the client is attempting to use an authentication method that the client cannot use correctly.' + - ' For example, either of the following cause this error: The client returns simple credentials when strong credentials are required' + - '...OR...The client returns a DN and a password for a simple bind when the entry does not have a password defined.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_inappropriate_matching_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_inappropriate_matching_error.ts deleted file mode 100644 index 7fc608b..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_inappropriate_matching_error.ts +++ /dev/null @@ -1,14 +0,0 @@ -import OperationalError from './operational_error'; - - -export default class LdapMatchingError extends OperationalError { - - static get code(): number { - return 18; - } - - static get description(): string { - return 'Indicates that the matching rule specified in the search filter does not match a rule defined for the attribute\'s syntax.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_invalid_credentials_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_invalid_credentials_error.ts deleted file mode 100644 index 917c774..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_invalid_credentials_error.ts +++ /dev/null @@ -1,14 +0,0 @@ -import LoginError from './login_error'; - -export default class LdapCredentialsError extends LoginError { - - static get code(): number { - return 49; - } - - static get description(): string { - return 'Indicates that during a bind operation one of the following occurred: The client passed either an incorrect DN or password,' + - ' or the password is incorrect because it has expired, intruder detection has locked the account, or another similar reason. See the data code for more information.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_invalid_dn_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_invalid_dn_error.ts deleted file mode 100644 index a71b387..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_invalid_dn_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapInvalidDnError extends OperationalError { - - static get code(): number { - return 34; - } - - static get description(): string { - return 'Indicates that the syntax of the DN is incorrect. (If the DN syntax is correct, but the LDAP server\'s structure rules do not permit the operation, the server returns LDAP_UNWILLING_TO_PERFORM.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_invalid_syntax_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_invalid_syntax_error.ts deleted file mode 100644 index 39bcbcd..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_invalid_syntax_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapInvalidSyntaxError extends OperationalError { - - static get code(): number { - return 21; - } - - static get description(): string { - return 'Indicates that the attribute value specified in an add, compare, or modify operation is an unrecognized or invalid syntax for the attribute.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_leaf_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_leaf_error.ts deleted file mode 100644 index 84e4565..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_leaf_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapLeafError extends OperationalError { - - static get code(): number { - return 35; - } - - static get description(): string { - return 'Indicates that the specified operation cannot be performed on a leaf entry. (This code is not currently in the LDAP specifications, but is reserved for this constant.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_loop_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_loop_error.ts deleted file mode 100644 index 5eaf275..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_loop_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import ServerError from './server_error'; - -export default class LdapLoopError extends ServerError { - - static get code(): number { - return 54; - } - - static get description(): string { - return 'Indicates that the client discovered an alias or referral loop, and is thus unable to complete this request.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_naming_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_naming_error.ts deleted file mode 100644 index fa64d57..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_naming_error.ts +++ /dev/null @@ -1,15 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapNamingError extends OperationalError { - - static get code(): number { - return 64; - } - - static get description(): string { - return 'Indicates that the add or modify DN operation violates the schema\'s structure rules.' + - ' For example,the request places the entry subordinate to an alias.' + - ' The request places the entry subordinate to a container that is forbidden by the containment rules. The RDN for the entry uses a forbidden attribute type.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_no_such_attribute_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_no_such_attribute_error.ts deleted file mode 100644 index e75fb56..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_no_such_attribute_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapNoSuchAttributeError extends OperationalError { - - static get code(): number { - return 16; - } - - static get description(): string { - return 'Indicates that the attribute specified in the modify or compare operation does not exist in the entry.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_non_leaf_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_non_leaf_error.ts deleted file mode 100644 index bd2989b..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_non_leaf_error.ts +++ /dev/null @@ -1,15 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapNonLeafError extends OperationalError { - - static get code(): number { - return 66; - } - - static get description(): string { - return 'Indicates that the requested operation is permitted only on leaf entries.' + - ' For example, the following types of requests return this error:The client requests a delete operation on a parent entry.' + - ' The client request a modify DN operation on a parent entry.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_object_class_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_object_class_error.ts deleted file mode 100644 index 4d2ae6d..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_object_class_error.ts +++ /dev/null @@ -1,16 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapObjectClassError extends OperationalError { - - static get code(): number { - return 65; - } - - static get description(): string { - return 'Indicates that the add, modify, or modify DN operation violates the object class rules for the entry.' + - ' For example, the following types of request return this error: The add or modify operation tries to add an entry without a value for a required attribute.' + - ' The add or modify operation tries to add an entry with a value for an attribute which the class definition does not contain.' + - ' The modify operation tries to remove a required attribute without removing the auxiliary class that defines the attribute as required.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_object_class_mods_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_object_class_mods_error.ts deleted file mode 100644 index 4be04d8..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_object_class_mods_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapObjectClassModsError extends OperationalError { - - static get code(): number { - return 69; - } - - static get description(): string { - return 'Indicates that the modify operation attempted to modify the structure rules of an object class.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_object_not_found_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_object_not_found_error.ts deleted file mode 100644 index 10d0c55..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_object_not_found_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapNotFoundError extends OperationalError { - - static get code(): number { - return 32; - } - - static get description(): string { - return 'Indicates the target object cannot be found. This code is not returned on following operations: Search operations that find the search base but cannot find any entries that match the search filter. Bind operations.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_operation_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_operation_error.ts deleted file mode 100644 index 2d4c290..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_operation_error.ts +++ /dev/null @@ -1,16 +0,0 @@ -import LdapError from './ldap_error'; - -export default class LdapOperationError extends LdapError { - - static get code(): number { - return 1; - } - - static get description(): string { - return 'Indicates an internal error. The server is unable to respond with a more specific error and is also unable to properly respond to a request.' + - ' It does not indicate that the client has sent an erroneous message.' + - ' In NDS 8.3x through NDS 7.xx, this was the default error for NDS errors that did not map to an LDAP error code.' + - ' To conform to the new LDAP drafts, NDS 8.5 uses 80 (0x50) for such errors.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_other_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_other_error.ts deleted file mode 100644 index ea18dcb..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_other_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import LdapError from './ldap_error'; - -export default class LdapOtherError extends LdapError { - - static get code(): number { - return 80; - } - - static get description(): string { - return 'Indicates an unknown error condition. This is the default value for NDS error codes which do not map to other LDAP error codes.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_protocol_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_protocol_error.ts deleted file mode 100644 index 12e4751..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_protocol_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapProtocolError extends OperationalError { - - static get code(): number { - return 2; - } - - static get description(): string { - return 'Indicates that the server has received an invalid or malformed request from the client.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_rdn_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_rdn_error.ts deleted file mode 100644 index d8a3024..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_rdn_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapRdnError extends OperationalError { - - static get code(): number { - return 67; - } - - static get description(): string { - return 'Indicates that the modify operation attempted to remove an attribute value that forms the entry\'s relative distinguished name.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_referral_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_referral_error.ts deleted file mode 100644 index 1e87692..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_referral_error.ts +++ /dev/null @@ -1,14 +0,0 @@ -import LdapError from './ldap_error'; - -export default class LdapReferralError extends LdapError { - - static get code(): number { - return 10; - } - - static get description(): string { - return 'Does not indicate an error condition. In LDAPv3, indicates that the server' + - ' does not hold the target entry of the request, but that the servers in the referral field may.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_sasl_bind_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_sasl_bind_error.ts deleted file mode 100644 index 7750c17..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_sasl_bind_error.ts +++ /dev/null @@ -1,14 +0,0 @@ -import LdapError from './ldap_error'; - -export default class LdapBindInProgressError extends LdapError { - - static get code(): number { - return 14; - } - - static get description(): string { - return 'Does not indicate an error condition, but indicates that the server is ready for the next step in the process.' + - ' The client must send the server the same SASL mechanism to continue the process.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_size_limit_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_size_limit_error.ts deleted file mode 100644 index 65780ce..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_size_limit_error.ts +++ /dev/null @@ -1,14 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapSizeLimitError extends OperationalError { - - static get code(): number { - return 4; - } - - static get description(): string { - return 'Indicates that in a search operation, the size limit specified by the client or the server' + - ' has been exceeded. Incomplete results are returned.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_strong_auth_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_strong_auth_error.ts deleted file mode 100644 index 5fd9677..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_strong_auth_error.ts +++ /dev/null @@ -1,16 +0,0 @@ -import LoginError from './login_error'; - -export default class LdapStrongAuthRequired extends LoginError { - - static get code(): number { - return 8; - } - - static get description(): string { - return 'Indicates one of the following: In bind requests, the LDAP server accepts only strong authentication.' + - ' In a client request, the client requested an operation such as delete that requires strong authentication.' + - ' In an unsolicited notice of disconnection, the LDAP server discovers the security protecting the communication' + - ' between the client and server has unexpectedly failed or been compromised.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_time_limit_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_time_limit_error.ts deleted file mode 100644 index 907292d..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_time_limit_error.ts +++ /dev/null @@ -1,14 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapTimeLimitError extends OperationalError { - - static get code(): number { - return 3; - } - - static get description(): string { - return 'Indicates that the operation\'s time limit specified by either the client or the server' + - ' has been exceeded. On search operations, incomplete results are returned.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_unavailable_critical_ext.ts b/ldapWrapTs/errors/ldap_errors/ldap_unavailable_critical_ext.ts deleted file mode 100644 index 3577b52..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_unavailable_critical_ext.ts +++ /dev/null @@ -1,14 +0,0 @@ -import ServerError from './server_error'; - -export default class LdapCriticalExtensionError extends ServerError { - - static get code(): number { - return 12; - } - - static get description(): string { - return 'Indicates that the LDAP server was unable to satisfy a request because one or more critical' + - ' extensions were not available. Either the server does not support the control or the control is not appropriate for the operation type.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_unavailable_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_unavailable_error.ts deleted file mode 100644 index efc3097..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_unavailable_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import ServerError from './server_error'; - -export default class LdapUnavailableError extends ServerError { - - static get code(): number { - return 52; - } - - static get description(): string { - return 'Indicates that the LDAP server cannot process the client\'s bind request, usually because it is shutting down.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_undefined_type_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_undefined_type_error.ts deleted file mode 100644 index 003a373..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_undefined_type_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import OperationalError from './operational_error'; - -export default class LdapUndefinedTypeError extends OperationalError { - - static get code(): number { - return 17; - } - - static get description(): string { - return 'Indicates that the attribute specified in the modify or add operation does not exist in the LDAP server\'s schema.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/ldap_unwilling_error.ts b/ldapWrapTs/errors/ldap_errors/ldap_unwilling_error.ts deleted file mode 100644 index b5957d0..0000000 --- a/ldapWrapTs/errors/ldap_errors/ldap_unwilling_error.ts +++ /dev/null @@ -1,13 +0,0 @@ -import ServerError from './server_error'; - -export default class LdapUnwillingError extends ServerError { - - static get code(): number { - return 53; - } - - static get description(): string { - return 'Indicates that the LDAP server cannot process the client\'s bind request, usually because it is shutting down.'; - } - -} diff --git a/ldapWrapTs/errors/ldap_errors/login_error.ts b/ldapWrapTs/errors/ldap_errors/login_error.ts deleted file mode 100644 index 2cc70cf..0000000 --- a/ldapWrapTs/errors/ldap_errors/login_error.ts +++ /dev/null @@ -1,5 +0,0 @@ -import LdapError from './ldap_error'; - -export default class LoginError extends LdapError { - -} diff --git a/ldapWrapTs/errors/ldap_errors/operational_error.ts b/ldapWrapTs/errors/ldap_errors/operational_error.ts deleted file mode 100644 index 616bc25..0000000 --- a/ldapWrapTs/errors/ldap_errors/operational_error.ts +++ /dev/null @@ -1,6 +0,0 @@ -import LdapError from './ldap_error'; - -export default class OperationalError extends LdapError { - - -} diff --git a/ldapWrapTs/errors/ldap_errors/server_error.ts b/ldapWrapTs/errors/ldap_errors/server_error.ts deleted file mode 100644 index e2abd01..0000000 --- a/ldapWrapTs/errors/ldap_errors/server_error.ts +++ /dev/null @@ -1,6 +0,0 @@ -import LdapError from './ldap_error'; - -export default class ServerError extends LdapError { - - -} diff --git a/ldapWrapTs/errors/state_error.ts b/ldapWrapTs/errors/state_error.ts deleted file mode 100644 index e6f4c51..0000000 --- a/ldapWrapTs/errors/state_error.ts +++ /dev/null @@ -1,9 +0,0 @@ -export default class StateError extends Error { - - constructor(message: string) { - super(message); - Error.captureStackTrace(this, this.constructor); - this.name = this.constructor.name; - } - -} diff --git a/ldapWrapTs/errors/validation_error.ts b/ldapWrapTs/errors/validation_error.ts deleted file mode 100644 index b39fdf8..0000000 --- a/ldapWrapTs/errors/validation_error.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { ErrorObject } from 'ajv'; - -export default class ValidationError extends Error { - - error: Error | ErrorObject[] | undefined; - - constructor(message: string, error: Error | undefined ,errors: ErrorObject[] | undefined) { - super(message); - Error.captureStackTrace(this, this.constructor); - this.name = this.constructor.name; - this.error = error || errors; - } - -} - diff --git a/ldapWrapTs/ldap_async_wrap.ts b/ldapWrapTs/ldap_async_wrap.ts deleted file mode 100644 index ddc3f09..0000000 --- a/ldapWrapTs/ldap_async_wrap.ts +++ /dev/null @@ -1,461 +0,0 @@ -import * as path from 'path'; -import * as Promise from 'bluebird'; -import * as _ from 'underscore'; - -import checkParameters from './utils/check_variable_format'; - -import SearchStream from './stream_interface'; -import StateError from './errors/state_error'; -import ldifConstruct, { IldifObject } from './utils/construct_ldif'; -import { RootObject } from './messages'; -import { IchangeSchema } from './schemas/change_schema'; -import { IcontrolSchema } from './schemas/control_schema'; -import { IaddEntrySchema } from './schemas/add_entry_schema'; - -import * as errorHandler from './errors/error_dispenser'; - -const ldif: any = require('ldif'); -const errorMessages: RootObject = require('./messages.json'); -const binary: any = require('node-pre-gyp'); -const bindingPath: string = binary.find(path.resolve(path.join(__dirname, '../package.json'))); -const binding = require(bindingPath); - -interface IObjectEState { - CREATED: number; - INITIALIZED: number; - BOUND: number; - UNBOUND: number; - [key: string]: number; -} - -interface IObjectScopeObject { - BASE: number; - ONE: number; - SUBTREE: number; - [key: string]: number; -} - -const E_STATES: IObjectEState = { - CREATED: 0, - INITIALIZED: 1, - BOUND: 2, - UNBOUND: 5, -}; - -const scopeObject: IObjectScopeObject = { - BASE: 0, - ONE: 1, - SUBTREE: 2, -}; - -/** - * @module LDAPTransition - * @class LDAPAsyncWrap - */ - -export default class LDAPAsyncWrap { - private _hostAddress: string; - _binding = new binding.LDAPClient(); - _stateClient: number; - _searchID: number; - constructor(public host: string) { - this._hostAddress = host; - this._stateClient = E_STATES.CREATED; - } - - /** - * Initialize to an LDAP server. - * - * @method initialize - * @return {Promise} That resolves if ldap_initialize succeeds - ** Rejects if client was not created or ldap_initialize fails. - * */ - - initialize(): Promise { - return new Promise((resolve, reject) => { - if (this._stateClient === E_STATES.CREATED) { - this._binding.initialize(this._hostAddress, (err: number) => { - if (err) { - const customError: any = errorHandler.errorSelection(err); - reject(new customError(errorMessages.ldapInitializeErrorMessage)); - } else { - this._stateClient = E_STATES.INITIALIZED; - resolve(); - } - }); - } else { - reject(new StateError(errorMessages.initErrorMessage)); - } - }); - } - - - /** - * Initiate a TLS processing on an LDAP session. - * - * @method startTLS - * @param {String} pathToCertFile The path to the certificate can be optional - * @return {Promise} Will reject if state is not Initialized or if the - * certificate is not good else will resolve If the certificate is not - * specified then the client will use the server certificate - * */ - - startTLS(pathToCertFile: string): Promise { - return new Promise((resolve, reject) => { - if (this._stateClient === E_STATES.INITIALIZED) { - const pathCert = pathToCertFile === undefined ? '' : pathToCertFile; - this._binding.startTls(pathCert, (err: number) => { - if (err) { - const customError: any = errorHandler.errorSelection(err); - reject(new customError(errorMessages.ldapStartTlsErrorMessage)); - } else { - resolve(); - } - }); - } else { - reject(new StateError(errorMessages.initErrorMessage)); - } - }); - } - - /** - * Authenticate to LDAP server. - * - * @method bind - * @param {String} bindDn The client user DN. - * @param {String} passwordUser The client's password. - * @return {Promise} That resolves if the credentials are correct. - * Rejects if dn or password are incorrect or the client did not initialize. - * */ - - bind(bindDn: string, passwordUser: string): Promise { - return new Promise((resolve, reject) => { - if (this._stateClient === E_STATES.INITIALIZED) { - this._binding.bind(bindDn, passwordUser, (err: number) => { - if (err) { - const customError: any = errorHandler.errorSelection(err); - this._stateClient = E_STATES.INITIALIZED; - reject(new customError(errorMessages.ldapBindErrorMessage)); - } else { - this._stateClient = E_STATES.BOUND; - resolve(); - } - }); - } else { - reject(new StateError(errorMessages.uninitializedErrorMessage)); - } - }); - } - - /** - * Search operation. - * - * @method search - * @param {String} searchBase the base for the search. - * @param {String} scope scope for the search, can be BASE, ONE or - * SUBTREE - * @param {String} searchFilter search filter.If not provided, - * the default filter, (objectClass=*), is used. - * @return {Promise} That resolves and returns a string with the search - * results. Rejects in case of error. - * */ - search(searchBase: string, scope: string, searchFilter: string): Promise { - return new Promise((resolve, reject) => { - if (this._stateClient !== E_STATES.BOUND) { - reject(new StateError(errorMessages.bindErrorMessage)); - } else { - checkParameters.validateStrings(searchBase, searchFilter, scope); - - if (scopeObject[scope] === undefined) { - throw new Error(errorMessages.scopeSearchErrorMessage); - } - - this._binding.search( - searchBase, scopeObject[scope], searchFilter, (err: number, result: string) => { - if (err) { - const customError: any = errorHandler.errorSelection(err); - reject(new customError(errorMessages.ldapSearchErrorMessage)); - } else { - let resJSON: string | JSON | IldifObject; - try { - resJSON = result === '' ? result : ldif.parse(result); - } catch (ldifErr) { - resJSON = ldifConstruct(result); - } - resolve(resJSON); - } - }); - } - }); - } - - /** - * Search operation with results displayed page by page. - * - * @method pagedSearch - * @param {String} searchBase the base for the search. - * @param {String} scope scope for the search, can be BASE, ONE or - * SUBTREE - * @param {String} searchFilter search filter. - * @param {int} pageSize The number of entries per LDAP page - * @return {Promise} that resolves to a readable stream or rejects to a - * Error; - */ - pagedSearch(searchBase: string, scope: string, searchFilter: string, pageSize: number) - : Promise { - return new Promise((resolve, reject) => { - if (this._stateClient === E_STATES.BOUND) { - checkParameters.validateStrings(searchBase, searchFilter, scope); - - if (scopeObject[scope] === undefined) { - throw new Error(errorMessages.scopeSearchErrorMessage); - } - - if (!_.isNumber(pageSize)) { - throw new TypeError(errorMessages.typeErrorMessage); - } - this._searchID += 1; - resolve( - new SearchStream( - searchBase, scopeObject[scope], searchFilter, pageSize, - this._searchID, this._binding)); - } - reject(new StateError(errorMessages.bindErrorMessage)); - }); - } - - - /** - * Compare operation. - * - * @method compare - * @param {String} dn The dn of the entry to compare. - * @param {String} attr The attribute given for comparison. - * @param {String} value Value sent to compare. - * @return {Promise} That resolves and returns True if the elements are - * equal - * or - * False otherwise. - * Rejects if an error occurs. - */ - - compare(dn: string, attr: string, value: string): Promise { - const LDAP_COMPARE_TRUE: number = 6; - return new Promise((resolve, reject) => { - if (this._stateClient !== E_STATES.BOUND) { - reject(new StateError(errorMessages.bindErrorMessage)); - } else { - checkParameters.validateStrings(dn, attr, value); - - this._binding.compare(dn, attr, value, (err: number, result: number) => { - if (err) { - const customError: any = errorHandler.errorSelection(err); - reject(new customError(errorMessages.ldapCompareErrorMessage)); - } else { - const res: boolean = result === LDAP_COMPARE_TRUE; - resolve(res); - } - }); - } - }); - } - - /** - * Perform an LDAP modify operation - * - * @method modify - * @param {String} dn The dn of the entry to modify - * @param {IchangeSchema} jsonChange The attribute and value to be changed - * @param {IcontrolSchema} [controls] Request to execute a specific control - * or - * multiple controls. This parameter is optional. - * @return {Promise} That resolves if LDAP modified successfully the - * entry. - * Reject if LDAP rejects the operation or the client's state is not - * BOUND - */ - modify(dn: string, jsonChange: IchangeSchema, controls: IcontrolSchema) - : Promise { - return new Promise((resolve, reject) => { - if (this._stateClient !== E_STATES.BOUND) { - reject(new StateError(errorMessages.bindErrorMessage)); - } else { - checkParameters.validateStrings(dn); - const changes: object[] = checkParameters.checkModifyChange(jsonChange); - const ctrls: object[] | null = checkParameters.checkControl(controls); - - this._binding.modify(dn, changes, ctrls, (err: number, result: string | number) => { - if (err) { - const customError: any = errorHandler.errorSelection(err); - reject(new customError(errorMessages.ldapModifyErrorMessage)); - } else { - const resJSON: string | number = result === 0 ? result : ldif.parse(result); - resolve(resJSON); - } - }); - } - }); - } - - /** - * Perform an LDAP rename operation - * - * @method rename - * @param {String} dn The dn of the entry to rename - * @param {String} newRdn The new rdn for the dn - * @param {String} newParent New parent for the rdn - * @param {IcontrolSchema} [controls] Request to execute a specific control - * or - * multiple controls. This parameter is optional. - * @return {Promise} Will fulfil with a result from a control if the - * operation is successful, else will reject with an LDAP error number. - * */ - rename(dn: string, newRdn: string, newParent: string, controls: IcontrolSchema) - : Promise { - return new Promise((resolve, reject) => { - if (this._stateClient !== E_STATES.BOUND) { - reject(new StateError(errorMessages.bindErrorMessage)); - } else { - checkParameters.validateStrings(dn, newRdn, newParent); - const ctrls: object[] | null = checkParameters.checkControl(controls); - - this._binding.rename(dn, newRdn, newParent, ctrls, (err:number, result:string | number) => { - if (err) { - const customError: any = errorHandler.errorSelection(err); - reject(new customError(errorMessages.ldapRenameErrorMessage)); - } else { - const resJSON: string | number = result === 0 ? result : ldif.parse(result); - resolve(resJSON); - } - }); - } - }); - } - - /** - * Perform an LDAP delete operation - * - * @method delete - * @param {String} dn the dn entry to be deleted. - * @param {IcontrolSchema} [controls] Request to execute a specific control - * or - * multiple controls. This parameter is optional. - * @return {Promise} promise that resolves if the element provided was - * deleted - * or rejects if not. - * */ - delete(dn: string, controls: IcontrolSchema): Promise { - return new Promise((resolve, reject) => { - if (this._stateClient !== E_STATES.BOUND) { - reject(new StateError(errorMessages.bindErrorMessage)); - } else { - checkParameters.validateStrings(dn); - const ctrls: object[] | null = checkParameters.checkControl(controls); - - this._binding.delete(dn, ctrls, (err: number, result: string | number) => { - if (err) { - const customError: any = errorHandler.errorSelection(err); - reject(new customError(errorMessages.ldapDeleteErrorMessage)); - } else { - const resJSON: string | number = result === 0 ? result : ldif.parse(result); - resolve(resJSON); - } - }); - } - }); - } - - /** - * Perform an LDAP password change operation - * - * @method changePassword - * @param {String} userDN The user dn which the password will be changed - * @param {String} oldPassword Old password of user - * @param {String} newPassword New password for user - * @return {Promise} Will fulfil with a result of success if the - * Old password is given correctly, the parameters are string type and - * the state of client is BOUND else will fail with type error or LDAP ERROR. - * */ - changePassword(userDN: string, oldPassword: string, newPassword: string): Promise { - return new Promise((resolve, reject) => { - if (this._stateClient !== E_STATES.BOUND) { - reject(new StateError(errorMessages.bindErrorMessage)); - } else { - checkParameters.validateStrings(userDN, oldPassword, newPassword); - - this._binding.changePassword( - userDN, oldPassword, newPassword, (err: number) => { - if (err) { - const customError: any = errorHandler.errorSelection(err); - reject( - new customError(errorMessages.ldapChangePasswordErrorMessage)); - } else { - resolve(); - } - }); - } - }); - } - /** - * Perform an LDAP add operation - * - * @method add - * @param {String} dn dn of the entry to add Ex: 'cn=foo, o=example.., - * NOTE:every entry except the first one,cn=foo in this case, must already - * exist' - * @param {IaddEntrySchema} entry ldif format to be added, needs to have a - * structure that is mappable to a LDAPMod structure - * @param {IcontrolSchema} [controls] Request to execute a specific control - * or - * multiple controls. This parameter is optional. - * @return {Promise} that fulfils if the add was successful, rejects - * otherwise. - * */ - add(dn: string, entry: IaddEntrySchema, controls: IcontrolSchema): Promise { - return new Promise((resolve, reject) => { - if (this._stateClient !== E_STATES.BOUND) { - reject(new StateError(errorMessages.bindErrorMessage)); - } else { - checkParameters.validateStrings(dn); - const entryAttr: object[] = checkParameters.checkEntryObject(entry); - const ctrls: object[] | null = checkParameters.checkControl(controls); - - this._binding.add(dn, entryAttr, ctrls, (err: number, result: string | number) => { - if (err) { - const customError: any = errorHandler.errorSelection(err); - reject(new customError(errorMessages.ldapAddErrorMessage)); - } else { - const resJSON: string | number = result === 0 ? result : ldif.parse(result); - resolve(resJSON); - } - }); - } - }); - } - - /** - * Unbind from a LDAP server. - * - * @method unbind - * @return {Promise} That resolves if the LDAP structure was unbound. - * Reject if the LDAP could not unbind. - */ - unbind(): Promise { - return new Promise((resolve, reject) => { - if (this._stateClient !== E_STATES.UNBOUND) { - this._binding.unbind((err: number) => { - if (err) { - const customError: any = errorHandler.errorSelection(err); - reject(new customError(errorMessages.ldapUnbindErrorMessage)); - } else { - this._stateClient = E_STATES.UNBOUND; - resolve(); - } - }); - } else { - resolve(); - } - }); - } - -} diff --git a/ldapWrapTs/messages.json b/ldapWrapTs/messages.json deleted file mode 100644 index 2d310d5..0000000 --- a/ldapWrapTs/messages.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "bindErrorMessage": "The operation failed. It could be done if the state of the client is BOUND", - "typeErrorMessage": "Expected Valid String parameter", - "entryObjectError": "Invalid entryObject array", - "controlArrayError": "The control is not an array", - "controlPropError": "Invalid control array", - "invalidJSONMessage":"Invalid JSON", - "scopeSearchErrorMessage": "Invalid scope", - "ldapStartTlsErrorMessage":"Ldap Start TLS operation failed, check description for additional info", - "ldapSearchErrorMessage":"Ldap Search operation failed, check description for additional info", - "ldapBindErrorMessage": "Ldap Bind operation failed, check description for additional info", - "ldapModifyErrorMessage":"Ldap Modify operation failed, check description for additional info", - "ldapCompareErrorMessage":"Ldap Compare operation failed, check description for additional info", - "ldapRenameErrorMessage":"Ldap Rename operation failed, check description for additional info", - "ldapDeleteErrorMessage":"Ldap Delete operation failed, check description for additional info", - "ldapUnbindErrorMessage":"Ldap Unbind operation failed, check description for additional info", - "ldapAddErrorMessage": "Ldap Add operation failed, check description for additional info", - "ldapChangePasswordErrorMessage": "Ldap Change password operation failed, check description for additional info", - "uninitializedErrorMessage": "Please initialize", - "initErrorMessage": "Initialize failed!", - "ldapInitializeErrorMessage":"Ldap Initialize operation failed, check description for additional info" - - } \ No newline at end of file diff --git a/ldapWrapTs/messages.ts b/ldapWrapTs/messages.ts deleted file mode 100644 index deacb16..0000000 --- a/ldapWrapTs/messages.ts +++ /dev/null @@ -1,22 +0,0 @@ -export interface RootObject { - bindErrorMessage: string; - typeErrorMessage: string; - entryObjectError: string; - controlArrayError: string; - controlPropError: string; - invalidJSONMessage: string; - scopeSearchErrorMessage: string; - ldapStartTlsErrorMessage: string; - ldapSearchErrorMessage: string; - ldapBindErrorMessage: string; - ldapModifyErrorMessage: string; - ldapCompareErrorMessage: string; - ldapRenameErrorMessage: string; - ldapDeleteErrorMessage: string; - ldapUnbindErrorMessage: string; - ldapAddErrorMessage: string; - ldapChangePasswordErrorMessage: string; - uninitializedErrorMessage: string; - initErrorMessage: string; - ldapInitializeErrorMessage: string; -} diff --git a/ldapWrapTs/schemas/add_entry_schema.json b/ldapWrapTs/schemas/add_entry_schema.json deleted file mode 100644 index 8b39c5b..0000000 --- a/ldapWrapTs/schemas/add_entry_schema.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "id": "https://www.hufsm.com/openldap/add_entry/", - "type": "object", - "properties": { - "attr": { - "id": "https://www.hufsm.com/openldap/add_entry/attr", - "type": "string" - }, - "vals": { - "id": "https://www.hufsm.com/openldap/add_entry/vals", - "type": "array" - } - }, - "required": [ - "attr", - "vals" - ] -} diff --git a/ldapWrapTs/schemas/add_entry_schema.ts b/ldapWrapTs/schemas/add_entry_schema.ts deleted file mode 100644 index 6a8d484..0000000 --- a/ldapWrapTs/schemas/add_entry_schema.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface IaddEntrySchema { - attr: string; - vals: string[]; -} diff --git a/ldapWrapTs/schemas/change_schema.json b/ldapWrapTs/schemas/change_schema.json deleted file mode 100644 index 27ba93f..0000000 --- a/ldapWrapTs/schemas/change_schema.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "id": "https://www.hufsm.com/openldap/change/", - "type": "object", - "properties": { - "op": { - "id": "https://www.hufsm.com/openldap/change/op", - "type": "string" - }, - "attr": { - "id": "https://www.hufsm.com/openldap/change/attr", - "type": "string" - }, - "vals": { - "id": "https://www.hufsm.com/openldap/change/vals", - "type": "array" - } - }, - "required": [ - "op", - "attr", - "vals" - ] -} diff --git a/ldapWrapTs/schemas/change_schema.ts b/ldapWrapTs/schemas/change_schema.ts deleted file mode 100644 index db13c22..0000000 --- a/ldapWrapTs/schemas/change_schema.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface Val { - oldVal: string; - newVal: string; -} - -export interface IchangeSchema { - op: string; - attr: string; - vals: Val[]; -} diff --git a/ldapWrapTs/schemas/control_schema.json b/ldapWrapTs/schemas/control_schema.json deleted file mode 100644 index ee7bc42..0000000 --- a/ldapWrapTs/schemas/control_schema.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "id": "https://www.hufsm.com/openldap/controlJson/", - "type": "object", - "properties": { - "oid": { - "id": "https://www.hufsm.com/openldap/controlJson/oid", - "type": "string" - }, - "value": { - "id": "https://www.hufsm.com/openldap/controlJson/value", - "type": "array" - }, - "isCritical": { - "id": "https://www.hufsm.com/openldap/controlJson/isCritical", - "type": "boolean" - } - }, - "required": [ - "oid", - "value", - "isCritical" - ] -} \ No newline at end of file diff --git a/ldapWrapTs/schemas/control_schema.ts b/ldapWrapTs/schemas/control_schema.ts deleted file mode 100644 index 4e1359d..0000000 --- a/ldapWrapTs/schemas/control_schema.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface IcontrolSchema { - oid: string; - value: string[]; - isCritical: boolean; -} diff --git a/ldapWrapTs/schemas/update_attr_schema.json b/ldapWrapTs/schemas/update_attr_schema.json deleted file mode 100644 index 1b935b2..0000000 --- a/ldapWrapTs/schemas/update_attr_schema.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "id": "https://www.hufsm.com/openldap/update/", - "type": "object", - "properties": { - "oldVal": { - "id": "https://www.hufsm.com/openldap/update/oldVal", - "type": "string" - }, - "attr": { - "id": "https://www.hufsm.com/openldap/update/newVal", - "type": "string" - } - }, - "required": [ - "oldVal", - "newVal" - ] -} diff --git a/ldapWrapTs/schemas/update_attr_schema.ts b/ldapWrapTs/schemas/update_attr_schema.ts deleted file mode 100644 index a8d9182..0000000 --- a/ldapWrapTs/schemas/update_attr_schema.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface IupdateAttrSchema { - oldVal: string; - newVal: string; -} diff --git a/ldapWrapTs/stream_interface.ts b/ldapWrapTs/stream_interface.ts deleted file mode 100644 index f947c18..0000000 --- a/ldapWrapTs/stream_interface.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { Readable as Readable } from 'stream'; -import { RootObject } from './messages'; -import * as errorHandler from './errors/error_dispenser'; -import ldifConstruct, { IldifObject } from './utils/construct_ldif'; - -const errorMessages: RootObject = require('./messages.json'); -const ldif: any = require('ldif'); - -/** - * @class PagedSearchStream - * class that extends the readable stream class - */ -export default class PagedSearchStream extends Readable { - - /** - * - * @param {String} base the base for the search. - * @param {unsigned int} scope scope for the search, can be 0(BASE), 1(ONE) or - * 2(SUBTREE) - * @param {String} filter search filter. - * @param {unsigned int} pageSize number of results displayed per page. - * @param {unsigned int} searchId unique search id. - * @param {Object} ldapInstance the ldap instance the search belongs to. - */ - - objectMode: boolean; - _binding: any; - _base: string; - _scope: number; - _filter: string; - _pageSize: number; - _searchId: number; - _lastResult: boolean; - constructor(base: string, scope: number, filter: string, pageSize: number, - searchId: number, ldapInstance: any) { - super(); - this.objectMode = true; - this._binding = ldapInstance; - this._base = base; - this._scope = scope; - this._filter = filter; - this._pageSize = pageSize; - this._searchId = searchId; - this._lastResult = false; - } - - _read(): void { - if (this._lastResult) { - this.push(null); - } else { - this._binding.pagedSearch( - this._base, this._scope, this._filter, this._pageSize, this._searchId, - (err: number, page: string, morePages: boolean) => { - if (err) { - const customError: any = errorHandler.errorSelection(err); - this.emit('err', new customError(errorMessages.ldapSearchErrorMessage)); - this.push(null); - } else { - if (!morePages) this._lastResult = true; - let resJSON: string | JSON | IldifObject; - try { - resJSON = page === '' ? page : ldif.parse(page); - } catch (ldifErr) { - resJSON = ldifConstruct(page); - } - this.push(JSON.stringify(resJSON)); - } - - }); - } - } - -} diff --git a/ldapWrapTs/utils/check_variable_format.ts b/ldapWrapTs/utils/check_variable_format.ts deleted file mode 100644 index 3f564d5..0000000 --- a/ldapWrapTs/utils/check_variable_format.ts +++ /dev/null @@ -1,132 +0,0 @@ -import * as Ajv from 'ajv'; -import * as _ from 'underscore'; - -import { IchangeSchema } from '../schemas/change_schema'; -import { IcontrolSchema } from '../schemas/control_schema'; -import { IaddEntrySchema } from '../schemas/add_entry_schema'; -import { IupdateAttrSchema } from '../schemas/update_attr_schema'; -import ValidationError from '../errors/validation_error'; -import { RootObject } from '../messages'; - -const changeSchema: IchangeSchema = require('../schemas/change_schema.json'); -const controlSchema: IcontrolSchema = require('../schemas/control_schema.json'); -const addEntrySchema: IaddEntrySchema = require('../schemas/add_entry_schema.json'); -const updateAttrSchema: IupdateAttrSchema = require('../schemas/update_attr_schema.json'); -const errorMessages: RootObject = require('../messages.json'); - -const ajv: Ajv.Ajv = new Ajv(); - -/** - * @module checkVariableFormat - * @class CheckParam - */ -export default class CheckParam { - - /** - * Checks if the arguments provided are Strings. - * - * @method validateStrings - * @return Throws an error in case the provided parameters aren't valid - * strings - */ - - static validateStrings(...arg: string[]): void { - _.each(arg, element => { - if (!_.isString(element)) { - throw new TypeError(errorMessages.typeErrorMessage); - } - }); - } - - /** - * Verify the modify change parameter. - * - * @method checkModifyChange - * @param {Object || Array} changes parameter set for verification - * @return Throws error in case the changes is not valid. Return the changes as - * an array in case entry is valid - */ - static checkModifyChange(changes: IchangeSchema): object[] { - const changesAttr = !_.isArray(changes) ? [changes] : changes; - const changeBuildArr: object[] = []; - changesAttr.forEach(element => { - const valid = ajv.validate(changeSchema, element); - if (!valid) { - throw new ValidationError(errorMessages.invalidJSONMessage, undefined, ajv.errors); - } - if (element.op === 'update') { - const deleteVals: string[] = []; - const addVals: string[] = []; - - element.vals.forEach((val) => { - const validVal = ajv.validate(updateAttrSchema, val); - if (!validVal) { - throw new ValidationError(errorMessages.invalidJSONMessage, undefined, ajv.errors); - } else { - deleteVals.push(val.oldVal); - addVals.push(val.newVal); - } - }); - - const ldapDeleteObject = { - op: 'delete', - attr: element.attr, - vals: deleteVals, - }; - changeBuildArr.push(ldapDeleteObject); - const ldapAddObject = { - op: 'add', - attr: element.attr, - vals: addVals, - }; - changeBuildArr.push(ldapAddObject); - } else { - changeBuildArr.push(element); - } - }); - return changeBuildArr; - } - - /** - * Verify the control parameter. - * - * @method checkControl - * @param {Object || Array} controls parameter set for verification - * @return Throws error in case the controls is not valid with the schema - * members. Return the array of control or null if the control is undefined. - */ - static checkControl(controls: Object | Object[]): Object[] | null { - if (controls !== undefined) { - const ctrls = !_.isArray(controls) ? [controls] : controls; - ctrls.forEach(element => { - const valid = ajv.validate(controlSchema, element); - if (!valid) { - throw new ValidationError(errorMessages.controlPropError, undefined, ajv.errors); - } - }); - return ctrls; - } - return null; - } - - /** - * Verify the entry parameter. - * - * @method checkControlArray - * @param {Object || Array} entry parameter set for verification - * @return Throws error in case the entry is not valid. Return the entry as - * an array in case entry is valid - */ - static checkEntryObject(entry: Object | Object[]): Object[] { - const entryAttr = !_.isArray(entry) ? [entry] : entry; - - entryAttr.forEach(element => { - const valid = ajv.validate(addEntrySchema, element); - if (!valid) { - throw new ValidationError(errorMessages.entryObjectError, undefined, ajv.errors); - } - }); - return entryAttr; - } - -} \ No newline at end of file diff --git a/ldapWrapTs/utils/construct_ldif.ts b/ldapWrapTs/utils/construct_ldif.ts deleted file mode 100644 index b564826..0000000 --- a/ldapWrapTs/utils/construct_ldif.ts +++ /dev/null @@ -1,70 +0,0 @@ - -export interface Iattribute { - type: string, - options: never[], - attribute: string, -} - -export interface Ivalue { - type: string, - value: string, -} - -export interface IattributeObject { - attribute: Iattribute, - value: Ivalue, -} - -export interface IentryObject { - type: string, - dn: string, - attributes: IattributeObject[], -} - -export interface IldifObject { - type: string, - version: null, - entries: IentryObject[], -} - -export default function constructLdif(ldifString: string) { - const ldifObject: IldifObject = { - type: 'content', - version: null, - entries: [], - }; - const resultArr: string[] = ldifString.split('\n'); - const entryObject: IentryObject = { - type: 'record', - dn: '', - attributes: [], - }; - - resultArr.forEach((element, index, array) => { - if (element.trim()) { - const elementArr = element.split(':'); - const objectKey = elementArr[0]; - const objectVal = elementArr[1]; - if (objectKey !== 'dn') { - const constructAttrObj = { - attribute: { - type: 'attribute', - options: [], - attribute: objectKey, - }, - value: - { - type: 'value', - value: objectVal, - }, - }; - entryObject.attributes.push(constructAttrObj); - } else { - entryObject.dn = objectVal; - } - } else if (index === array.length - 1) { - ldifObject.entries.push(entryObject); - } - }); - return ldifObject; -} diff --git a/package.json b/package.json index 6b244aa..f2e1f3e 100644 --- a/package.json +++ b/package.json @@ -8,31 +8,19 @@ "url": "https://github.com/hufsm/openldapjs.git" }, "dependencies": { - "@types/ajv": "^1.0.0", - "@types/bluebird": "^3.5.18", - "@types/lodash": "^4.14.88", - "@types/underscore": "^1.8.5", "ajv": "5.3.0", "bluebird": "3.4.3", "ldif": "0.5.1", "nan": "2.6.0", - "github": "^12.1.0", - "node-pre-gyp": "^0.6.39", - "tslint": "^5.8.0", "underscore": "1.8.3" }, "devDependencies": { - "@types/node": "^8.0.58", "eslint": "4.7.1", "eslint-config-airbnb": "15.1.0", - "eslint-config-airbnb-base": "^12.1.0", "eslint-plugin-import": "2.7.0", "eslint-plugin-jsx-a11y": "5.1.1", "eslint-plugin-react": "7.3.0", - "istanbul": "0.4.5", - "mocha": "4.0.1", - "should": "11.2.0", - "typescript-eslint-parser": "^9.0.1" + "should": "11.2.0" }, "scripts": { "coverage": "istanbul cover \"./node_modules/mocha/bin/_mocha\" ./test/*.js", diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 83e2399..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "compilerOptions": { - /* Basic Options */ - "target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - // "lib": [], /* Specify library files to be included in the compilation: */ - "allowJs": false, /* Allow javascript files to be compiled. */ - // "checkJs": true, /* Report errors in .js files. */ - "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - "declaration": true, /* Generates corresponding '.d.ts' file. */ - "declarationDir": "./TSdeclaration/@types", - // "sourceMap": true, /* Generates corresponding '.map' file. */ - // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./libBuildTLS/libs", /* Redirect output structure to the directory. */ - // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ - // "removeComments": true, /* Do not emit comments to output. */ - // "noEmit": true, /* Do not emit outputs. */ - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ - // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ - - /* Strict Type-Checking Options */ - "strict": true, /* Enable all strict type-checking options. */ - "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - "strictNullChecks": true, /* Enable strict null checks. */ - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ - // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ - - /* Additional Checks */ - "noUnusedLocals": true, /* Report errors on unused locals. */ - "noUnusedParameters": true, /* Report errors on unused parameters. */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - - /* Module Resolution Options */ - "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - "typeRoots": ["@types", "./ldapWrapTs/@types"], /* List of folders to include type definitions from. */ - "types": ["node"], /* Type declaration files to be included in compilation. */ - "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - - /* Source Map Options */ - // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - - /* Experimental Options */ - "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - "plugins": [ - { - "name": "tslint-language-service" - } - ] - }, - "include": [ - "./ldapWrapTs/**/*" - ], - "exclude": [ - "node_modules" - ] -} \ No newline at end of file diff --git a/tslint.json b/tslint.json deleted file mode 100644 index a8c425f..0000000 --- a/tslint.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": [ - "tslint-config-airbnb" - ], - "rules": { - "no-trailing-whitespace": true, - "whitespace": true, - "typedef-whitespace": true - } -} \ No newline at end of file From 7c26abf3004dd40d7662c75b66c57c1e78d0d546 Mon Sep 17 00:00:00 2001 From: Radu Date: Tue, 30 Jan 2018 11:44:27 +0200 Subject: [PATCH 3/8] changed add op --- sample/add_operation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/add_operation.js b/sample/add_operation.js index 5a643f2..72bbef8 100644 --- a/sample/add_operation.js +++ b/sample/add_operation.js @@ -1,6 +1,6 @@ 'use strict'; -const LdapClientLib = require('../libs/ldap_async_wrap.js'); +const LdapClientLib = require('../index').Client; const ldif = require('ldif'); const config = require('./config.json'); @@ -40,5 +40,5 @@ newClient.initialize() }); }) .catch((err) => { - console.log(`${err.name} ${err.constructor.description}`); + console.log(err.toString()); }); From 663db28ad3c9ff02a452e406185af4bed0716dd7 Mon Sep 17 00:00:00 2001 From: Radu Date: Tue, 30 Jan 2018 11:45:04 +0200 Subject: [PATCH 4/8] pakcage changed --- package.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f2e1f3e..043dbcb 100644 --- a/package.json +++ b/package.json @@ -15,12 +15,15 @@ "underscore": "1.8.3" }, "devDependencies": { + "istanbul": "0.4.5", + "mocha": "4.0.1", "eslint": "4.7.1", "eslint-config-airbnb": "15.1.0", "eslint-plugin-import": "2.7.0", "eslint-plugin-jsx-a11y": "5.1.1", - "eslint-plugin-react": "7.3.0", - "should": "11.2.0" + "should": "11.2.0", + "eslint-plugin-react": "7.3.0" + }, "scripts": { "coverage": "istanbul cover \"./node_modules/mocha/bin/_mocha\" ./test/*.js", @@ -42,4 +45,4 @@ "directories": { "test": "test" } -} \ No newline at end of file +} From c3fc529fe57fedc4ba9b5a3df39efeef65b5a82d Mon Sep 17 00:00:00 2001 From: Radu Date: Tue, 30 Jan 2018 11:55:04 +0200 Subject: [PATCH 5/8] Switched samples requires, updated error catching. --- sample/README.MD | 3 +++ sample/change_password_operation.js | 4 ++-- sample/compare_operation.js | 4 ++-- sample/delete_operation.js | 4 ++-- sample/extended_operation.js | 4 ++-- sample/modify_operation.js | 4 ++-- sample/page_search_operation.js | 8 ++++---- sample/rename_oparation.js | 4 ++-- sample/search_operation.js | 4 ++-- 9 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 sample/README.MD diff --git a/sample/README.MD b/sample/README.MD new file mode 100644 index 0000000..b66854a --- /dev/null +++ b/sample/README.MD @@ -0,0 +1,3 @@ +# TODO + +Nothing to see here... \ No newline at end of file diff --git a/sample/change_password_operation.js b/sample/change_password_operation.js index f7c9375..3529531 100644 --- a/sample/change_password_operation.js +++ b/sample/change_password_operation.js @@ -1,6 +1,6 @@ 'use strict'; -const LdapClientLib = require('../libs/ldap_async_wrap.js'); +const LdapClientLib = require('../index').Client; const config = require('./config.json'); const newClient = new LdapClientLib(config.ldapAuthentication.host); @@ -23,5 +23,5 @@ newClient.initialize() console.log('The user\'s password was changed with success'); }) .catch((err) => { - console.log(`${err.name} ${err.constructor.description}`); + console.log(err.toString()); }); diff --git a/sample/compare_operation.js b/sample/compare_operation.js index fac6822..52a8ccb 100644 --- a/sample/compare_operation.js +++ b/sample/compare_operation.js @@ -1,6 +1,6 @@ 'use strict'; -const LdapClientLib = require('../libs/ldap_async_wrap.js'); +const LdapClientLib = require('../index').Client; const config = require('./config.json'); @@ -31,5 +31,5 @@ newClient.initialize() console.log(`Compare result: ${result}`); }) .catch((err) => { - console.log(`${err.name} ${err.constructor.description}`); + console.log(err.toString()); }); diff --git a/sample/delete_operation.js b/sample/delete_operation.js index a121e4b..9b10a04 100644 --- a/sample/delete_operation.js +++ b/sample/delete_operation.js @@ -1,6 +1,6 @@ 'use strict'; -const LdapClientLib = require('../libs/ldap_async_wrap.js'); +const LdapClientLib = require('../index').Client; const ldif = require('ldif'); const config = require('./config.json'); @@ -35,5 +35,5 @@ newClient.initialize() }); }) .catch((err) => { - console.log(`${err.name} ${err.constructor.description}`); + console.log(err.toString()); }); diff --git a/sample/extended_operation.js b/sample/extended_operation.js index 64c9b64..83eb95f 100644 --- a/sample/extended_operation.js +++ b/sample/extended_operation.js @@ -1,6 +1,6 @@ 'use strict'; -const LdapClientLib = require('../libs/ldap_async_wrap.js'); +const LdapClientLib = require('../index').Client; const config = require('./config.json'); @@ -34,6 +34,6 @@ newClient.initialize() console.log(`The current user is: ${res}`); }) .catch((err) => { - console.log(`${err.name} ${err.constructor.description}`); + console.log(err.toString()); }); diff --git a/sample/modify_operation.js b/sample/modify_operation.js index 6bd57eb..3c2e4b3 100644 --- a/sample/modify_operation.js +++ b/sample/modify_operation.js @@ -1,6 +1,6 @@ 'use strict'; -const LdapClientLib = require('../libs/ldap_async_wrap.js'); +const LdapClientLib = require('../index').Client; const ldif = require('ldif'); @@ -48,5 +48,5 @@ newClient.initialize() }); }) .catch((err) => { - console.log(`${err.name} ${err.constructor.description}`); + console.log(err.toString()); }); diff --git a/sample/page_search_operation.js b/sample/page_search_operation.js index a567350..69b9b92 100644 --- a/sample/page_search_operation.js +++ b/sample/page_search_operation.js @@ -1,6 +1,6 @@ 'use strict'; -const LdapClientLib = require('../libs/ldap_async_wrap.js'); +const LdapClientLib = require('../index').Client; const ldif = require('ldif'); @@ -41,8 +41,8 @@ newClient.initialize() result.on('err', (err) => { console.log('-----------------'); console.error(`Error name: ${err.name}`); - console.error(`Error code: ${err.constructor.code}`); - console.error(`Error description: ${err.constructor.description}`); + console.error(`Error code: ${err.code}`); + console.error(`Error description: ${err.description}`); console.log('-----------------'); }); @@ -51,5 +51,5 @@ newClient.initialize() }); }) .catch((err) => { - console.log(`${err.name} ${err.constructor.description}`); + console.log(err.toString()); }); diff --git a/sample/rename_oparation.js b/sample/rename_oparation.js index 26ba411..87239b7 100644 --- a/sample/rename_oparation.js +++ b/sample/rename_oparation.js @@ -1,6 +1,6 @@ 'use strict'; -const LdapClientLib = require('../libs/ldap_async_wrap.js'); +const LdapClientLib = require('../index').Client; const ldif = require('ldif'); const config = require('./config.json'); @@ -41,5 +41,5 @@ newClient.initialize() }); }) .catch((err) => { - console.log(`${err.name} ${err.constructor.description}`); + console.log(err.toString()); }); diff --git a/sample/search_operation.js b/sample/search_operation.js index 4b17097..ea5a541 100644 --- a/sample/search_operation.js +++ b/sample/search_operation.js @@ -1,6 +1,6 @@ 'use strict'; -const LdapClientLib = require('../libs/ldap_async_wrap.js'); +const LdapClientLib = require('../index').Client; const ldif = require('ldif'); @@ -33,5 +33,5 @@ newClient.initialize() }); }) .catch((err) => { - console.log(`${err.name} ${err.constructor.description}`); + console.log(err.toString()); }); From 6fee1cd0ea3d6c48f2db06a966f7c6c1961c7374 Mon Sep 17 00:00:00 2001 From: Radu Date: Tue, 30 Jan 2018 13:00:45 +0200 Subject: [PATCH 6/8] typo corrected and readme added --- sample/README.MD | 17 ++++++++++++-- sample/rename_operation.js | 45 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 sample/rename_operation.js diff --git a/sample/README.MD b/sample/README.MD index b66854a..cf6b460 100644 --- a/sample/README.MD +++ b/sample/README.MD @@ -1,3 +1,16 @@ -# TODO +# Code Samples -Nothing to see here... \ No newline at end of file +Sample code for all function calls: + +- [Add](./add_operation.js) +- [Delete](./delete_operation.js) +- [Compare](./compare_operation.js) +- [Change Password](./change_password_operation.js) +- [Extended Operations](./extended_operation.js) +- [Modify](./modify_operation.js) +- [Paged Search](./page_search_operation.js) +- [Rename](./rename_operation.js) +- [Search](./search_operation.js) + + +The samples use credentials and parameter values from the [config](./config.json) file, check that out for further info on how to use the library. \ No newline at end of file diff --git a/sample/rename_operation.js b/sample/rename_operation.js new file mode 100644 index 0000000..87239b7 --- /dev/null +++ b/sample/rename_operation.js @@ -0,0 +1,45 @@ +'use strict'; + +const LdapClientLib = require('../index').Client; +const ldif = require('ldif'); + +const config = require('./config.json'); + +const newClient = new LdapClientLib(config.ldapAuthentication.host); + +const prePostReadControls = [ + config.ldapControls.ldapModificationControlPostRead, + config.ldapControls.ldapModificationControlPreRead, +]; + +newClient.initialize() + .then(() => { + console.log('Init successfully'); + return newClient.startTLS(config.ldapAuthentication.pathFileToCert); + }) + .then(() => { + console.log('TLS successfully'); + return newClient.bind(config.ldapAuthentication.dnUser, config.ldapAuthentication.passwordUser); + }) + .then(() => { + console.log('Bind successfully'); + return newClient.rename(config.ldapRename.firstDNChange, config.ldapRename.firstRDN, + config.ldapRename.newParent); + }) + .then(() => { + console.log('The user was renamed with success'); + return newClient.rename(config.ldapRename.secondDNChange, config.ldapRename.secondRDN, + config.ldapRename.newParent, prePostReadControls); + }) + .then((result) => { + const resultJson = ldif.parse(result); + const outputOptions = {}; + + const JSONstructure = resultJson.toObject(outputOptions); + JSONstructure.entries.forEach((element) => { + console.log(element); + }); + }) + .catch((err) => { + console.log(err.toString()); + }); From e383b47de4f4c566dd41dbfdd27c95cca923e26c Mon Sep 17 00:00:00 2001 From: Radu Date: Tue, 30 Jan 2018 13:19:56 +0200 Subject: [PATCH 7/8] Readme updated and modify slightly change to easier showcase post/preread controls. --- sample/README.MD | 4 +++- sample/modify_operation.js | 12 ++++++++-- sample/rename_oparation.js | 45 -------------------------------------- 3 files changed, 13 insertions(+), 48 deletions(-) delete mode 100644 sample/rename_oparation.js diff --git a/sample/README.MD b/sample/README.MD index cf6b460..7bc71fe 100644 --- a/sample/README.MD +++ b/sample/README.MD @@ -13,4 +13,6 @@ Sample code for all function calls: - [Search](./search_operation.js) -The samples use credentials and parameter values from the [config](./config.json) file, check that out for further info on how to use the library. \ No newline at end of file +The samples use credentials and parameter values from the [config](./config.json) file, check that out for further info on how to use the library. + +For more details on the control parameters, please check the [documentation](../docs/controls.MD) \ No newline at end of file diff --git a/sample/modify_operation.js b/sample/modify_operation.js index 3c2e4b3..9432543 100644 --- a/sample/modify_operation.js +++ b/sample/modify_operation.js @@ -17,8 +17,16 @@ const changes = [ ]; const prePostReadControls = [ - config.ldapControls.ldapModificationControlPostRead, - config.ldapControls.ldapModificationControlPreRead, + { + oid: 'preread', + value: ['cn'], + isCritical: false, + }, + { + oid: 'postread', + value: ['cn'], + isCritical: false, + }, ]; newClient.initialize() diff --git a/sample/rename_oparation.js b/sample/rename_oparation.js deleted file mode 100644 index 87239b7..0000000 --- a/sample/rename_oparation.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -const LdapClientLib = require('../index').Client; -const ldif = require('ldif'); - -const config = require('./config.json'); - -const newClient = new LdapClientLib(config.ldapAuthentication.host); - -const prePostReadControls = [ - config.ldapControls.ldapModificationControlPostRead, - config.ldapControls.ldapModificationControlPreRead, -]; - -newClient.initialize() - .then(() => { - console.log('Init successfully'); - return newClient.startTLS(config.ldapAuthentication.pathFileToCert); - }) - .then(() => { - console.log('TLS successfully'); - return newClient.bind(config.ldapAuthentication.dnUser, config.ldapAuthentication.passwordUser); - }) - .then(() => { - console.log('Bind successfully'); - return newClient.rename(config.ldapRename.firstDNChange, config.ldapRename.firstRDN, - config.ldapRename.newParent); - }) - .then(() => { - console.log('The user was renamed with success'); - return newClient.rename(config.ldapRename.secondDNChange, config.ldapRename.secondRDN, - config.ldapRename.newParent, prePostReadControls); - }) - .then((result) => { - const resultJson = ldif.parse(result); - const outputOptions = {}; - - const JSONstructure = resultJson.toObject(outputOptions); - JSONstructure.entries.forEach((element) => { - console.log(element); - }); - }) - .catch((err) => { - console.log(err.toString()); - }); From 5e95a02e59e13bea8a99adf05c946f4339174732 Mon Sep 17 00:00:00 2001 From: Radu Date: Thu, 1 Feb 2018 09:38:39 +0200 Subject: [PATCH 8/8] polishing samples, changed some config files --- populate.js | 8 ++++---- sample/add_operation.js | 4 +--- sample/config.json | 2 +- sample/delete_operation.js | 4 +--- sample/modify_operation.js | 9 +++------ sample/page_search_operation.js | 5 +---- sample/rename_operation.js | 8 +++----- sample/search_operation.js | 5 +---- test/config.json | 13 +++++-------- test/test_paged_search.js | 4 ++-- 10 files changed, 22 insertions(+), 40 deletions(-) diff --git a/populate.js b/populate.js index 420d04f..2108730 100644 --- a/populate.js +++ b/populate.js @@ -33,13 +33,13 @@ const validEntryObject = [ ]; -const ldapClient = new Client(configFile.ldapTestEntries.host); +const ldapClient = new Client(configFile.ldapAuthentication.host); ldapClient.initialize() .then(() => { return ldapClient.bind( - configFile.ldapTestEntries.userDn, - configFile.ldapTestEntries.userPassword); + configFile.ldapAuthentication.dnAdmin, + configFile.ldapAuthentication.passwordAdmin); }) .then(() => { ldapClient.add(dn, validEntryObject) @@ -51,6 +51,6 @@ ldapClient.initialize() Promise.map(args, (arg) => { return ldapClient.add(arg, validEntryObject); - }, {concurrency: 1}); + }, {concurrency: 4}); }); }); diff --git a/sample/add_operation.js b/sample/add_operation.js index 72bbef8..7d88d0f 100644 --- a/sample/add_operation.js +++ b/sample/add_operation.js @@ -1,7 +1,6 @@ 'use strict'; const LdapClientLib = require('../index').Client; -const ldif = require('ldif'); const config = require('./config.json'); const newClient = new LdapClientLib(config.ldapAuthentication.host); @@ -31,10 +30,9 @@ newClient.initialize() config.ldapControls.ldapModificationControlPostRead); }) .then((result) => { - const resultJson = ldif.parse(result); const outputOptions = {}; - const JSONstructure = resultJson.toObject(outputOptions); + const JSONstructure = result.toObject(outputOptions); JSONstructure.entries.forEach((element) => { console.log(element); }); diff --git a/sample/config.json b/sample/config.json index 4e9f68b..ea9b8ea 100644 --- a/sample/config.json +++ b/sample/config.json @@ -1,6 +1,6 @@ { "ldapAuthentication": { - "host": "ldap://localhost:389", + "host": "ldap://10.16.0.179:389", "dnUser": "cn=managerUser,ou=users,o=myhost,dc=demoApp,dc=com", "passwordUser": "secret", "pathFileToCert": "/etc/ldap/ca_certs.pem" diff --git a/sample/delete_operation.js b/sample/delete_operation.js index 9b10a04..6da922d 100644 --- a/sample/delete_operation.js +++ b/sample/delete_operation.js @@ -1,7 +1,6 @@ 'use strict'; const LdapClientLib = require('../index').Client; -const ldif = require('ldif'); const config = require('./config.json'); @@ -26,10 +25,9 @@ newClient.initialize() config.ldapControls.ldapModificationControlPreRead); }) .then((result) => { - const resultJson = ldif.parse(result); const outputOptions = {}; - const JSONstructure = resultJson.toObject(outputOptions); + const JSONstructure = result.toObject(outputOptions); JSONstructure.entries.forEach((element) => { console.log(element); }); diff --git a/sample/modify_operation.js b/sample/modify_operation.js index 9432543..b20ca73 100644 --- a/sample/modify_operation.js +++ b/sample/modify_operation.js @@ -2,8 +2,6 @@ const LdapClientLib = require('../index').Client; -const ldif = require('ldif'); - const dn = 'ou=users,o=myhost,dc=demoApp,dc=com'; const config = require('./config.json'); @@ -18,12 +16,12 @@ const changes = [ const prePostReadControls = [ { - oid: 'preread', + oid: '1.3.6.1.1.13.1', value: ['cn'], isCritical: false, }, { - oid: 'postread', + oid: '1.3.6.1.1.13.2', value: ['cn'], isCritical: false, }, @@ -47,10 +45,9 @@ newClient.initialize() return newClient.modify(config.ldapModify.secondDNEntry, changes, prePostReadControls); }) .then((result) => { - const resultJson = ldif.parse(result); const outputOptions = {}; - const JSONstructure = resultJson.toObject(outputOptions); + const JSONstructure = result.toObject(outputOptions); JSONstructure.entries.forEach((element) => { console.log(element); }); diff --git a/sample/page_search_operation.js b/sample/page_search_operation.js index 69b9b92..db027cc 100644 --- a/sample/page_search_operation.js +++ b/sample/page_search_operation.js @@ -2,8 +2,6 @@ const LdapClientLib = require('../index').Client; -const ldif = require('ldif'); - const config = require('./config.json'); const newClient = new LdapClientLib(config.ldapAuthentication.host); @@ -28,10 +26,9 @@ newClient.initialize() console.log('-----------------------------------'); console.log(`The page number is ${pageNumber += 1}`); console.log('-----------------------------------'); - const resultJson = ldif.parse(data.toString()); const outputOptions = {}; - const JSONstructure = resultJson.toObject(outputOptions); + const JSONstructure = data.toObject(outputOptions); console.log(`LDIF structure: ${data.toString()}`); JSONstructure.entries.forEach((element) => { console.log(element); diff --git a/sample/rename_operation.js b/sample/rename_operation.js index 87239b7..9f13fff 100644 --- a/sample/rename_operation.js +++ b/sample/rename_operation.js @@ -1,15 +1,14 @@ 'use strict'; const LdapClientLib = require('../index').Client; -const ldif = require('ldif'); const config = require('./config.json'); const newClient = new LdapClientLib(config.ldapAuthentication.host); const prePostReadControls = [ - config.ldapControls.ldapModificationControlPostRead, - config.ldapControls.ldapModificationControlPreRead, + '1.3.6.1.1.13.2', + '1.3.6.1.1.13.1', ]; newClient.initialize() @@ -32,10 +31,9 @@ newClient.initialize() config.ldapRename.newParent, prePostReadControls); }) .then((result) => { - const resultJson = ldif.parse(result); const outputOptions = {}; - const JSONstructure = resultJson.toObject(outputOptions); + const JSONstructure = result.toObject(outputOptions); JSONstructure.entries.forEach((element) => { console.log(element); }); diff --git a/sample/search_operation.js b/sample/search_operation.js index ea5a541..d96f41c 100644 --- a/sample/search_operation.js +++ b/sample/search_operation.js @@ -2,8 +2,6 @@ const LdapClientLib = require('../index').Client; -const ldif = require('ldif'); - const config = require('./config.json'); const newClient = new LdapClientLib(config.ldapAuthentication.host); @@ -23,9 +21,8 @@ newClient.initialize() config.ldapSearch.filter); }) .then((result) => { - const resultJson = ldif.parse(result); const outputOptions = {}; - const JSONstructure = resultJson.toObject(outputOptions); + const JSONstructure = result.toObject(outputOptions); console.log(`LDIF structure: ${result}`); console.log('\n\n'); JSONstructure.entries.forEach((element) => { diff --git a/test/config.json b/test/config.json index 0ff0a42..7b6dee7 100644 --- a/test/config.json +++ b/test/config.json @@ -6,7 +6,7 @@ "dnUserNoRight": "cn=simpleUser,ou=users,o=myhost,dc=demoApp,dc=com", "passwordAdmin": "secret", "passwordUser": "secret", - "pathFileToCert": "D:/HSM/ca_certs.pem" + "pathFileToCert": "ca_certs.pem" }, "ldapExtendedOperation": { "oid": { @@ -134,18 +134,15 @@ "filterObjAll": "objectclass=*", "filterObjSpecific": "objectclass=aliens", "filterObjSpecific2": "objectClass=simpleSecurityObject", - "filterObjSpecific3": "objectClass=inetOrgPerson" + "filterObjSpecific3": "objectClass=inetOrgPerson", + "nrOfResults": 10000, + "pageSize": 10 }, "ldapDelete": { "rdnUser": "cn=testUsersDelete", "dn": ",cn=newPoint,ou=users,o=myhost,dc=demoApp,dc=com" }, "ldapTestEntries": { - "host": "ldap://localhost:389", - "entryDn": "cn=newPoint,ou=users,o=myhost,dc=demoApp,dc=com", - "userDn": "cn=admin,dc=demoApp,dc=com", - "userPassword": "secret", - "nrOfResults": 10000, - "pageSize": 10 + "entryDn": "cn=newPoint,ou=users,o=myhost,dc=demoApp,dc=com" } } \ No newline at end of file diff --git a/test/test_paged_search.js b/test/test_paged_search.js index 76f5c06..b6cc54c 100644 --- a/test/test_paged_search.js +++ b/test/test_paged_search.js @@ -23,9 +23,9 @@ describe('Testing the async LDAP paged search ', () => { let userLDAP = new LDAPWrap(host); let pagedSearchPromise; - const nrOfResults = config.ldapTestEntries.nrOfResults; + const nrOfResults = config.ldapSearch.nrOfResults; - const pageSize = config.ldapTestEntries.pageSize; + const pageSize = config.ldapSearch.pageSize; const searchScope = { base: 'BASE',