Skip to content

Commit

Permalink
[all] 중복 로그인이 가능하도록 사용자의 연결을 관리하는 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
powerumc committed Jul 26, 2019
1 parent 2ce5aef commit 495deb3
Show file tree
Hide file tree
Showing 52 changed files with 839 additions and 353 deletions.
3 changes: 2 additions & 1 deletion client/Ntreev.Crema.Services/Authentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public AuthenticationInfo AuthenticationInfo
ID = this.ID,
Name = this.Name,
Authority = this.Authority,
Token = this.Token
};
}
}
Expand Down Expand Up @@ -180,7 +181,7 @@ internal SignatureDate Sign()

internal SignatureDate Sign(DateTime dateTime)
{
this.signatureDate = new SignatureDate(this.ID, DateTime.UtcNow);
this.signatureDate = new SignatureDate(this.ID, this.token, DateTime.UtcNow);
return this.signatureDate;
}

Expand Down
2 changes: 0 additions & 2 deletions client/Ntreev.Crema.Services/CremaHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ private Guid OpenInternal(string address, string dataBase, string userID, Secure
this.log.Verbose = this.verbose;
this.userContext = new UserContext(this, this.ipAddress, serviceInfos[nameof(UserService)], userID, password);
var user = this.userContext.Users[userID];
user.SetUserState(UserState.Online);
this.userID = userID;
this.authority = user.Authority;

Expand All @@ -221,7 +220,6 @@ private Guid OpenInternal(string address, string dataBase, string userID, Secure

this.OnOpened(EventArgs.Empty);
this.token = UserContext.AuthenticationToken;
this.token = Guid.NewGuid();
CremaLog.Info($"Crema opened : {address} {userID}");
return token;
}
Expand Down
6 changes: 3 additions & 3 deletions client/Ntreev.Crema.Services/Domains/DomainContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ void IDomainServiceCallback.OnUserAdded(SignatureDate signatureDate, Guid domain
this.InvokeAsync(() =>
{
var domain = this.Domains[domainID];
var authentication = this.userContext.Authenticate(signatureDate, domainUserInfo.Token);
var authentication = this.userContext.Authenticate(signatureDate);
domain.InvokeUserAdded(authentication, domainUserInfo, domainUserState);
}, nameof(IDomainServiceCallback.OnUserAdded));
}
Expand All @@ -523,7 +523,7 @@ void IDomainServiceCallback.OnUserRemoved(SignatureDate signatureDate, Guid doma
this.InvokeAsync(() =>
{
var domain = this.Domains[domainID];
var authentication = this.userContext.Authenticate(signatureDate, domainUserInfo.Token);
var authentication = this.userContext.Authenticate(signatureDate);
domain.InvokeUserRemoved(authentication, domainUserInfo, removeInfo);
}, nameof(IDomainServiceCallback.OnUserRemoved));
}
Expand All @@ -533,7 +533,7 @@ void IDomainServiceCallback.OnUserChanged(SignatureDate signatureDate, Guid doma
this.InvokeAsync(() =>
{
var domain = this.Domains[domainID];
var authentication = this.userContext.Authenticate(signatureDate, domainUserInfo.Token);
var authentication = this.userContext.Authenticate(signatureDate);
domain.InvokeUserChanged(authentication, domainUserInfo, domainUserState);
}, nameof(IDomainServiceCallback.OnUserChanged));
}
Expand Down
2 changes: 2 additions & 0 deletions client/Ntreev.Crema.Services/Ntreev.Crema.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
</Compile>
<Compile Include="Domains\Domain.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Users\UserAuthentication.cs" />
<Compile Include="Users\UserAuthenticationCollection.cs" />
<Compile Include="Users\UserAuthenticationProvider.cs" />
<Compile Include="Users\UserServiceFactory.cs" />
<Compile Include="Users\User.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://schemas.ntreev.com" elementFormDefault="qualified" targetNamespace="http://schemas.ntreev.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:schema xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:tns="http://schemas.ntreev.com" elementFormDefault="qualified" targetNamespace="http://schemas.ntreev.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
<xs:complexType name="ArrayOfLogInfo">
<xs:sequence>
Expand Down Expand Up @@ -200,6 +200,7 @@
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" name="Token" type="ser:guid" />
</xs:sequence>
</xs:complexType>
<xs:element name="SignatureDate" nillable="true" type="tns:SignatureDate" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" name="Token" type="ser:guid" />
</xs:sequence>
</xs:complexType>
<xs:element name="SignatureDate" nillable="true" type="tns:SignatureDate" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://schemas.ntreev.com" elementFormDefault="qualified" targetNamespace="http://schemas.ntreev.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:schema xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:tns="http://schemas.ntreev.com" elementFormDefault="qualified" targetNamespace="http://schemas.ntreev.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
<xs:complexType name="ResultBaseOfDomainContextMetaDataq8erDhHE">
<xs:annotation>
Expand Down Expand Up @@ -108,6 +108,7 @@
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" name="Token" type="ser:guid" />
</xs:sequence>
</xs:complexType>
<xs:element name="SignatureDate" nillable="true" type="tns:SignatureDate" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ internal interface IUserServiceCallback {
void OnUserItemsDeleted(Ntreev.Library.SignatureDate signatureDate, string[] itemPaths);

[System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="http://www.ntreev.com/IUserService/OnUsersLoggedIn")]
void OnUsersLoggedIn(Ntreev.Library.SignatureDate signatureDate, string[] userIDs);
void OnUsersLoggedIn(Ntreev.Library.SignatureDate signatureDate, Ntreev.Crema.ServiceModel.AuthenticationInfo[] auteAuthenticationInfos);

[System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="http://www.ntreev.com/IUserService/OnUsersLoggedOut")]
void OnUsersLoggedOut(Ntreev.Library.SignatureDate signatureDate, string[] userIDs);
void OnUsersLoggedOut(Ntreev.Library.SignatureDate signatureDate, Ntreev.Crema.ServiceModel.AuthenticationInfo[] auteAuthenticationInfos);

[System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="http://www.ntreev.com/IUserService/OnUsersKicked")]
void OnUsersKicked(Ntreev.Library.SignatureDate signatureDate, string[] userIDs, string[] comments);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://schemas.ntreev.com" elementFormDefault="qualified" targetNamespace="http://schemas.ntreev.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:schema xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:tns="http://schemas.ntreev.com" elementFormDefault="qualified" targetNamespace="http://schemas.ntreev.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
<xs:complexType name="ResultBaseOfUserContextMetaDataq8erDhHE">
<xs:annotation>
Expand Down Expand Up @@ -119,6 +119,7 @@
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" name="Token" type="ser:guid" />
</xs:sequence>
</xs:complexType>
<xs:element name="SignatureDate" nillable="true" type="tns:SignatureDate" />
Expand Down Expand Up @@ -179,6 +180,21 @@
</xs:list>
</xs:simpleType>
<xs:element name="UserState" nillable="true" type="tns:UserState" />
<xs:complexType name="ArrayOfAuthenticationInfo">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="AuthenticationInfo" type="tns:AuthenticationInfo" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfAuthenticationInfo" nillable="true" type="tns:ArrayOfAuthenticationInfo" />
<xs:complexType name="AuthenticationInfo">
<xs:annotation>
<xs:appinfo>
<IsValueType xmlns="http://schemas.microsoft.com/2003/10/Serialization/">true</IsValueType>
</xs:appinfo>
</xs:annotation>
<xs:sequence />
</xs:complexType>
<xs:element name="AuthenticationInfo" nillable="true" type="tns:AuthenticationInfo" />
<xs:complexType name="ArrayOfBanInfo">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="BanInfo" type="tns:BanInfo" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,15 @@
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q38="http://schemas.ntreev.com" minOccurs="0" name="signatureDate" type="q38:SignatureDate" />
<xs:element xmlns:q39="http://schemas.microsoft.com/2003/10/Serialization/Arrays" minOccurs="0" name="userIDs" nillable="true" type="q39:ArrayOfstring" />
<xs:element xmlns:q39="http://schemas.ntreev.com" minOccurs="0" name="auteAuthenticationInfos" nillable="true" type="q39:ArrayOfAuthenticationInfo" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="OnUsersLoggedOut">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q40="http://schemas.ntreev.com" minOccurs="0" name="signatureDate" type="q40:SignatureDate" />
<xs:element xmlns:q41="http://schemas.microsoft.com/2003/10/Serialization/Arrays" minOccurs="0" name="userIDs" nillable="true" type="q41:ArrayOfstring" />
<xs:element xmlns:q41="http://schemas.ntreev.com" minOccurs="0" name="auteAuthenticationInfos" nillable="true" type="q41:ArrayOfAuthenticationInfo" />
</xs:sequence>
</xs:complexType>
</xs:element>
Expand Down
55 changes: 32 additions & 23 deletions client/Ntreev.Crema.Services/Users/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,28 @@
using Ntreev.Library.Linq;
using System.Security;
using System.ComponentModel;
using System.IdentityModel.Tokens;

namespace Ntreev.Crema.Services.Users
{
class User : UserBase<User, UserCategory, UserCollection, UserCategoryCollection, UserContext>,
IUser, IUserItem, IInfoProvider, IStateProvider
{
private Authentication authentication;
public UserAuthenticationCollection Authentications { get; } = new UserAuthenticationCollection();

public UserState UserState
{
get
{
this.Dispatcher.VerifyAccess();
return this.Authentications.Any() ? ServiceModel.UserState.Online : ServiceModel.UserState.None;
}
}

public bool IsOnline
{
get { return this.UserState.HasFlag(UserState.Online); }
}

public User()
{
Expand Down Expand Up @@ -84,10 +99,11 @@ public void Kick(Authentication authentication, string comment)
var users = new User[] { this };
var comments = Enumerable.Repeat(comment, users.Length).ToArray();
this.Container.InvokeUserKick(authentication, this, comment);
this.IsOnline = false;
var authenticationInfos = users.SelectMany(user => user.Authentications.Select(auth => auth.Value.Authentication.AuthenticationInfo)).ToArray();
this.Authentications.Clear();
this.Container.InvokeUsersKickedEvent(authentication, users, comments);
this.Container.InvokeUsersStateChangedEvent(authentication, users);
this.Container.InvokeUsersLoggedOutEvent(authentication, users, new CloseInfo(CloseReason.Kicked, comment));
this.Container.InvokeUsersLoggedOutEvent(authentication, authenticationInfos, new CloseInfo(CloseReason.Kicked, comment));
}

public void Ban(Authentication authentication, string comment)
Expand All @@ -103,9 +119,10 @@ public void Ban(Authentication authentication, string comment)
this.Container.InvokeUsersBannedEvent(authentication, users, comments);
if (this.IsOnline == true)
{
this.IsOnline = false;
var authenticationInfos = users.SelectMany(user => user.Authentications.Select(auth => auth.Value.Authentication.AuthenticationInfo)).ToArray();
this.Authentications.Clear();
this.Container.InvokeUsersStateChangedEvent(authentication, users);
this.Container.InvokeUsersLoggedOutEvent(authentication, users, new CloseInfo(CloseReason.Banned, comment));
this.Container.InvokeUsersLoggedOutEvent(authentication, authenticationInfos, new CloseInfo(CloseReason.Banned, comment));
}
}

Expand Down Expand Up @@ -154,12 +171,6 @@ public void SetUserInfo(UserInfo userInfo)
this.UpdateUserInfo(userInfo);
}

[EditorBrowsable(EditorBrowsableState.Never)]
public void SetUserState(UserState userState)
{
base.UserState = userState;
}

[EditorBrowsable(EditorBrowsableState.Never)]
public void SetBanInfo(BanChangeType changeType, BanInfo banInfo)
{
Expand Down Expand Up @@ -205,21 +216,25 @@ public string UserName
}
}

public new UserInfo UserInfo
protected override void InitializeUserInfo(UserInfo userInfo)
{
get
if (userInfo.AuthenticationInfos == null) return;

foreach (var auth in userInfo.AuthenticationInfos)
{
this.Dispatcher.VerifyAccess();
return base.UserInfo;
if (this.Authentications.ContainsKey(auth.Token)) continue;

var authentication = new Authentication(new AuthenticationProvider(this), auth.Token);
this.Authentications.Add(auth.Token, new UserAuthentication(this, authentication));
}
}

public new UserState UserState
public new UserInfo UserInfo
{
get
{
this.Dispatcher.VerifyAccess();
return base.UserState;
return base.UserInfo;
}
}

Expand All @@ -237,11 +252,6 @@ public bool IsBanned
get { return this.BanInfo.Path != string.Empty; }
}

public Authentication Authentication
{
get { return authentication; }
}

public IUserService Service
{
get { return this.Context.Service; }
Expand Down Expand Up @@ -344,7 +354,6 @@ public CremaDispatcher Dispatcher
protected override void OnAttached()
{
base.OnAttached();
this.authentication = new Authentication(new UserAuthenticationProvider(this));
}

private void Sign(Authentication authentication, ResultBase result)
Expand Down
44 changes: 44 additions & 0 deletions client/Ntreev.Crema.Services/Users/UserAuthentication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//Released under the MIT License.
//
//Copyright (c) 2018 Ntreev Soft co., Ltd.
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
//documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
//rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
//persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
//Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
//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 System;
using Ntreev.Crema.ServiceModel;

namespace Ntreev.Crema.Services.Users
{
class UserAuthentication : IUserAuthentication
{
public UserAuthentication(IUser user, Authentication authentication)
{
this.User = user;
this.Authentication = authentication;
}

public IUser User { get; set; }
public Authentication Authentication { get; }

public void SendMessage(Authentication authentication, string message)
{
throw new NotImplementedException();
}

public void Kick(Authentication authentication, string comment)
{
throw new NotImplementedException();
}
}
}
Loading

0 comments on commit 495deb3

Please sign in to comment.