-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from hermesdj/dev
Package improvements
- Loading branch information
Showing
5 changed files
with
71 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace VRisingServerApiPlugin.http.security; | ||
|
||
public class AuthorizedUser | ||
{ | ||
public string Username { get; set; } | ||
public string Password { get; set; } | ||
|
||
private AuthorizedUser(string username, string password) | ||
{ | ||
Username = username; | ||
Password = password; | ||
} | ||
|
||
public static IEnumerable<AuthorizedUser> ParseConfig(string authorizedUsers) | ||
{ | ||
return (from user in authorizedUsers.Split(",") | ||
select user.Split(':') | ||
into parts | ||
where parts.Length == 2 | ||
select new AuthorizedUser(parts[0].Trim(), parts[1].Trim())).ToList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using BepInEx.Configuration; | ||
|
||
namespace VRisingServerApiPlugin.http.security; | ||
|
||
public class HttpSecuritySingleton | ||
{ | ||
private static HttpSecuritySingleton _instance; | ||
|
||
private IEnumerable<AuthorizedUser> _authorizedUsers; | ||
|
||
public static HttpSecuritySingleton GetInstance() | ||
{ | ||
return _instance ??= new HttpSecuritySingleton(); | ||
} | ||
|
||
public void Initialize(ConfigEntry<string> authorizedUsers) | ||
{ | ||
authorizedUsers.SettingChanged += (_, args) => | ||
{ | ||
var changedArgs = (SettingChangedEventArgs)args; | ||
var changedSettings = (ConfigEntry<string>)changedArgs.ChangedSetting; | ||
|
||
_authorizedUsers = GetAuthorizedUserList(changedSettings.Value); | ||
}; | ||
_authorizedUsers = GetAuthorizedUserList(authorizedUsers.Value); | ||
} | ||
|
||
private static IEnumerable<AuthorizedUser> GetAuthorizedUserList(string authorizedUsers) | ||
{ | ||
return AuthorizedUser.ParseConfig(authorizedUsers); | ||
} | ||
|
||
public bool CheckAuthenticationOfUser(string username, string password) | ||
{ | ||
return _authorizedUsers | ||
.Count(user => user.Username.Equals(username) && user.Password.Equals(password)) == 1; | ||
} | ||
} |