This repository has been archived by the owner on Feb 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NEW-FEATURE] External Authorization to work with cyclic PLC data (#513)
* Create draft PR for #512 * external authentication added possibility to use plc variable as a source of authentication token * added basic tests for the token providers Co-authored-by: PTKu <[email protected]> Co-authored-by: Peter <[email protected]>
- Loading branch information
1 parent
68c612e
commit 6be92d8
Showing
7 changed files
with
112 additions
and
37 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
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
74 changes: 74 additions & 0 deletions
74
...TcOpen.Inxton/src/TcOpen.Inxton.Local.Security.Externals/PlcTokenReader/PlcTokenReader.cs
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,74 @@ | ||
using System; | ||
using System.IO.Ports; | ||
using TcOpen.Inxton.Security; | ||
using Vortex.Connector; | ||
using Vortex.Connector.ValueTypes; | ||
|
||
namespace TcOpen.Inxton.Local.Security | ||
{ | ||
/// <summary> | ||
/// Provides access to authentication token data from the PLC. | ||
/// </summary> | ||
public class PlcTokenReader : ITokenProvider | ||
{ | ||
|
||
private readonly OnlinerString _valueToken; | ||
private readonly OnlinerBool _tokenPresence; | ||
|
||
/// <summary> | ||
/// Creates new instance of <see cref="PlcTokenReader"/> | ||
/// </summary> | ||
/// <param name="valueToken">Onliner of the variable containing value of the token</param> | ||
/// <param name="tokenPresence">Onliner indicating whether the authentication token is present (inserted/active)</param> | ||
public PlcTokenReader(OnlinerString valueToken, OnlinerBool tokenPresence) | ||
{ | ||
_valueToken = valueToken; | ||
_tokenPresence = tokenPresence; | ||
|
||
_valueToken?.Subscribe(TagDataChanged); | ||
_tokenPresence?.Subscribe(TagDataPresence); | ||
} | ||
|
||
public void SetTokenReceivedAction(Action<string> tokenReceivedAction) | ||
{ | ||
IncomingTokenAction = tokenReceivedAction; | ||
} | ||
|
||
public Action<string> IncomingTokenAction; | ||
|
||
|
||
void TagDataChanged(IValueTag sender, ValueChangedEventArgs args) | ||
{ | ||
try | ||
{ | ||
if (_tokenPresence.Synchron) | ||
{ | ||
IncomingTokenAction?.Invoke(_valueToken.Cyclic); | ||
} | ||
else | ||
{ | ||
SecurityManager.Manager.Service.DeAuthenticateCurrentUser(); | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
throw; | ||
} | ||
} | ||
|
||
void TagDataPresence(IValueTag sender, ValueChangedEventArgs args) | ||
{ | ||
try | ||
{ | ||
if(_tokenPresence.Synchron == false) | ||
{ | ||
SecurityManager.Manager.Service.DeAuthenticateCurrentUser(); | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
throw; | ||
} | ||
} | ||
} | ||
} |
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