Ext.define("NX.saml.app.PluginStrings",{"@aggregate_priority":90,singleton:true,requires:["NX.I18n"],keys:{SAML_SignIn_SSO:"Sign In with SSO",SAML_SignIn_Local:"Sign In without SSO"}},function(a){NX.I18n.register(a)});Ext.define("NX.saml.app.PluginConfig",{"@aggregate_priority":100,requires:["NX.saml.app.PluginStrings"],controllers:[{id:"NX.saml.controller.SamlAuth",active:function(){return NX.State.getValue("samlEnabled",false)}}]});Ext.define("NX.saml.view.SamlSignInWindow",{extend:"NX.view.ModalDialog",alias:"widget.nx-saml-signin",requires:["NX.I18n"],ui:"nx-inset",initComponent:function(){this.title=NX.I18n.get("SignIn_Title");this.width=NX.view.ModalDialog.SMALL_MODAL;this.items=[{layout:{type:"vbox",align:"middle"},defaults:{margin:{bottom:10}},items:[{xtype:"button",text:NX.I18n.get("SAML_SignIn_SSO"),ui:"nx-primary",action:"signInWithSso"},{xtype:"button",text:NX.I18n.get("SAML_SignIn_Local"),scale:"small",action:"signInLocally"}]}];this.callParent()}});Ext.define("NX.saml.controller.SamlAuth",{extend:"NX.app.Controller",requires:["NX.State","NX.saml.view.SamlSignInWindow"],listen:{controller:{"#User":{beforeauthenticate:"authenticate",beforereauthenticate:"reauthenticate",authTokenRequest:"authTokenRequest"},},component:{"button[action=signInWithSso]":{click:"doSamlSignin",},"button[action=signInLocally]":{click:"doLocalSignin"}}},refs:[{ref:"samlSignInWindow",selector:"nx-saml-signin"}],views:["SamlSignInWindow"],showLocalSignInWindow:undefined,authenticate:function(a){if(!NX.State.getValue("samlEnabled",false)){console.debug("saml not enabled, showing regular login dialog");return true}this.showLocalSignInWindow=a;this.getSamlSignInWindowView().create();return false},reauthenticate:function(){var a=NX.State.getUser().authenticatedRealms||[];if(Ext.Array.contains(a,"SamlRealm")){console.warn("SAML user attempted to access a feature they have no permissions for, skip reauthentication");return false}},authTokenRequest:function(c){var b=new Ext.Deferred(),a=NX.State.getUser().authenticatedRealms||[];if(Ext.Array.contains(a,"SamlRealm")){axios.get("/service/rest/internal/ui/saml/authToken").then(function(d){b.resolve(d.data)});if(Ext.isArray(c)){c.push(b)}}return true},doSamlSignin:function(){window.location.href="saml"},doLocalSignin:function(){this.getSamlSignInWindow().close();this.showLocalSignInWindow()}});
