<%
' *****************************************************************************
'
'	This file contains methods and variables to help with the use of IIS
'	Authentication.
'
' *****************************************************************************


' Constant flag for enabling or disabling the use of IIS security context login
' To disable use of IIS security context login, set this flag to False
Const CF_ENABLE_IIS_SECURITY_CONTEXT_LOGIN = False


' Cookie that indicates a successful IIS authentication occurred during the 
' browser session. Used to deny access if further requests are made 
' anonymously during the same session.
Const CSTR_COOKIE_USING_IIS = "USEIISAUTHENTICATION"


' ---- [Public] Returns True if authentication scripts are configured to use
' the IIS authentication mechanisms. This just returns the state
' of the constant flag CF_ENABLE_IIS_SECURITY_CONTEXT_LOGIN
'
Function IsUsingIISAuthentication()
	if Request.Cookies( "CMSAUTHTOKEN" ) <> "" Or Request.QueryString( "CMSAUTHTOKEN" ) <> "" then
		IsUsingIISAuthentication = false
	end if


	IsUsingIISAuthentication = CF_ENABLE_IIS_SECURITY_CONTEXT_LOGIN

End Function


' ---- [Public] Sends a 401 Unauthorized status as the HTTP response and ends
' the request.  The IIS authentication control settings determine the 
' WWW-Authenticate headers that go along with this response
'  
Function RequestIISAuthentication( strMessage )

	Response.status = "401 Unauthorized"
	Response.Write( strMessage )
	Response.End

End Function


' ---- [Public] The IISSecurityContextLogin function attempts to authenticate using 
' the current IIS Security Context. This function will not use the security
' context if site server authentication is being used or if IIS is using 
' the anonymous context - indicated by an empty LOGON_USER field
'
Function IISSecurityContextLogin()
	IISSecurityContextLogin = False

	if Request.Cookies( "CMSAUTHTOKEN" ) <> "" Or Request.QueryString( "CMSAUTHTOKEN" ) <> "" then
		exit function
	end if
	
	if Not Autosession.IsUsingSiteServerAuthentication Then 

		Dim strAuthUser
		strAuthUser = Request.ServerVariables("LOGON_USER")

		If strAuthUser <> "" Then

			' Attempt to login using the current security context user. 
			' A CMSAUTHTOKEN cookie is not installed
			IISSecurityContextLogin = AutoSession.AuthenticateAsUser("","",False)

		End If
	End If
	
End Function

%>
