Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for PortalSecurity.cs #5780

Merged
merged 33 commits into from
Aug 4, 2023
Merged
Changes from 17 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
27d6a78
Add documentation for PortalSecurity.cs
david-poindexter Aug 4, 2023
a5d1582
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
124b0ea
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
d263e2b
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
10f8d56
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
f214365
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
6d9d83d
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
bc07989
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
ea5a7d4
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
f51fe3a
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
47820f9
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
6bf66df
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
4597127
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
24c4519
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
33445a8
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
893375d
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
70920ab
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
33c6555
Update DNN Platform/Library/Security/PortalSecurity.cs
valadas Aug 4, 2023
dc09729
Update DNN Platform/Library/Security/PortalSecurity.cs
valadas Aug 4, 2023
8eb50d2
Update DNN Platform/Library/Security/PortalSecurity.cs
valadas Aug 4, 2023
f68937c
Update DNN Platform/Library/Security/PortalSecurity.cs
valadas Aug 4, 2023
e625990
Update DNN Platform/Library/Security/PortalSecurity.cs
valadas Aug 4, 2023
4103082
Update DNN Platform/Library/Security/PortalSecurity.cs
valadas Aug 4, 2023
8020f21
Update DNN Platform/Library/Security/PortalSecurity.cs
valadas Aug 4, 2023
965b4dc
Update DNN Platform/Library/Security/PortalSecurity.cs
valadas Aug 4, 2023
4b9aecd
Update DNN Platform/Library/Security/PortalSecurity.cs
valadas Aug 4, 2023
67c8606
Update DNN Platform/Library/Security/PortalSecurity.cs
valadas Aug 4, 2023
c4c4f1e
Update DNN Platform/Library/Security/PortalSecurity.cs
valadas Aug 4, 2023
6fd48bd
Update DNN Platform/Library/Security/PortalSecurity.cs
valadas Aug 4, 2023
eea95e1
Update DNN Platform/Library/Security/PortalSecurity.cs
valadas Aug 4, 2023
6b929d3
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
9efe38d
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
007b765
Update DNN Platform/Library/Security/PortalSecurity.cs
david-poindexter Aug 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions DNN Platform/Library/Security/PortalSecurity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ private enum RoleType
Owner = 3,
}

/// <summary>
/// Forces the secure connection.
/// </summary>
public static void ForceSecureConnection()
{
// get current url
Expand All @@ -163,6 +166,11 @@ public static void ForceSecureConnection()
}
}

/// <summary>
/// Gets the cookie domain for the portal group or from web.config.
/// </summary>
/// <param name="portalId">The portal identifier.</param>
/// <returns>Cookie domain for the portal group or from web.config.</returns>
public static string GetCookieDomain(int portalId)
{
string cookieDomain = string.Empty;
Expand Down Expand Up @@ -193,13 +201,31 @@ public static string GetCookieDomain(int portalId)
return cookieDomain;
}

/// <summary>
/// Determined whether the current user is denied for the given role(s)
valadas marked this conversation as resolved.
Show resolved Hide resolved

valadas marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <param name="roles">The semicolon separated list of roles.</param>
/// <returns>
/// <c>true</c> if the current user is denied from the provided specified roles; otherwise, <c>false</c>.

valadas marked this conversation as resolved.
Show resolved Hide resolved
/// </returns>
public static bool IsDenied(string roles)
{
UserInfo objUserInfo = UserController.Instance.GetCurrentUserInfo();
PortalSettings settings = PortalController.Instance.GetCurrentPortalSettings();
return IsDenied(objUserInfo, settings, roles);
}

/// <summary>
/// Determines whether the specified user is denied for the given roles.
/// </summary>
/// <param name="objUserInfo">The user information.</param>
/// <param name="settings">The settings.</param>
/// <param name="roles">The semicolon separated list of roles.</param>
/// <returns>
/// <c>true</c> if the specified user is denied; otherwise, <c>false</c>.
/// </returns>
public static bool IsDenied(UserInfo objUserInfo, PortalSettings settings, string roles)
{
// super user always has full access
Expand Down Expand Up @@ -238,6 +264,13 @@ public static bool IsDenied(UserInfo objUserInfo, PortalSettings settings, strin
return isDenied;
}

/// <summary>
/// Determines whether the current user belonds to the specified role.
/// </summary>
/// <param name="role">The role name.</param>
/// <returns>
/// <c>true</c> if user belongs to the specified role; otherwise, <c>false</c>.
/// </returns>
public static bool IsInRole(string role)
{
if (!string.IsNullOrEmpty(role) && role == Globals.glbRoleUnauthUserName && !HttpContext.Current.Request.IsAuthenticated)
Expand All @@ -248,13 +281,31 @@ public static bool IsInRole(string role)
return IsInRoles(UserController.Instance.GetCurrentUserInfo(), PortalController.Instance.GetCurrentPortalSettings(), role);
}

/// <summary>
/// Determines whether the current user belongs to the specified roles.
/// </summary>
/// <param name="roles">The semicolon separated list of roles.</param>
/// <returns>
/// <c>true</c> if user belongs to the specified roles; otherwise, <c>false</c>.
/// </returns>
public static bool IsInRoles(string roles)
{
UserInfo objUserInfo = UserController.Instance.GetCurrentUserInfo();
PortalSettings settings = PortalController.Instance.GetCurrentPortalSettings();
return IsInRoles(objUserInfo, settings, roles);
}

/// <summary>
/// Determines whether the provided user belongs to the specified roles.

valadas marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <param name="objUserInfo">The user information.</param>
/// <param name="settings">The settings.</param>
/// <param name="roles">The semicolon separated list of roles.</param>
/// <returns>
/// <c>true</c> if the provided user belongs to the specific roles; otherwise, <c>false</c>.

/// </returns>
public static bool IsInRoles(UserInfo objUserInfo, PortalSettings settings, string roles)
{
// super user always has full access
Expand All @@ -280,20 +331,45 @@ public static bool IsInRoles(UserInfo objUserInfo, PortalSettings settings, stri
return isInRoles;
}

/// <summary>
/// Determines whether the specified user is a friend of the current user.

/// </summary>
valadas marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="userId">The user identifier.</param>
/// <returns>
/// <c>true</c> if the specified user is a friend of the current user; otherwise, <c>false</c>.

/// </returns>
valadas marked this conversation as resolved.
Show resolved Hide resolved
public static bool IsFriend(int userId)
{
UserInfo objUserInfo = UserController.Instance.GetCurrentUserInfo();
PortalSettings settings = PortalController.Instance.GetCurrentPortalSettings();
return IsInRoles(objUserInfo, settings, RoleFriendPrefix + userId);
}

/// <summary>
/// Determines whether the specified user is a follower of the current user.

/// </summary>
/// <param name="userId">The user identifier.</param>
/// <returns>
/// <c>true</c> if the specified user is a follower of the current user; otherwise, <c>false</c>.

/// </returns>
valadas marked this conversation as resolved.
Show resolved Hide resolved
public static bool IsFollower(int userId)
{
UserInfo objUserInfo = UserController.Instance.GetCurrentUserInfo();
PortalSettings settings = PortalController.Instance.GetCurrentPortalSettings();
return IsInRoles(objUserInfo, settings, RoleFollowerPrefix + userId);
}

/// <summary>
/// Determines whether the specified user is an owner.
/// </summary>
/// <param name="userId">The user identifier.</param>
/// <returns>
/// <c>true</c> if the specified user is an owner; otherwise, <c>false</c>.
/// </returns>
public static bool IsOwner(int userId)
{
UserInfo objUserInfo = UserController.Instance.GetCurrentUserInfo();
Expand All @@ -315,21 +391,51 @@ public string CreateKey(int numBytes)
}
}

/// <summary>
/// Decrypts the provided string data using a supplied key.

/// </summary>
/// <param name="strKey">The encryption key.</param>

/// <param name="strData">The encrypted data.</param>

/// <returns>The decrypted string.</returns>
valadas marked this conversation as resolved.
Show resolved Hide resolved
public string Decrypt(string strKey, string strData)
{
return CryptographyProvider.Instance().DecryptParameter(strData, strKey);
}

/// <summary>
/// Decrypts a string using a provided passphrase.

/// </summary>
/// <param name="message">The encrypted message.</param>

/// <param name="passphrase">The passphrase.</param>
/// <returns>The decrypted string.</returns>
valadas marked this conversation as resolved.
Show resolved Hide resolved
public string DecryptString(string message, string passphrase)
{
return CryptographyProvider.Instance().DecryptString(message, passphrase);
}

/// <summary>
/// Encrypts the specified key.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="data">The data.</param>
/// <returns>The encrypted string.</returns>
public string Encrypt(string key, string data)
{
return CryptographyProvider.Instance().EncryptParameter(data, key);
}

/// <summary>
/// Encrypts a string using a provided passphrase
david-poindexter marked this conversation as resolved.
Show resolved Hide resolved

/// </summary>
/// <param name="message">The message.</param>
/// <param name="passphrase">The passphrase.</param>
/// <returns>The encrypted string.</returns>
valadas marked this conversation as resolved.
Show resolved Hide resolved
public string EncryptString(string message, string passphrase)
{
return CryptographyProvider.Instance().EncryptString(message, passphrase);
Expand Down Expand Up @@ -500,6 +606,12 @@ public string Remove(string inputString, ConfigType configType, string configSou
return inputString;
}

/// <summary>
/// Signs the provided user in and sets a persistent login cookie if needed
david-poindexter marked this conversation as resolved.
Show resolved Hide resolved

/// </summary>
/// <param name="user">The user info.</param>
/// <param name="createPersistentCookie">if set to <c>true</c> [create persistent cookie].</param>
valadas marked this conversation as resolved.
Show resolved Hide resolved
public void SignIn(UserInfo user, bool createPersistentCookie)
{
if (PortalController.IsMemberOfPortalGroup(user.PortalID) || createPersistentCookie)
Expand Down Expand Up @@ -574,6 +686,10 @@ public void SignIn(UserInfo user, bool createPersistentCookie)
HttpContext.Current.Items["DNN_UserSignIn"] = true;
}

/// <summary>
/// Signs the current user out.

/// </summary>
valadas marked this conversation as resolved.
Show resolved Hide resolved
public void SignOut()
{
InvalidateAspNetSession(HttpContext.Current);
Expand Down
Loading