Saving TicketGrantingTicket is failing.

56 views
Skip to first unread message

Larry Zhao

unread,
Oct 22, 2012, 1:06:18 AM10/22/12
to rubycas...@googlegroups.com
Hi, Guys,

I am using the latest rubycas-server from Github repository. It works very well in development on my machine, but after I deployed on to my staging machine, an Internal Server Error poped up when I perform a log-in.

I tried to debug, and found that the error is raised by tgt.save! from lib/casserver/cas.rb


def generate_ticket_granting_ticket(username, extra_attributes = {})
    # 3.6 (ticket granting cookie/ticket)
    tgt = TicketGrantingTicket.new
    tgt.ticket = "TGC-" + CASServer::Utils.random_string
    tgt.username = username
    tgt.extra_attributes = extra_attributes
    tgt.client_hostname = @env['HTTP_X_FORWARDED_FOR'] || @env['REMOTE_HOST'] || @env['REMOTE_ADDR']
$LOG.debug tgt.inspect
    tgt.save!
    $LOG.debug("Generated ticket granting ticket '#{tgt.ticket}' for user" +
      " '#{tgt.username}' at '#{tgt.client_hostname}'" +
      (extra_attributes.blank? ? "" : " with extra attributes #{extra_attributes.inspect}"))
    tgt
  end

I changed the code a little bit to print out more information, and refreshed my database, but it's still failing, I don't know how to investigate further. Needed your help.

From casserver.log, the authentication is successful and it stops just before the tgt.inpect

D, [2012-10-22T13:04:20.674304 #4944] DEBUG -- : Logging in with username: yuhao, lt: LT-1350882260r94CD7D01D8421A6E3A, service: , auth: [CASServer::Authenticators::SQLBcrypt]
D, [2012-10-22T13:04:20.674714 #4944] DEBUG -- : CASServer::Authenticators::SQLBcrypt: [CASServer::Authenticators::SQLBcrypt::CASUser_0] 
D, [2012-10-22T13:04:20.967765 #4944] DEBUG -- : CASServer::Authenticators::SQLBcrypt will try to extract the following extra_attributes: ["name", "email", "ziya_news_role", "news_manage_cats", "news_read_cats"]
D, [2012-10-22T13:04:20.968003 #4944] DEBUG -- : CASServer::Authenticators::SQLBcrypt: Read the following extra_attributes for user "yuhao": {"name"=>"\u4E8E\u6D69", "email"=>"yu...@ziya.gov.cn", "ziya_news_role"=>"admin", "news_manage_cats"=>nil, "news_read_cats"=>nil}
I, [2012-10-22T13:04:20.968050 #4944]  INFO -- : Credentials for username 'yuhao' successfully validated using CASServer::Authenticators::SQLBcrypt.
D, [2012-10-22T13:04:20.968095 #4944] DEBUG -- : Authenticator provided additional user attributes: {"name"=>"\u4E8E\u6D69", "email"=>"yu...@ziya.gov.cn", "ziya_news_role"=>"admin", "news_manage_cats"=>nil, "news_read_cats"=>nil}
D, [2012-10-22T13:04:20.978150 #4944] DEBUG -- : tgt: #<CASServer::Model::TicketGrantingTicket id: nil, ticket: "TGC-1350882260r1CA2A7645A92C22295", created_on: nil, client_hostname: "173.224.220.149", username: "yuhao", extra_attributes: {"name"=>"\u4E8E\u6D69", "email"=>"yu...@ziya.gov.cn", "ziya_news_role"=>"admin", "news_manage_cats"=>nil, "news_read_cats"=>nil}>


What could be the problem?


Regards.

Larry

Larry Zhao

unread,
Oct 22, 2012, 3:54:06 AM10/22/12
to rubycas...@googlegroups.com
I turned on :show_exceptions to true on my staging environment, and got this, what the reason is that?

Inline image 1

Regards.

Larry
Screen Shot 2012-10-22 at 15.48.03 .png

Larry Zhao

unread,
Oct 22, 2012, 4:28:15 AM10/22/12
to rubycas...@googlegroups.com
Finally, I found out that it's because in there's non-ASCII characters in the extra_attributes filed of TicketGrantingTicket, in my case, Chinese, which caused this error when being serialized into YAML I believe.


Just fixed it by adding the following on top of my Gemfile, I am not sure if it's the good solution or not...

if RUBY_VERSION =~ /1.9/
  Encoding.default_external = Encoding::UTF_8
  Encoding.default_internal = Encoding::UTF_8
end

Regards.

Larry
Screen Shot 2012-10-22 at 15.48.03 .png

Matt Zukowski

unread,
Oct 22, 2012, 2:59:38 PM10/22/12
to rubycas...@googlegroups.com
Thanks for that Larry. Tyler and I were actually trying to deal with this same issue last week, but taking a different approach. This might help.

--
You received this message because you are subscribed to the Google Groups "RubyCAS" group.
To post to this group, send email to rubycas...@googlegroups.com.
To unsubscribe from this group, send email to rubycas-serve...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubycas-server?hl=en.

Screen Shot 2012-10-22 at 15.48.03 .png

t.pickett66

unread,
Oct 24, 2012, 1:24:07 PM10/24/12
to rubycas...@googlegroups.com, ma...@roughest.net
I'll work on incorporating this into my existing UTF-madness branch.

t.pickett66

unread,
Oct 26, 2012, 2:27:14 PM10/26/12
to rubycas...@googlegroups.com, ma...@roughest.net
Larry, what database and interpreter are you using? I'm trying to reproduce this with tests using the string you supplied and can't seem to get 1.9.3 to gag on it.

The spec I've added is:

describe CASServer::Model::TicketGrantingTicket do
  it "should successfully be able to serialize non-ascii extra attributes" do
    tgt = CASServer::Model::TicketGrantingTicket.new
    tgt.ticket = "test-ticket"
    tgt.username = 'name'
    tgt.extra_attributes = {"name"=>"于浩"}
    tgt.client_hostname = 'host.test'

    tgt.save!
    1.should == 1
  end
end

The only way I can get this error to be thrown is by removing the encoding statement from the top of the spec file and then it fails when parsing the file. I wonder if specifying the encoding of the files is masking the issue. I'll keep poking at it but if you have time please pull from my utf8-madness branch and see if the problem persists without your fix.

Larry Zhao

unread,
Oct 27, 2012, 12:09:51 PM10/27/12
to rubycas...@googlegroups.com, ma...@roughest.net
Hi, Tyler,

I am using ruby-1.9.3-p194 and mysql. I may have no time to work on this tomorrow, but I will check your branch out on Monday and give you a feedback.


Cheers,

--- 
Larry Zhao

To view this discussion on the web visit https://groups.google.com/d/msg/rubycas-server/-/HHM5UFD3xtEJ.

Larry Zhao

unread,
Oct 27, 2012, 10:33:33 PM10/27/12
to rubycas...@googlegroups.com, ma...@roughest.net
Hi, Tyler,

I am using ruby-1.9.3-p194 and mysql. I may have got no time tomorrow, but I will check your branch out on Monday and give you feedback.



Cheers,

--- 
Larry Zhao

On Saturday, October 27, 2012 at 02:27 , t.pickett66 wrote:

To view this discussion on the web visit https://groups.google.com/d/msg/rubycas-server/-/HHM5UFD3xtEJ.

Larry Zhao

unread,
Oct 29, 2012, 6:04:23 AM10/29/12
to rubycas...@googlegroups.com
Hi, Tyler, where is this 'utf8-madness' branch? I didn't found it at https://github.com/tpickett66/rubycas-server nor under your github repos https://github.com/tpickett66


Cheers,

--- 
Larry Zhao

t.pickett66

unread,
Oct 29, 2012, 1:43:13 PM10/29/12
to rubycas...@googlegroups.com
Larry,
Sorry for the confusion it was originally filed under my company's account (https://github.com/r2practice/rubycas-server) but has sense been merged into the main master so I removed the branch from that repo.

Larry Zhao

unread,
Nov 4, 2012, 12:21:00 AM11/4/12
to rubycas...@googlegroups.com
Hi, Tyler,

I suppose I should use the master branch from the repo under your company's account to try this UTF-8 thing out. 

I started the application on my local machine, but I encountered the following exception when calling /login :

Inline image 1

Is there anything I missed?

Regards.

Larry


To view this discussion on the web visit https://groups.google.com/d/msg/rubycas-server/-/SgmKCdFbofsJ.
image.png

t.pickett66

unread,
Nov 5, 2012, 3:29:33 PM11/5/12
to rubycas...@googlegroups.com
Larry,

That's strange. The undefined method on String was added in another series of commits that were merged recently. The extension should be found in casserver/core_ext/string.rb Either it isn't getting required and included in String or it doesn't exist. I'm not sure why either of these would be happening since I'm using the current master for my own testing without incident.

Larry Zhao

unread,
Nov 6, 2012, 10:12:43 AM11/6/12
to rubycas...@googlegroups.com
Hi, Tyler,

Found out that after I add `require 'casserver/core_ext'` this line to `casserver/server` this Sting extension thing is fixed. I could see the login page showing now. 

I got no time for the rest today. I will try it out in the next few days. 

Regards.

Larry


To view this discussion on the web visit https://groups.google.com/d/msg/rubycas-server/-/c4AUXu0k4JoJ.
Reply all
Reply to author
Forward
0 new messages