<cfif form.Type EQ "Patch">
    <cfinclude template="patch_16.5.02.cfm">
</cfif>

<!--- AZ-4953 Add CORSPolicyEnabled setting --->
<cftransaction>
    <cfquery datasource="#application.config.DSN#" name="CorsPolicyEnabled">
        IF NOT EXISTS (SELECT * FROM AppSetting WHERE Name = 'CORSPolicyEnabled')
        BEGIN
            INSERT INTO [dbo].[AppSetting] ([Name], [Value])
            VALUES ('CORSPolicyEnabled', '0')
        END
    </cfquery>
</cftransaction>


<!--- AZ-4953 Create new CORSWhiteList Table and insert default values --->
<cftransaction>
    <cfquery name="checkCORSTableExists" datasource="#application.config.DSN#">
        IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='CORSWhiteList')
        BEGIN
            CREATE TABLE CORSWhiteList (
                ID int IDENTITY(1,1) PRIMARY KEY,
                Domain varchar(255),
                Provider varchar(255),
                Enabled bit DEFAULT 0,
                AddedBy varchar(50) DEFAULT 'System'
            )

            -- Insert SSO Provider domains
            INSERT INTO CORSWhiteList (Domain, Provider, Enabled, AddedBy)
            VALUES 
                ('https://okta.com', 'Okta', 0, 'System'),
                ('https://login.microsoftonline.com', 'Microsoft Azure AD', 0, 'System'),
                ('https://windows.net', 'Microsoft Azure AD', 0, 'System'),
                ('https://sts.windows.net', 'Microsoft', 0, 'System'),
                ('https://graph.microsoft.com', 'Microsoft', 0, 'System'),
                ('https://accounts.google.com', 'Google Workspace', 0, 'System'),
                ('https://onelogin.com', 'OneLogin', 0, 'System'),
                ('https://pingidentity.com', 'Ping Identity', 0, 'System'),
                ('https://auth0.com', 'Auth0', 0, 'System'),
                ('https://jumpcloud.com', 'JumpCloud', 0, 'System'),
                ('https://login.salesforce.com', 'Salesforce', 0, 'System'),
                ('https://test.salesforce.com', 'Salesforce', 0, 'System'),
                ('https://ibm.com', 'IBM Security Access Manager', 0, 'System'),
                ('https://oracle.com', 'Oracle Identity Federation', 0, 'System'),
                ('https://canarie.ca', 'Canadian Access Federation (CAF)', 0, 'System'),
                ('https://connect.canada.ca', 'Sign In Canada Platform', 0, 'System');
        END
    </cfquery>
</cftransaction>