Skip to content

Commit

Permalink
ActivateSession fix for changing identity from UserName to Anonymous. F…
Browse files Browse the repository at this point in the history
…ixes #1149 (#1360)

Check for unsupported UserIdentity type in ReferenceServer e.g. IssuedToken identity
  • Loading branch information
AlinMoldovean committed Apr 14, 2021
1 parent 8a8a382 commit fafc442
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 13 additions & 3 deletions Applications/ReferenceServer/ReferenceServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,19 @@ private void SessionManager_ImpersonateUser(Session session, ImpersonateEventArg
return;
}

// allow anonymous authentication and set Anonymous role for this authentication
args.Identity = new UserIdentity();
args.Identity.GrantedRoleIds.Add(ObjectIds.WellKnownRole_Anonymous);
// check for anonymous token.
if (args.NewIdentity is AnonymousIdentityToken || args.NewIdentity == null)
{
// allow anonymous authentication and set Anonymous role for this authentication
args.Identity = new UserIdentity();
args.Identity.GrantedRoleIds.Add(ObjectIds.WellKnownRole_Anonymous);

return;
}

// unsuported identity token type.
throw ServiceResultException.Create(StatusCodes.BadIdentityTokenInvalid,
"Not supported user token type: {0}.", args.NewIdentity);
}

/// <summary>
Expand Down
6 changes: 0 additions & 6 deletions Libraries/Opc.Ua.Server/Session/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -939,12 +939,6 @@ internal void TraceState(string context)
if (identityToken == null || identityToken.Body == null ||
identityToken.Body.GetType() == typeof(Opc.Ua.AnonymousIdentityToken))
{
// not changing the token if already activated.
if (m_activated)
{
return null;
}

// check if an anonymous login is permitted.
if (m_endpoint.UserIdentityTokens != null && m_endpoint.UserIdentityTokens.Count > 0)
{
Expand Down

0 comments on commit fafc442

Please sign in to comment.