Hi -
Can some one give me a hand, I have been struggling with this problem for quite a while. I am using cf4.5, on NT with advanced security. I want to secure a directory using a security contex thats call pageworkers. I am validating the users from an LDAP server.
I have it working to a certain extent. A user can log in, and it validates the login. The problem lies with logging the user out. I have several questions about this.
My code will be listed below.
1. I created a logout.cfm, that basically clears the session, then sends the user back to the index.cfm page.
What do I need to do to have the application.cfm prompt the user to log back in. The Login page is in the application.cfm.
2. Should my logout.cfm, do something different?
3. Its been suggested that I create a new login.cfm page, but how do you take the login information from that and authenicate the user again? Do you then create a login_action.cfm page?
4. On all pages, what code do I need to put to autenitcate the user? Is there something that checks it?
5. In my book it talks about <cfcatch> If I catch a security problem, how do you send the user to the login screen.
6. In my application.cfm, theres a section that says "showlogin", How do I force the login from this code.
Is there a better way.
Matt
Application.cfm
<cfapplication name="pw"
clientmanagement="Yes"
applicationtimeout="#CreateTime(0, 0, 1)#"
sessionmanagement="yes"
setclientcookies="no"
sessiontimeout="#CreateTime(0, 0, 1)#" >
<CFIF not IsAuthenticated()>
<!--- The user is not authenticated --->
<CFSET showLogin = "No">
<CFIF IsDefined("form.username" and
IsDefined("form.password">
<cfset session.username="#form.username#">
<cfset session.password="#form.password#">
<!--- The login form was submitted --->
<CFTRY>
<cfauthenticate setcookie="yes"
throwonfailure="Yes"
securitycontext="PageWorkers"
username="#form.username#"
password="#form.password#">
<CFCATCH TYPE="security">
<!--- Security error in login occurred,
show login again --->
<H3>Invalid Login</H3>
<CFSET showLogin = "Yes">
</CFCATCH>
</CFTRY>
<CFELSE>
<!--- The login was not detected --->
<CFSET showLogin = "Yes">
</CFIF>
<CFIF showLogin>
<!--- Recreate the url used to call this template --->
<CFSET url = "#cgi.script_name#">
<CFIF cgi.query_string is not "">
<CFSET url = url & "?#cgi.query_string#">
</CFIF>
<!--- Populate the login with the recreated url --->
<CFOUTPUT>
<FORM ACTION="#url#" METHOD="Post">
<TABLE>
<TR>
<TD>username:</TD>
<TD><INPUT TYPE="text" NAME="username"></TD>
</TR>
<TR>
<TD>password:</TD>
<TD><INPUT TYPE="password" NAME="password"></TD>
</TR>
</TABLE>
<INPUT TYPE="submit" VALUE="Login">
</FORM>
</CFOUTPUT>
<CFABORT>
</CFIF>
logout.cfm
<CFSET StructClear(Session)>
<cfset StructDelete(Session, "username">
<cfset Structclear(Session)>
<meta http-equiv="REFRESH" content="1; url=index.cfm?logout=yes">
Can some one give me a hand, I have been struggling with this problem for quite a while. I am using cf4.5, on NT with advanced security. I want to secure a directory using a security contex thats call pageworkers. I am validating the users from an LDAP server.
I have it working to a certain extent. A user can log in, and it validates the login. The problem lies with logging the user out. I have several questions about this.
My code will be listed below.
1. I created a logout.cfm, that basically clears the session, then sends the user back to the index.cfm page.
What do I need to do to have the application.cfm prompt the user to log back in. The Login page is in the application.cfm.
2. Should my logout.cfm, do something different?
3. Its been suggested that I create a new login.cfm page, but how do you take the login information from that and authenicate the user again? Do you then create a login_action.cfm page?
4. On all pages, what code do I need to put to autenitcate the user? Is there something that checks it?
5. In my book it talks about <cfcatch> If I catch a security problem, how do you send the user to the login screen.
6. In my application.cfm, theres a section that says "showlogin", How do I force the login from this code.
Is there a better way.
Matt
Application.cfm
<cfapplication name="pw"
clientmanagement="Yes"
applicationtimeout="#CreateTime(0, 0, 1)#"
sessionmanagement="yes"
setclientcookies="no"
sessiontimeout="#CreateTime(0, 0, 1)#" >
<CFIF not IsAuthenticated()>
<!--- The user is not authenticated --->
<CFSET showLogin = "No">
<CFIF IsDefined("form.username" and
IsDefined("form.password">
<cfset session.username="#form.username#">
<cfset session.password="#form.password#">
<!--- The login form was submitted --->
<CFTRY>
<cfauthenticate setcookie="yes"
throwonfailure="Yes"
securitycontext="PageWorkers"
username="#form.username#"
password="#form.password#">
<CFCATCH TYPE="security">
<!--- Security error in login occurred,
show login again --->
<H3>Invalid Login</H3>
<CFSET showLogin = "Yes">
</CFCATCH>
</CFTRY>
<CFELSE>
<!--- The login was not detected --->
<CFSET showLogin = "Yes">
</CFIF>
<CFIF showLogin>
<!--- Recreate the url used to call this template --->
<CFSET url = "#cgi.script_name#">
<CFIF cgi.query_string is not "">
<CFSET url = url & "?#cgi.query_string#">
</CFIF>
<!--- Populate the login with the recreated url --->
<CFOUTPUT>
<FORM ACTION="#url#" METHOD="Post">
<TABLE>
<TR>
<TD>username:</TD>
<TD><INPUT TYPE="text" NAME="username"></TD>
</TR>
<TR>
<TD>password:</TD>
<TD><INPUT TYPE="password" NAME="password"></TD>
</TR>
</TABLE>
<INPUT TYPE="submit" VALUE="Login">
</FORM>
</CFOUTPUT>
<CFABORT>
</CFIF>
logout.cfm
<CFSET StructClear(Session)>
<cfset StructDelete(Session, "username">
<cfset Structclear(Session)>
<meta http-equiv="REFRESH" content="1; url=index.cfm?logout=yes">