mirror of
https://github.com/jellyfin/jellyfin-plugin-ldapauth.git
synced 2024-11-27 00:00:38 +00:00
Style changes and compile embed fix
This commit is contained in:
parent
671e0a12d6
commit
ee55cf7632
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,3 +3,6 @@
|
||||
################################################################################
|
||||
|
||||
/.vs/LDAP-Auth/v15/Server/sqlite3
|
||||
/obj
|
||||
/LDAP-Auth.sln.DotSettings.user
|
||||
/bin/Debug/netstandard2.0
|
||||
|
@ -1,24 +1,23 @@
|
||||
using System.Collections.Generic;
|
||||
namespace Jellyfin.Plugin.LDAP_Auth
|
||||
{
|
||||
public class PluginConfiguration : MediaBrowser.Model.Plugins.BasePluginConfiguration
|
||||
{
|
||||
public string LDAPServer{get;}
|
||||
public string LDAPBaseDN{get;}
|
||||
public int LDAPPort{get;}
|
||||
public string LDAPQuery{get;}
|
||||
public string LDAPBindUser{get;}
|
||||
public string LDAPBindPassword{get;}
|
||||
public bool CreateUsersFromLDAP{get;}
|
||||
public string LdapServer{get;}
|
||||
public string LdapBaseDn{get;}
|
||||
public int LdapPort{get;}
|
||||
public string LdapQuery{get;}
|
||||
public string LdapBindUser{get;}
|
||||
public string LdapBindPassword{get;}
|
||||
public bool CreateUsersFromLdap{get;}
|
||||
public PluginConfiguration()
|
||||
{
|
||||
LDAPServer = "ldap-server.contoso.com";
|
||||
LDAPBaseDN = "o=domains,dc=contoso,dc=com";
|
||||
LDAPPort = 389;
|
||||
LDAPQuery = "(memberOf=CN=JellyfinUsers,DC=contoso,DC=com)";
|
||||
LDAPBindUser = "CN=BindUser,DC=contoso,DC=com";
|
||||
LDAPBindPassword = "password";
|
||||
CreateUsersFromLDAP = true;
|
||||
LdapServer = "ldap-server.contoso.com";
|
||||
LdapBaseDn = "o=domains,dc=contoso,dc=com";
|
||||
LdapPort = 389;
|
||||
LdapQuery = "(memberOf=CN=JellyfinUsers,DC=contoso,DC=com)";
|
||||
LdapBindUser = "CN=BindUser,DC=contoso,DC=com";
|
||||
LdapBindPassword = "password";
|
||||
CreateUsersFromLdap = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<RootNamespace>Jellyfin.Plugin.LDAP_Auth</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Config\configPage.html" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Config\configPage.html" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Jellyfin.Controller" Version="10.2.*" />
|
||||
<PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="2.3.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Configuration\configPage.html" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Configuration\configPage.html" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
@ -1,26 +1,24 @@
|
||||
using System;
|
||||
using System;
|
||||
using MediaBrowser.Controller.Authentication;
|
||||
using MediaBrowser.Common;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Model;
|
||||
using System.Threading.Tasks;
|
||||
using Novell.Directory.Ldap;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.LDAP_Auth
|
||||
{
|
||||
public class LDAPAuthenticationProviderPlugin : IAuthenticationProvider
|
||||
public class LdapAuthenticationProviderPlugin : IAuthenticationProvider
|
||||
{
|
||||
private readonly string[] _attrs = new string[]{
|
||||
"uid",
|
||||
"CN",
|
||||
"displayName"
|
||||
};
|
||||
private PluginConfiguration _config;
|
||||
private ILogger _logger;
|
||||
private IUserManager _userManager;
|
||||
public LDAPAuthenticationProviderPlugin(IUserManager userManager)
|
||||
private readonly PluginConfiguration _config;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUserManager _userManager;
|
||||
public LdapAuthenticationProviderPlugin(IUserManager userManager)
|
||||
{
|
||||
_config = Plugin.Instance.Configuration;
|
||||
_logger = Plugin.Logger;
|
||||
@ -41,8 +39,8 @@ namespace Jellyfin.Plugin.LDAP_Auth
|
||||
ldapClient.SecureSocketLayer = true;
|
||||
try
|
||||
{
|
||||
ldapClient.Connect(_config.LDAPServer,_config.LDAPPort);
|
||||
ldapClient.Bind(_config.LDAPBindUser,_config.LDAPBindPassword);
|
||||
ldapClient.Connect(_config.LdapServer,_config.LdapPort);
|
||||
ldapClient.Bind(_config.LdapBindUser,_config.LdapBindPassword);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@ -51,7 +49,7 @@ namespace Jellyfin.Plugin.LDAP_Auth
|
||||
}
|
||||
if(ldapClient.Bound)
|
||||
{
|
||||
LdapSearchResults ldapUsers = ldapClient.Search(_config.LDAPBaseDN,0,_config.LDAPQuery,_attrs,false);
|
||||
LdapSearchResults ldapUsers = ldapClient.Search(_config.LdapBaseDn,0,_config.LdapQuery,_attrs,false);
|
||||
if (ldapUsers == null || ldapUsers.Count == 0)
|
||||
{
|
||||
_logger.LogWarning("No approved LDAP Users found from query");
|
||||
@ -64,7 +62,7 @@ namespace Jellyfin.Plugin.LDAP_Auth
|
||||
foreach(string attr in _attrs)
|
||||
{
|
||||
var toCheck = currentUser.getAttribute(attr);
|
||||
if(toCheck != null && toCheck.StringValueArray != null)
|
||||
if(toCheck?.StringValueArray != null)
|
||||
{
|
||||
foreach (string name in toCheck.StringValueArray)
|
||||
{
|
||||
@ -94,7 +92,7 @@ namespace Jellyfin.Plugin.LDAP_Auth
|
||||
ldapClient.SecureSocketLayer = true;
|
||||
try
|
||||
{
|
||||
ldapClient.Connect(_config.LDAPServer,_config.LDAPPort);
|
||||
ldapClient.Connect(_config.LdapServer,_config.LdapPort);
|
||||
ldapClient.Bind(ldapUser.DN,password);
|
||||
}
|
||||
catch(Exception e)
|
||||
@ -106,10 +104,10 @@ namespace Jellyfin.Plugin.LDAP_Auth
|
||||
{
|
||||
if(user == null)
|
||||
{
|
||||
if(_config.CreateUsersFromLDAP)
|
||||
if(_config.CreateUsersFromLdap)
|
||||
{
|
||||
user = await _userManager.CreateUser(ldapUser.getAttribute("uid").StringValue);
|
||||
user.Policy.AuthenticationProviderId = this.GetType().Name;
|
||||
user.Policy.AuthenticationProviderId = GetType().Name;
|
||||
_userManager.UpdateUserPolicy(user.Id,user.Policy);
|
||||
}
|
||||
else
|
||||
@ -129,7 +127,6 @@ namespace Jellyfin.Plugin.LDAP_Auth
|
||||
throw new Exception("Error completing LDAP login. Invalid username or password.");
|
||||
}
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task ChangePassword(User user, string newPassword)
|
||||
|
Loading…
Reference in New Issue
Block a user