Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public override Object Invoke( UserSession session, Object inputParams )
- {
- string User = "g.сhernyshev";
- string Password = "123";
- string DomainName = "TEST";
- string ADGroupName = "test";
- Template UserTemplate = Service.GetCommonRegistryValue<Template>( @"CommonSettings\plmsoyuzconfig\Configurations\ADSYNC\UserTemplate" );
- string Login = Service.GetCommonRegistryValue<string>( @"CommonSettings\plmsoyuzconfig\Configurations\ADSYNC\AccountId", "sAMAccountName" );
- string UserFlags = Service.GetCommonRegistryValue<string>( @"CommonSettings\plmsoyuzconfig\Configurations\ADSYNC\UserFlags", "userAccountControl" );
- var Params = Service.GetRegistryItem( null, @"CommonSettings\plmsoyuzconfig\Configurations\ADSYNC\Params", null, RegistryItemBase.DataTypeEnum.Undefined, false, true );
- var ParamsArray = new Dictionary<string, string>();
- foreach( var i in Params.AllChildren )
- {
- ParamsArray.Add( i.NameKey, i.GetValue<string>() );
- }
- System.DirectoryServices.DirectoryEntry rootEnt = null;
- System.DirectoryServices.DirectorySearcher DirSearch = null;
- var allPLMUsers = Service.AllUsers.Where( u => u.IsUser ).ToArray();
- rootEnt = new System.DirectoryServices.DirectoryEntry("LDAP://" + DomainName, User, Password );
- if( rootEnt != null )
- {
- System.DirectoryServices.DirectoryEntry ADUser = new System.DirectoryServices.DirectoryEntry( "LDAP://" + DomainName + "/", User, Password );
- var sAMAccountName = ( ADUser.Properties[ Login ].Count > 0 ) ? ADUser.Properties[ Login ][0].ToString() : "";
- if( !string.IsNullOrEmpty( sAMAccountName ) )
- {
- var sAMAccountNameKey = sAMAccountName.Replace( '.', '_' ).Replace( ',', '_' ).Replace( ';', '_' ).Replace( '\\', '_' ).Replace( '&', '_' ).Replace( '*', '_' ).Replace( '/', '_' );
- var user = allPLMUsers.FirstOrDefault( u => u.AccountId.ToLower() == sAMAccountName.ToLower() );
- if( user == null || ( user != null && !user.GetValue<bool>( "NotAllowedSync", false ) ) )
- {
- if( user == null )
- {
- user = new User( UserTemplate );
- user.AccountId = sAMAccountName;
- user.NameKey = sAMAccountNameKey;
- user.Kind = UserBase.UserKindEnum.InternalUser;
- user.Notes = string.Format( Owner.GetLocalized( "importedFrom" , "Учетная запись импортирована из домена {0}" ), DomainName );
- }
- if( user.GetValue<string>( "Login" ) != sAMAccountName )
- user[ "Login" ] = sAMAccountName;
- var SID = new System.Security.Principal.SecurityIdentifier( ( byte[] )ADUser.Properties[ "objectSid" ][0], 0 ).Value;
- if( user.SID != SID )
- user.SID = SID;
- var ADName = string.Format( "{0} ({1})", sAMAccountName, SID );
- if( user.GetValue<string>( "ADName" ) != ADName )
- user[ "ADName" ] = ADName;
- user[ "FirstName" ] = "Георгий";
- user[ "SecondName" ] = "Чернышов";
- user[ "MiddleName" ] = "Владимирович";
- int userAccountControl = ( ADUser.Properties[ UserFlags ].Count > 0 ) ? ( int )ADUser.Properties[ UserFlags ][0].GetValueOfType<int>() : 0;
- bool IsDisabled = ( ( userAccountControl & 0x0002 ) > 0 );
- if( IsDisabled != user.IsDisabled )
- user[ "IsDisabled" ] = IsDisabled;
- foreach( var param in ParamsArray )
- {
- var val = ( ADUser.Properties[ param.Key ].Count > 0 ) ? ADUser.Properties[ param.Key ][0].ToString() : "";
- if( user.GetValue<string>( param.Value, "" ) != val )
- user[ param.Value ] = val;
- }
- }
- }
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement