Skip to content

Commit

Permalink
[all] 도메인 복구 시 사용자 토큰 기반으로 도메인이 복구되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
powerumc committed Jul 29, 2019
1 parent 495deb3 commit 758730d
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 19 deletions.
2 changes: 2 additions & 0 deletions common/Ntreev.Crema.Services.Sharing/IUserAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
//COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
//OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using Ntreev.Crema.Services.Users;

namespace Ntreev.Crema.Services
{
public interface IUserAuthentication
Expand Down
4 changes: 2 additions & 2 deletions server/Ntreev.Crema.Services/Domains/Domain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ protected Domain(SerializationInfo info, StreamingContext context)
this.InitializeUsers(info);
}

protected Domain(string creatorID, Guid dataBaseID, string itemPath, string itemType)
protected Domain(string creatorID, Guid creatorToken, Guid dataBaseID, string itemPath, string itemType)
{
var signatureDate = new SignatureDate(creatorID, DateTime.UtcNow);
var signatureDate = new SignatureDate(creatorID, creatorToken, DateTime.UtcNow);
var domainInfo = new DomainInfo()
{
DomainID = Guid.NewGuid(),
Expand Down
3 changes: 3 additions & 0 deletions server/Ntreev.Crema.Services/Domains/DomainActionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public DomainActionBase()
[DataMember]
public string UserID { get; set; }

[DataMember]
public Guid UserToken { get; set; }

[DataMember]
public long ID { get; set; }

Expand Down
51 changes: 45 additions & 6 deletions server/Ntreev.Crema.Services/Domains/DomainLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ public void NewRow(Authentication authentication, DomainRowInfo[] rows)
if (this.isEnabled == false)
return;

var action = new NewRowAction() { UserID = authentication.ID, Rows = rows, AcceptTime = authentication.SignatureDate.DateTime };
var action = new NewRowAction()
{
UserID = authentication.ID,
UserToken = authentication.Token,
Rows = rows,
AcceptTime = authentication.SignatureDate.DateTime
};
this.Post(action);
}

Expand All @@ -117,7 +123,13 @@ public void SetRow(Authentication authentication, DomainRowInfo[] rows)
if (this.isEnabled == false)
return;

var action = new SetRowAction() { UserID = authentication.ID, Rows = rows, AcceptTime = authentication.SignatureDate.DateTime };
var action = new SetRowAction()
{
UserID = authentication.ID,
UserToken = authentication.Token,
Rows = rows,
AcceptTime = authentication.SignatureDate.DateTime
};
this.Post(action);
}

Expand All @@ -126,7 +138,13 @@ public void RemoveRow(Authentication authentication, DomainRowInfo[] rows)
if (this.isEnabled == false)
return;

var action = new RemoveRowAction() { UserID = authentication.ID, Rows = rows, AcceptTime = authentication.SignatureDate.DateTime };
var action = new RemoveRowAction()
{
UserID = authentication.ID,
UserToken = authentication.Token,
Rows = rows,
AcceptTime = authentication.SignatureDate.DateTime
};
this.Post(action);
}

Expand All @@ -135,19 +153,38 @@ public void SetProperty(Authentication authentication, string propertyName, obje
if (this.isEnabled == false)
return;

var action = new SetPropertyAction() { UserID = authentication.ID, PropertyName = propertyName, Value = value, AcceptTime = authentication.SignatureDate.DateTime };
var action = new SetPropertyAction()
{
UserID = authentication.ID,
UserToken = authentication.Token,
PropertyName = propertyName,
Value = value,
AcceptTime = authentication.SignatureDate.DateTime
};
this.Post(action);
}

public void Join(Authentication authentication, DomainAccessType accessType)
{
var action = new JoinAction() { UserID = authentication.ID, AccessType = accessType, AcceptTime = authentication.SignatureDate.DateTime};
var action = new JoinAction()
{
UserID = authentication.ID,
UserToken = authentication.Token,
AccessType = accessType,
AcceptTime = authentication.SignatureDate.DateTime
};
this.Post(action);
}

public void Disjoin(Authentication authentication, RemoveInfo removeInfo)
{
var action = new DisjoinAction() { UserID = authentication.ID, RemoveInfo = removeInfo, AcceptTime = authentication.SignatureDate.DateTime };
var action = new DisjoinAction()
{
UserID = authentication.ID,
UserToken = authentication.Token,
RemoveInfo = removeInfo,
AcceptTime = authentication.SignatureDate.DateTime
};
this.Post(action);
}

Expand All @@ -156,6 +193,7 @@ public void Kick(Authentication authentication, string userID, Guid token, strin
var action = new KickAction()
{
UserID = authentication.ID,
UserToken = authentication.Token,
TargetID = userID,
TargetToken = token,
Comment = comment,
Expand All @@ -169,6 +207,7 @@ public void SetOwner(Authentication authentication, string userID, Guid token)
var action = new SetOwnerAction()
{
UserID = authentication.ID,
UserToken = authentication.Token,
TargetID = userID,
TargetToken = token,
AcceptTime = authentication.SignatureDate.DateTime
Expand Down
24 changes: 16 additions & 8 deletions server/Ntreev.Crema.Services/Domains/DomainRestorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DomainRestorer

private readonly HashSet<long> completedActions = new HashSet<long>();
private readonly List<DomainActionBase> postedActions = new List<DomainActionBase>();
private Dictionary<string, Authentication> authentications;
private Dictionary<Guid, Authentication> authentications;
private Domain domain;
private DateTime dateTime;

Expand Down Expand Up @@ -165,19 +165,27 @@ private void DeserializeDomain()

private void CollectAuthentications()
{
var creatorID = this.domain.DomainInfo.CreationInfo.ID;
var creator = this.domain.DomainInfo.CreationInfo;
var userContext = this.domainContext.CremaHost.UserContext;
var userIDs = this.postedActions.Select(item => item.UserID).Concat(Enumerable.Repeat(creatorID, 1)).Distinct();
var actionUsers = this.postedActions.Select(item => new
{
item.UserID,
item.UserToken
}).Concat(Enumerable.Repeat(new
{
UserID = creator.ID,
UserToken = creator.Token
}, 1)).Distinct();

var users = userContext.Dispatcher.Invoke(() =>
{
var query = from userID in userIDs
join User user in userContext.Users on userID equals user.ID
select new Authentication(new UserAuthenticationProvider(user, true));
var query = from actionUser in actionUsers
join User user in userContext.Users on actionUser.UserID equals user.ID
select new Authentication(new UserAuthenticationProvider(user, true), actionUser.UserToken);
return query.ToArray();
});

this.authentications = users.ToDictionary(item => item.ID);
this.authentications = users.ToDictionary(item => item.Token);
}

private void RestoreDomain()
Expand All @@ -190,7 +198,7 @@ private void RestoreDomain()

foreach (var item in this.postedActions)
{
var authentication = this.authentications[item.UserID];
var authentication = this.authentications[item.UserToken];
try
{
var action = item as DomainActionBase;
Expand Down
2 changes: 1 addition & 1 deletion server/Ntreev.Crema.Services/Domains/TableContentDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private TableContentDomain(SerializationInfo info, StreamingContext context)
}

public TableContentDomain(Authentication authentication, CremaDataSet dataSet, DataBase dataBase, string itemPath, string itemType)
: base(authentication.ID, dataBase.ID, itemPath, itemType)
: base(authentication.ID, authentication.Token, dataBase.ID, itemPath, itemType)
{
if (dataSet.HasChanges() == true)
throw new ArgumentException(Resources.Exception_UnsavedDataCannotEdit, nameof(dataSet));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public TableTemplateDomain(SerializationInfo info, StreamingContext context)
}

public TableTemplateDomain(Authentication authentication, CremaTemplate templateSource, DataBase dataBase, string itemPath, string itemType)
: base(authentication.ID, dataBase.ID, itemPath, itemType)
: base(authentication.ID, authentication.Token, dataBase.ID, itemPath, itemType)
{
this.template = templateSource;
this.view = this.template.View;
Expand Down
2 changes: 1 addition & 1 deletion server/Ntreev.Crema.Services/Domains/TypeDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public TypeDomain(SerializationInfo info, StreamingContext context)
}

public TypeDomain(Authentication authentication, CremaDataType dataType, DataBase dataBase, string itemPath, string itemType)
: base(authentication.ID, dataBase.ID, itemPath, itemType)
: base(authentication.ID, authentication.Token, dataBase.ID, itemPath, itemType)
{
this.dataType = dataType;
this.view = this.dataType.View;
Expand Down

0 comments on commit 758730d

Please sign in to comment.