/*
*
* (c) Copyright Ascensio System Limited 2010-2021
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace ASC.ActiveDirectory.Novell.Data;
///
/// Novell LDAP object class
///
public class NovellLdapObject : LdapObject
{
private LdapEntry _ldapEntry;
private readonly ILog _log;
private string _sid;
private string _sidAttribute;
private readonly NovellLdapEntryExtension _novellLdapEntryExtension;
///
/// Constructor
///
/// init ldap entry
///
public NovellLdapObject(IOptionsMonitor option, NovellLdapEntryExtension novellLdapEntryExtension)
{
_novellLdapEntryExtension = novellLdapEntryExtension;
_log = option.Get("ASC");
}
public void Init(LdapEntry ldapEntry, string ldapUniqueIdAttribute = null)
{
if (ldapEntry == null)
throw new ArgumentNullException("ldapEntry");
_ldapEntry = ldapEntry;
if (string.IsNullOrEmpty(ldapUniqueIdAttribute))
return;
try
{
_sid = GetValue(ldapUniqueIdAttribute) as string;
_sidAttribute = ldapUniqueIdAttribute;
}
catch (Exception e)
{
_log.ErrorFormat("Can't get LDAPObject Sid property. {0}", e);
}
}
#region .Public
public override string DistinguishedName
{
get { return _ldapEntry.Dn; }
}
public override string Sid
{
get { return _sid; }
}
public override string SidAttribute
{
get { return _sidAttribute; }
}
public override bool IsDisabled
{
get
{
var userAccauntControl = LdapConstants.UserAccountControl.EMPTY;
try
{
var uac = Convert.ToInt32(GetValue(LdapConstants.ADSchemaAttributes.USER_ACCOUNT_CONTROL));
userAccauntControl = (LdapConstants.UserAccountControl)uac;
}
catch (Exception e)
{
_log.ErrorFormat("Can't get LDAPUser UserAccauntControl property. {0}", e);
}
return (userAccauntControl & LdapConstants.UserAccountControl.ADS_UF_ACCOUNTDISABLE) > 0;
}
}
#endregion
///
/// Get property object
///
/// property name
/// value object
public sealed override object GetValue(string propertyName, bool getBytes = false)
{
return _novellLdapEntryExtension.GetAttributeValue(_ldapEntry, propertyName, getBytes);
}
///
/// Get property values
///
/// property name
/// list of values
public override List GetValues(string propertyName)
{
var propertyValueArray = _novellLdapEntryExtension.GetAttributeArrayValue(_ldapEntry, propertyName);
if (propertyValueArray == null)
{
return new List();
}
var properties = propertyValueArray.ToList();
return properties;
}
}