Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
olmobrutall committed Apr 12, 2023
2 parents e8c2011 + dcd8547 commit 1cad7eb
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
76 changes: 76 additions & 0 deletions Signum.Engine.Extensions/Authorization/ActiveDirectoryLogic.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Signum.Engine.Mailing;
using Signum.Engine.Scheduler;
using Signum.Entities.Authorization;
using Signum.Entities.Basics;
using Signum.Utilities.Reflection;
Expand Down Expand Up @@ -147,4 +148,79 @@ public static UserEntity CreateUserFromAD(ActiveDirectoryUser adUser)
return null;
}
}


public static bool CheckUserActive(string username)
{
var config = ((ActiveDirectoryAuthorizer)AuthLogic.Authorizer!).GetConfig();

using (var domainContext = new PrincipalContext(ContextType.Domain, config.DomainName))
{
using (var foundUser = UserPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, username))
{
if (foundUser.Enabled.HasValue)
{
return (bool)foundUser.Enabled;
}
else
{
return false;
}
}
}
}

public static void Start(SchemaBuilder sb, bool deactivateUsersTask)
{
if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
{
if (deactivateUsersTask)
{
SimpleTaskLogic.Register(ActiveDirectoryTask.DeactivateUsers, stc =>
{
var config = ((ActiveDirectoryAuthorizer)AuthLogic.Authorizer!).GetConfig();

var list = Database.Query<UserEntity>().ToList();

using (var domainContext = new PrincipalContext(ContextType.Domain, config.DomainName, config.DirectoryRegistry_Username + "@" + config.DomainName, config.DirectoryRegistry_Password!))
{
stc.ForeachWriting(list.Chunk(10), gr => gr.Length + " user(s)...", gr =>
{
foreach (var u in gr)
{
if (u.State == UserState.Active)
{
var foundUser = UserPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, u.UserName);

if (foundUser != null && foundUser.Enabled.HasValue && foundUser.Enabled == false)
{
stc.StringBuilder.AppendLine($"User {u.Id} ({u.UserName}) with SID {u.Mixin<UserADMixin>().SID} has been deactivated in AD");
u.Execute(UserOperation.Deactivate);
}
else
{

}

if (foundUser == null && u.PasswordHash == null)
{
stc.StringBuilder.AppendLine($"User {u.Id} ({u.UserName}) with SID {u.Mixin<UserADMixin>().SID} has been deactivated in AD");
u.Execute(UserOperation.Deactivate);
}

}
}
});

return null;
}
});
}
}
}

public static void CheckAllUserActive()
{

}
}
4 changes: 2 additions & 2 deletions Signum.Engine/Connection/SqlServerConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace Signum.Engine;

public enum SqlServerVersion
{
AzureSQL,

SqlServer2005,
SqlServer2008,
SqlServer2012,
Expand All @@ -20,6 +18,8 @@ public enum SqlServerVersion
SqlServer2017,
SqlServer2019,
SqlServer2022,

AzureSQL = 100,
}

public static class SqlServerVersionDetector
Expand Down
4 changes: 2 additions & 2 deletions Signum.React.Extensions/TypeHelp/TypeHelpComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ export default function TypeHelpComponent(p: TypeHelpComponentProps) {
renderInput={input => <div className="input-group input-group-sm" style={{ position: "initial" }}>
<button className="btn input-group-text" disabled={!canBack()}
onClick={e => handleGoHistory(e, historyIndex - 1)} type="button">
<FontAwesomeIcon icon="circle-arrow-left" title={HelpMessage.Previous.niceToString()}/>
<FontAwesomeIcon icon="circle-arrow-left" /*title={HelpMessage.Previous.niceToString()}*/ />
</button>
<button className="btn input-group-text" disabled={!canForth()}
onClick={e => handleGoHistory(e, historyIndex + 1)} type="button">
<FontAwesomeIcon icon="circle-arrow-right" title={HelpMessage.Next.niceToString()}/>
<FontAwesomeIcon icon="circle-arrow-right" /*title={HelpMessage.Next.niceToString()}*/ />
</button>
{input}
<div className="input-group-text" style={{ color: "white", backgroundColor: p.mode == "CSharp" ? "#007e01" : "#017acc" }}>
Expand Down
4 changes: 2 additions & 2 deletions Signum.Utilities/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,12 @@ public Expression Expand(Expression? instance, Expression[] arguments, MethodInf

public static bool IsNullOrEmpty<T>([NotNullWhen(false)]this IEnumerable<T>? collection)
{
return collection == null || collection.IsEmpty();
return collection == null || collection is string s && s.Length == 0 || collection.IsEmpty();
}

public static bool IsNullOrEmpty<T>([NotNullWhen(false)] this ICollection<T>? collection)
{
return collection == null || collection.Count == 0;
return collection == null || collection is string s && s.Length == 0 || collection.Count == 0;
}

public static bool HasItems<T>([NotNullWhen(true)]this IEnumerable<T>? collection)
Expand Down

0 comments on commit 1cad7eb

Please sign in to comment.