I got the following source code from Brandon Purcell, dont know if you
already have it, and it works fine. But you are right about the roles thing,
because we are going to store the roles in the db for the application users,
so they will be different than their network roles.


The only code you should have to change is the request.mydomain variable
located on line 4 of the application.cfm to the name of your domain, and
then add the db functionality in the cfc for your specific application(this
is for roles, or whatever) if you are just using nt authentication, then you
only need to change the domain name.


Application.cfm
||||||||||||||||||||||||||||||||||||||||||||||||||||
<cfapplication name="example2" sessionmanagement="Yes">
<!--- Application.cfm --->
<!--- CFMX will check for authentication with each page request. --->
<cfset Request.myDomain="yipgroup">


<cfif isdefined("url.logout")>
<CFLOGOUT>
</cfif>

<cflogin>
<cfif not IsDefined("cflogin")>
      <cfinclude template="loginform.cfm">
      <cfabort>
   <cfelse>
      <!---Invoke NTSecurity CFC --->
   <cfinvoke component = "NTSecurity" method = "authenticateAndGetGroups"
   returnVariable = "userRoles" domain = "#Request.myDomain#"
   userid = "#cflogin.name#" passwd = "#cflogin.password#">
  <cfif userRoles NEQ "">
   <cfloginuser name = "#cflogin.name#" password = "#cflogin.password#"
roles="#stripSpacesfromList(userRoles)#">
   <!--- <cfset session.displayroles=stripSpacesfromList(userRoles)><!---
for displaying roles only ---> --->
  <cfelse>
   <cfset loginmessage="Invalid Login">
   <cfinclude template="loginform.cfm">
   <cfabort>
  </cfif>
   </cfif>
</cflogin>


<!--- strips leading & trailing spaces from the list of roles that was
returned --->
<cffunction name="stripSpacesfromList">
<cfargument name="myList">
<cfset myArray=listtoarray(arguments.myList)>
<cfloop index="i" from="1" to="#arraylen(myArray)#" step="1">
  <!--- <cfset myArray[i]=replace(trim(myArray[i]), " ", "_")>
  out<br>--->
  <cfset myArray[i]=trim(myArray[i])>
</cfloop>
<cfset newList=arrayToList(myArray)>
<cfreturn newList>
</cffunction>
||||||||||||||||||||||||||||||||||||||||||||||||||||


ntSecurity.cfc
||||||||||||||||||||||||||||||||||||||||||||||||||||
<!---
This component implements methods for use for NT Authentication and
Authorization.


$Log: NTSecurity.cfc,v $
Revision 1.1  2002/03/08 22:40:41  jking
Revision 1.2  2002/06/26 22:46  Brandon Purcell
component for authentication and authorization
--->


<cfcomponent name="NTSecurity" >


        <!---  Authenticates the user and outputs true on success and false
on failure. --->
        <cffunction name="authenticateUser" access="REMOTE" output="no"
static="yes" hint="Authenticates the user." returntype="boolean">
                <cfargument name="userid" type="string" required="true" />
                <cfargument name="passwd" type="string" required="true" />
                <cfargument name="domain" type="string" required="true" />
                <cftry>
                        <cfscript>
                        ntauth = createObject("java",
"jrun.security.NTAuth");
                        ntauth.init(arguments.domain);
                        // authenticateUser throws an exception if it fails,

                        ntauth.authenticateUser(arguments.userid,
arguments.passwd);
                        </cfscript>
                        
                <cfreturn true>
                <cfcatch>
    <cfreturn false>
                </cfcatch>
                </cftry>  
        </cffunction>
        
        <!---
                Authenticates the user and outputs true on success and false
on failure.
        --->
        <cffunction access="remote" name="getUserGroups" output="false"
returntype="string" hint="Gets user groups." static="yes">
                <cfargument name="userid" type="string" required="true" />
                <cfargument name="domain" type="string" required="true" />
               
                 <cftry>
                        <cfscript>
                        ntauth = createObject("java",
"jrun.security.NTAuth");
                        ntauth.init(arguments.domain);
                        groups = ntauth.GetUserGroups(arguments.userid);
                        // note that groups is a java.util.list, which
should be
                        // equiv to a CF array, but it's not right now???
                        groups = trim(groups.toString());
                        groups = mid(groups,2,len(groups)-2);
                        </cfscript>
                       <cfreturn groups>
                <cfcatch>
      <cflog text="Error in ntsecurity.cfc method getUserGroups - Error:
#cfcatch.message#" type="Error" log="authentication" file="authentication"
thread="yes" date="yes" time="yes" application="no">
                        <cfreturn "">
        </cfcatch>
                </cftry>  
               
        </cffunction>
  
   
        <!---
                This method combines the functionality of authenticateUser
and getUserGroups.
        --->
        <cffunction access="remote" name="authenticateAndGetGroups"
output="false" returntype="string" hint="Authenticates the user and gets
user groups if it returns nothing the user is not authticated" static="yes">
                <cfargument name="userid" type="string" required="true" />
                <cfargument name="passwd" type="string" required="true" />
                <cfargument name="domain" type="string" required="true" />  
                 <cftry>  
                        <cfscript>
                        ntauth = createObject("java",
"jrun.security.NTAuth");
                        ntauth.init(arguments.domain);
                        // authenticateUser throws an exception if it fails,

                        // so we don't have anything specific here
                        ntauth.authenticateUser(arguments.userid,
arguments.passwd);
                        groups = ntauth.GetUserGroups(arguments.userid);
                                
                        // note that groups is a java.util.list, which
should be
                        // equiv to a CF array, but it's not right now
                        groups = trim(groups.toString());
                        groups = mid(groups,2,len(groups)-2);
                        </cfscript>     
                <cfreturn groups>
                <cfcatch>
     <cfreturn "">
        </cfcatch>
                </cftry>   
               
        </cffunction>


</cfcomponent>
||||||||||||||||||||||||||||||||||||||||||||||||||||


index.cfm
||||||||||||||||||||||||||||||||||||||||||||||||||||
<html>
<head>
<title>NT Domain Authentication</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="" rel="stylesheet" type="text/css">
</head>


<body>

<cfoutput>
<p>
  <b>Welcome, #GetAuthUser()#!</b>
  <cfoutput><br>You were logged into the following Roles- <!---
#session.displayroles# ---></cfoutput>
</p>
</cfoutput>
<p>Based on your user name, your security credentials let you access the
following tasks:<br />
(These links are for display purposes only.)</p>
<p>
<b>Task Menu</b><br />
<!--- Check roles for permission to view --->
<cfif isUserInRole("TECHSUPPORT")>
  <a href="" Support HomePage</a><br>
</cfif>
<cfif isUserInRole("Domain Users")>
  <a href="" Users Page</a><br>
</cfif>
<cfif isUserInRole("Administrators")>
  <a href=""> </cfif>
<cfif isUserInRole("AUSER")>
  <a href="" User Tasks</a><br>
</cfif>


</p>
<p>
<a href="" out</a><br>
</p>
</body>
</html>
||||||||||||||||||||||||||||||||||||||||||||||||||||


loginform.cfm
|||||||||||||||||||||||||||||||||||||||||||||||||||
<html>
<head>
<title>Login Form</title>
<link href="" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>


<body>
<H2>Please Log In <cfif isdefined("loginmessage")>(Invalid
Login)</cfif></H2>
<cfoutput>
    <form action="" method="Post">
       <table>
          <tr>
             <td>username:</td>
             <td><input type="text" name="j_username"></td>
          </tr>
          <tr>
             <td>password:</td>
             <td><input type="password" name="j_password"></td>
          </tr>
       </table>
       <br>
       <input type="submit" value="Log In">
    </form>
    <p>&nbsp;</p>
</cfoutput>
<cfinvoke component = "NTSecurity" method = "getNTUser"
   returnVariable = "user" domain = "#Request.myDomain#">
<cfoutput>#user#</cfoutput>
<p><a href="">

</body>
</html>
|||||||||||||||||||||||||||||||||||||||||||||||||||

-----Original Message-----
From: CF Lists [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 25, 2003 8:57 AM
To: CF-Talk
Subject: CFLogin

How about a show of hands of people using CFLogin? I've been trying to get
my head around it for a few days now. I did a tutorial on EasyCFM and got
MORE confused. Anyone like it? Anyone want to take a shot at explaining it?
I'm still not sure what MM gave us. A "container"? We still have to provide
tables to store the username/pw and the roles? HELP!

  _____  


[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to