Permalink
Browse files

[KFI] Save during startup (#191)

* give startup user a real id that will let us save content during request startup.
* add Startup user content that will fill some fields.
* deny delete permissions on the startup user for admins.
  • Loading branch information...
tusmester committed Oct 4, 2017
1 parent 1d03d60 commit fa9c3029b2f2bc40248a01a34be3d8f81de9e77e
@@ -3,7 +3,7 @@
public class Identifiers
{
public const int AdministratorUserId = 1;
public const int StartupUserId = -2;
public const int StartupUserId = 12;
public const int SystemUserId = -1;
public const int PortalRootId = 2;
public const int PortalOrgUnitId = 5;
@@ -119,6 +119,7 @@ EXEC dbo.xCreateNode 'Group', 3, '/Root/IMS/BuiltIn/Portal',
EXEC dbo.xCreateNode 'Group', 5, '/Root/IMS/BuiltIn/Portal', 'Owners' -- NodeId: 9
EXEC dbo.xCreateNode 'User', 6, '/Root/IMS/BuiltIn/Portal', 'Somebody' -- NodeId: 10
EXEC dbo.xCreateNode 'Group', 7, '/Root/IMS/BuiltIn/Portal', 'Operators' -- NodeId: 11
EXEC dbo.xCreateNode 'User', 8, '/Root/IMS/BuiltIn/Portal', 'Startup' -- NodeId: 12
GO
--==== create NodeId gap for future extensions
@@ -2456,7 +2456,7 @@ private void ChecksBeforeSave()
var currentUser = AccessProvider.Current.GetOriginalUser();
var currentUserNode = currentUser as Node;
if (currentUserNode == null)
if (currentUserNode == null && !(currentUser is StartupUser))
throw new InvalidOperationException("Cannot save the content because the current user account representation is not a Node.");
var thisList = this as IContentList;
@@ -9,7 +9,7 @@ namespace SenseNet.ContentRepository.Storage.Security
{
internal sealed class StartupUser : IUser
{
// ================================================================================================== IUser Members
public bool Enabled
@@ -30,7 +30,7 @@ public string Email
}
public string FullName
{
get { return "STARTUP"; }
get { return "Startup User"; }
set { throw new InvalidOperationException("You cannot set a property of the STARTUP user."); }
}
public string Password
@@ -45,7 +45,7 @@ public string PasswordHash
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "value", Justification = "Interface implementation")]
public string Username
{
get { return "STARTUP"; }
get { return "Startup"; }
set { throw new InvalidOperationException("You cannot set a property of the STARTUP user."); }
}
public bool IsInGroup(IGroup group)
@@ -71,10 +71,7 @@ public bool IsInGroup(int securityGroupId)
public int Id => Identifiers.StartupUserId;
public string Path
{
get { throw new InvalidOperationException("You cannot get the Path property of the STARTUP user."); }
}
public string Path => $"/Root/IMS/{IdentityManagement.BuiltInDomainName}/Portal/{Name}";
// ================================================================================================== IIdentity Members
@@ -86,10 +83,7 @@ public bool IsAuthenticated
{
get { return true; }
}
public string Name
{
get { return "STARTUP"; }
}
public string Name => "Startup";
// ================================================================================================== SenseNet.Security.ISecurityUser
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<ContentMetaData>
<ContentType>User</ContentType>
<ContentName>Startup</ContentName>
<Fields>
<Enabled>true</Enabled>
<FullName>Startup User</FullName>
<LoginName>Startup</LoginName>
<Password>
<Text>startup</Text>
</Password>
</Fields>
<Permissions>
<Identity path="/Root/IMS/BuiltIn/Portal/Administrators">
<Delete>Deny</Delete>
</Identity>
<Identity path="/Root/IMS/BuiltIn/Portal/HR">
<Delete>Deny</Delete>
</Identity>
<Identity path="/Root/IMS/BuiltIn/Portal/Owners">
<Delete>Deny</Delete>
</Identity>
</Permissions>
</ContentMetaData>

0 comments on commit fa9c302

Please sign in to comment.