?
Solved

cflogin - Struct cannot be cast

Posted on 2011-10-10
26
Medium Priority
?
1,086 Views
Last Modified: 2012-05-12
<cfif structKeyExists(form,"username")>
	
	<cfset userLogin = application.admin.login(users_name=form.username,users_pass=form.password) />
	
	<cfdump var="#userLogin#" label="user login data output" expand="no" />
	
    <cfif len(userLogin.users_name) AND len(userLogin.users_pass)>
        <cflogin idletimeout="1800">
            <cfloginuser name = "#userLogin.users_name#" password ="#userLogin.users_pass#" roles = "#userLogin.users_admin#" />
        </cflogin>
    <cfelse>
        <cfset invalid_login = 1>
    </cfif>

</cfif>

Open in new window


The code (above) throws the following error:
Error casting an object of type coldfusion.runtime.Struct cannot be cast to coldfusion.runtime.Scope to an incompatible type. This usually indicates a programming error in Java, although it could also mean you have tried to use a foreign object in a different way than it was designed.
coldfusion.runtime.Struct cannot be cast to coldfusion.runtime.Scope

I can't for the life of me figure out why...  Any help would be appreciated.
0
Comment
Question by:brianmfalls
  • 14
  • 9
  • 3
26 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 36944744
Look at the definition of the function "login" in your "admin" cfc... the return type is probably not STRUCT, but you are returning a structure.   You can change the return type to "struct" or "any"

0
 
LVL 39

Expert Comment

by:gdemaria
ID: 36944752
To be more specific, I was referring to this line...

<cffunction name="login" returnType="xxxxx" ....
0
 
LVL 52

Expert Comment

by:_agx_
ID: 36944771
> The code (above) throws the following error:

on which line ? can you include full error message?

> <cfdump var="#userLogin#" label="user login data output" expand="no" />

what type of object does application.admin.login return?
0
Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

 
LVL 52

Expert Comment

by:_agx_
ID: 36944800
Whoops... didn't see any responses before posting.

> the return type is probably not STRUCT, but you are returning a structure.

It's possible, but I'd expect a different error.
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 36944877
Function Being referenced:
<!--------updateElement-(inception)------->
<cffunction name="updateElement" returntype="any" output="true" hint="updates data for products/services">
	
	<cfargument name="id" required="yes">
	<cfargument name="content" required="yes">
	
	<cfquery name="updateElement" datasource="#this.dsn#">
		UPDATE		prodServ
		SET			prodServ_html = #arguments.content#
		WHERE		prodServ_id = #arguments.id#
	</cfquery>
	
</cffunction>
<!--------updateElement-(completion)------->

Open in new window


I am not attempting to return anything, so I don't think that's it.

I thought that maybe it didn't like the directory structure.  I rearranged that a bit, and still I get the same error.  I am trying some other things now.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 36944898
Brian - I think you posted the wrong function.  
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 36944922
I'm mixing up my posts...  
Hold one.
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 36944929
Here's the function:
	<cffunction name="login" access="public" returntype="any" output="true" hint="returns login">
		
		<cfargument name="users_name" required="yes" />
		<cfargument name="users_pass" required="yes" />
		
		<cfquery name="loginData" datasource="#this.dsn#">
			SELECT	users_name, users_pass, users_admin
			FROM	users
			WHERE	users_name = '#arguments.users_name#'
			AND		users_pass = '#arguments.users_pass#'
		</cfquery>
		
		<cfreturn loginData>

	</cffunction>

Open in new window

0
 
LVL 1

Author Comment

by:brianmfalls
ID: 36944930
Here's the code:
<cfparam name="url.logout" default="0">
<cfparam name="invalid_login" default="0">

<cfif structKeyExists(form,"username")>
	
	<cfset userLogin = application.admin.login(users_name=form.username,users_pass=form.password) />
	
	<cfdump var="#userLogin#" label="user login data output" expand="no" />
	
    <cfif len(userLogin.users_name) AND len(userLogin.users_pass)>
        <cflogin idletimeout="1800">
            <cfloginuser name = "#userLogin.users_name#" password ="#userLogin.users_pass#" roles = "#userLogin.users_admin#" />
        </cflogin>
    <cfelse>
        <cfset invalid_login = 1>
    </cfif>

</cfif>

<cfif url.logout>
    <cflogout>
    <cflocation url="index.cfm">
</cfif>

<cfif NOT len(GetAuthUser())>
	<div class="loginForm">
		<form name="userLogin" method="post" action="index.cfm">
			<label for="username">User Name</label><input name="username" type="text" id="username">
			<label for="password">Password</label><input name="password" type="text" id="password">
			<input type="submit" name="login" value="Login">
		</form>
	</div>
<cfelse>
    <p>User: <cfoutput>#GetAuthUser()#</cfoutput></p>
    <a href="index.cfm?logout=1">Logout</a>
</cfif>

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 36944946
Works for me. Can you post the complete error message? It'd help to see the line number...
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 36944957
If I comment out the cflogin, there is no error.

Like So:
    <cfif len(userLogin.users_name) AND len(userLogin.users_pass)>
		Valid Login
        <!---<cflogin idletimeout="1800">
            <cfloginuser name = "#userLogin.users_name#" password ="#userLogin.users_pass#" roles = "#userLogin.users_admin#" />
        </cflogin>--->
    <cfelse>
        <cfset invalid_login = 1>
    </cfif>

Open in new window

0
 
LVL 1

Author Comment

by:brianmfalls
ID: 36944965
I cannot.  My host doesn't allow robust debug output.
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 36944983
Output, the cfloginuser line looks like this:
cfloginuser name = "brian" password ="jesus" roles = "1"
0
 
LVL 52

Expert Comment

by:_agx_
ID: 36945038
> cfloginuser name = "brian" password ="jesus" roles = "1"

Does it work with a hard coded string instead of the query variables ? Maybe it's the query cflogin doesn't like.

> I cannot.  My host doesn't allow robust debug output.
Wrap it in a try/catch then.

<cftry>
     .... all of your code here

     <cfcatch><cfdump var="#cfcatch#"></cfcatch>
</cftry>
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 36945079
I hard coded it, still get the error.  I'll wrap it int the catch.
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 36945172
Here's the dump from the catch:

struct
Message       coldfusion.runtime.Struct cannot be cast to coldfusion.runtime.Scope
StackTrace       java.lang.ClassCastException: coldfusion.runtime.Struct cannot be cast to coldfusion.runtime.Scope at coldfusion.tagext.security.AuthenticateTag.doStartTag(AuthenticateTag.java:80) at cflogin2ecfm1821806886.runPage(D:\brianmfalls\www\goodThrift\admin\login.cfm:9) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416) at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2722) at cfApplication2ecfm2026658558.runPage(D:\brianmfalls\www\goodThrift\admin\Application.cfm:12) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416) at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65) at coldfusion.filter.CfincludeFilter.include(CfincludeFilter.java:33) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:279) at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:94) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62) at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:126) at coldfusion.CfmServlet.service(CfmServlet.java:200) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at jrun.servlet.FilterChain.doFilter(FilterChain.java:86) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at jrun.servlet.FilterChain.doFilter(FilterChain.java:94) at jrun.servlet.FilterChain.service(FilterChain.java:101) at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106) at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42) at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286) at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543) at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203) at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320) at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428) at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266) at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
TagContext       
array
1       
struct
COLUMN       0
ID       CFAUTHENTICATE
LINE       9
RAW_TRACE       at cflogin2ecfm1821806886.runPage(D:\brianmfalls\www\goodThrift\admin\login.cfm:9)
TEMPLATE       D:\brianmfalls\www\goodThrift\admin\login.cfm
TYPE       CFML
2       
struct
COLUMN       0
ID       CFINCLUDE
LINE       12
RAW_TRACE       at cfApplication2ecfm2026658558.runPage(D:\brianmfalls\www\goodThrift\admin\Application.cfm:12)
TEMPLATE       D:\brianmfalls\www\goodThrift\admin\Application.cfm
TYPE       CFML
Type       java.lang.ClassCastException
0
 
LVL 52

Expert Comment

by:_agx_
ID: 36945237
> I hard coded it, still get the error.

Hm... if it doesn't work with simple values then that suggests the cflogin code is wrong.  Not sure.  I rarely use cflogin ...
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 36945301
I copied and pasted it directly from Adobe's documentation.  I think it's something on the server (settings).  We'll see.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 36945313
Could be.  Sorry, I don't use cflogin. So I'm out of suggestions unfortunately.
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 36945327
No worries.  I have the admin's looking at the server.  I'll post if that turns out to be the case.
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 36946097

I also don't use cflogin... so here's a very easy alternative.

Just set a session variable:

<cfset session.login.user_id = userLogin.user_id>
<cfset session.login.userName = userLogin.userName>

That's all you have to do..

Check to see if it's not populated and send the user to login...

<cfif NOT isDefined("session.login.user_id") or val(session.login.user_id) eq 0>
   .... login
</cfif>


I never userstood what cflogin provided that a few simple lines of code do not... except the cflogin stuff tends to mysteriously not work every now and then and there's no debugging it...

0
 
LVL 1

Author Comment

by:brianmfalls
ID: 36948494
That's usually what I do, I just wanted to try cflogin out.  It's no wonder why no one uses it...  Way to go Adobe!  lol
0
 
LVL 52

Expert Comment

by:_agx_
ID: 36950339
   > except the cflogin stuff tends to mysteriously not work every now
    > and then and there's no debugging it...

But don't we all need a little mystery in our lives every now and then? ;-)
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 36950677
No.  No we do not.  I'd prefer things work they way they are supposed to.  First time, and every time...  Which is more of a fantasy???
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 36950727
lol.  I've had that fantasy from time to time. Unfortunately..I always wake up ;-)
0
 
LVL 1

Author Closing Comment

by:brianmfalls
ID: 36987801
The verdict....  scrap all attempts to use cflogin
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question