public ActionResult MethodUpdate(AuthenticationMethodModel model, GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageExternalAuthenticationMethods)) { return(AccessDeniedView()); } var eam = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(model.SystemName); if (eam.IsMethodActive(_externalAuthenticationSettings)) { if (!model.IsActive) { //mark as disabled _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Remove(eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } else { if (model.IsActive) { //mark as active _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Add(eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } return(Methods(command)); }
public async Task <IActionResult> MethodUpdate(AuthenticationMethodModel model) { var eam = _openAuthenticationService.LoadAuthenticationProviderBySystemName(model.SystemName); if (eam.IsMethodActive(_externalAuthenticationSettings)) { if (!model.IsActive) { //mark as disabled _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Remove(eam.SystemName); await _settingService.SaveSetting(_externalAuthenticationSettings); } } else { if (model.IsActive) { //mark as active _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Add(eam.SystemName); await _settingService.SaveSetting(_externalAuthenticationSettings); } } return(new JsonResult("")); }
public IActionResult MethodUpdate(AuthenticationMethodModel model) { var eam = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(model.SystemName); if (eam.IsMethodActive(_externalAuthenticationSettings)) { if (!model.IsActive) { //mark as disabled _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Remove(eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } else { if (model.IsActive) { //mark as active _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Add(eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } var pluginDescriptor = eam.PluginDescriptor; pluginDescriptor.DisplayOrder = model.DisplayOrder; PluginFileParser.SavePluginDescriptionFile(pluginDescriptor); //reset plugin cache _pluginFinder.ReloadPlugins(); return(new NullJsonResult()); }
/// <summary> /// Convert user token policy to service model /// </summary> /// <param name="policy"></param> /// <param name="serializer"></param> /// <returns></returns> public static AuthenticationMethodModel ToServiceModel(this UserTokenPolicy policy, IJsonSerializer serializer) { if (policy == null) { return(null); } var result = new AuthenticationMethodModel { Id = policy.PolicyId, SecurityPolicy = policy.SecurityPolicyUri }; switch (policy.TokenType) { case UserTokenType.Anonymous: result.CredentialType = CredentialType.None; break; case UserTokenType.UserName: result.CredentialType = CredentialType.UserName; break; case UserTokenType.Certificate: result.CredentialType = CredentialType.X509Certificate; result.Configuration = policy.IssuerEndpointUrl; break; case UserTokenType.IssuedToken: switch (policy.IssuedTokenType) { case "http://opcfoundation.org/UA/UserToken#JWT": result.CredentialType = CredentialType.JwtToken; try { // See part 6 result.Configuration = serializer.Parse( policy.IssuerEndpointUrl); } catch { // Store as string result.Configuration = policy.IssuerEndpointUrl; } break; default: // TODO return(null); } break; default: return(null); } return(result); }
/// <summary> /// Create api model from service model /// </summary> /// <param name="model"></param> public AuthenticationMethodApiModel(AuthenticationMethodModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } Id = model.Id; SecurityPolicy = model.SecurityPolicy; Configuration = model.Configuration; CredentialType = model.CredentialType == IIoT.OpcUa.Core.Models.CredentialType.None ? null : model.CredentialType; }
/// <summary> /// Create api model from service model /// </summary> /// <param name="model"></param> public static AuthenticationMethodApiModel ToApiModel( this AuthenticationMethodModel model) { if (model == null) { return(null); } return(new AuthenticationMethodApiModel { Id = model.Id, SecurityPolicy = model.SecurityPolicy, Configuration = model.Configuration, CredentialType = (IIoT.OpcUa.Api.Core.Models.CredentialType?)model.CredentialType ?? IIoT.OpcUa.Api.Core.Models.CredentialType.None }); }
public virtual IActionResult MethodUpdate(AuthenticationMethodModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageExternalAuthenticationMethods)) { return(AccessDeniedView()); } var eam = _externalAuthenticationService.LoadExternalAuthenticationMethodBySystemName(model.SystemName); if (eam.IsMethodActive(_externalAuthenticationSettings)) { if (!model.IsActive) { //mark as disabled _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Remove(eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } else { if (model.IsActive) { //mark as active _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Add(eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } var pluginDescriptor = eam.PluginDescriptor; pluginDescriptor.DisplayOrder = model.DisplayOrder; //update the description file PluginManager.SavePluginDescriptor(pluginDescriptor); //reset plugin cache _pluginFinder.ReloadPlugins(pluginDescriptor); return(new NullJsonResult()); }
/// <summary> /// Convert service model to user token policy /// </summary> /// <param name="policy"></param> /// <returns></returns> public static UserTokenPolicy ToStackModel(this AuthenticationMethodModel policy) { if (policy == null) { return(null); } var result = new UserTokenPolicy { SecurityPolicyUri = policy.SecurityPolicy, PolicyId = policy.Id }; switch (policy.CredentialType) { case CredentialType.None: result.TokenType = UserTokenType.Anonymous; break; case CredentialType.UserName: result.TokenType = UserTokenType.UserName; break; case CredentialType.X509Certificate: result.TokenType = UserTokenType.Certificate; break; case CredentialType.JwtToken: result.TokenType = UserTokenType.IssuedToken; result.IssuedTokenType = "http://opcfoundation.org/UA/UserToken#JWT"; result.IssuerEndpointUrl = policy.Configuration?.ToString(); break; default: return(null); } return(result); }