2009-05-21 3 views
5

Esiste un modo consigliato (e preferibilmente gratuito) in ColdFusion per accedere a un file remoto protetto dall'autenticazione NTLM? Il tag cfhttp sembra supportare solo l'autenticazione di base.Autenticazione NTLM in ColdFusion

risposta

4

Questo tag CFX - CFX_HTTP5 - dovrebbe fare quello che ti serve. Costa $ 50, ma forse ne vale la pena? Sembra un piccolo prezzo da pagare.

+0

+1 E 'come ho fatto una volta. Funziona bene! –

+0

Questa non è una cattiva soluzione; L'ho usato in passato e funziona. Quello che vorrei evitare non è tanto il costo monetario, ma il costo fastidioso di mantenere le licenze e una dipendenza esterna. – Soldarnal

+0

Beh, al momento non è possibile farlo in modo nativo in CF, quindi o avete bisogno di una soluzione di terze parti come questa o avete bisogno di eseguire il rollover. – ale

1

Ecco il codice che ho trovato in:

http://www.bpurcell.org/downloads/presentations/securing_cfapps_examples.zip

Ci sono anche esempi per LDAP, webservices, e molto altro .. io ti incollare 2 file qui in modo da poter avere un'idea, sguardi di codice come dovrebbe funzionare ancora.

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

<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> 

Questo è il CFC che potrebbe essere di vostro interesse:

<!--- 
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> 
+0

Questo sembra più per se voglio proteggere la mia applicazione con NTLM. O sto capendo questo sbagliato? – Soldarnal

+0

Mi dispiace, ho letto male la domanda! –

0

Si potrebbe provare a seguire la guida qui: http://cfsilence.com/blog/client/index.cfm/2008/3/17/ColdFusionSharepoint-Integration--Part-1--Authenticating

Ecco ciò che si riduce a voi fare:

edit the client-config.wsdd 

Change

<transport 
    name="http" 
    pivot="java:org.apache.axis.transport.http.HTTPSender"> 
</transport> 

a

<transport 
    name="http" 
    pivot="java:org.apache.axis.transport.http.CommonsHTTPSender"> 
</transport> 
+0

Hmm, questo sembrava promettente, ma non ha funzionato per me. Forse CF usa Axis solo quando fa una richiesta SOAP? (Sto solo cercando di prendere un file di testo normale.) – Soldarnal

1

Se il codice da Brandon Purcell che utilizza la classe jrun.security.NTauth non funziona per voi in cf9 (non ha fatto per me) la correzione è quello di utilizzare la classe coldfusion.security.NTAuthentication invece . Tutto ha funzionato bene per me.

+0

Ho appena passato mezz'ora a cercare di trovare quel nome di classe! Grazie!! –