# Authorisation question

**URL:** <https://www.ruby-forum.com/t/authorisation-question/58735>\
**Category:** Rails\
**Created:** [April 25, 2006, 1:17pm UTC](https://www.ruby-forum.com/t/authorisation-question/58735 "2006-04-25T13:17:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [April 25, 2006, 1:17pm UTC](https://www.ruby-forum.com/t/authorisation-question/58735/1 "2006-04-25T13:17:47Z")

</div>

My authentication (signup/login) is up and running in my app, now I need  
to implement an authorisation system. Its not going to be a complex  
one. One admin (me) and then normal members and premium members. Any  
tutorials or tips on a simple way to get this running? Thanks.

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [April 25, 2006, 1:20pm UTC](https://www.ruby-forum.com/t/authorisation-question/58735/2 "2006-04-25T13:20:07Z")

</div>

Rob B. wrote:

> My authentication (signup/login) is up and running in my app, now I need  
> to implement an authorisation system. Its not going to be a complex  
> one. One admin (me) and then normal members and premium members. Any  
> tutorials or tips on a simple way to get this running? Thanks.

See Chad F.s Rails Recipes for 2 or 3 different authentication  
options.

Available Now (!) from the Prags on PDF.

A.

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [April 25, 2006, 1:29pm UTC](https://www.ruby-forum.com/t/authorisation-question/58735/3 "2006-04-25T13:29:20Z")

</div>

Alan F. wrote:

> Rob B. wrote:
> 
> > My authentication (signup/login) is up and running in my app, now I need  
> > to implement an authorisation system. Its not going to be a complex  
> > one. One admin (me) and then normal members and premium members. Any  
> > tutorials or tips on a simple way to get this running? Thanks.
> 
> See Chad F.s Rails Recipes for 2 or 3 different authentication  
> options.
> 
> Available Now (!) from the Prags on PDF.
> 
> A.

Yeah I have that - his examples are hard to follow for a newbie like  
myself. He uses the console to give privileges and doesn’t expand his  
example any further. I have tried the main one but it locks me out of  
the app completely, so Im looking for a more simple method!

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [April 25, 2006, 2:12pm UTC](https://www.ruby-forum.com/t/authorisation-question/58735/4 "2006-04-25T14:12:12Z")

</div>

I have been writing a Rails 1.1.2 plug-in that authenticates a user  
using NTLM on an IIS server. It all works great with Webrick. Also my  
logger writes work fine when running with Webrick. When I switch over  
to Apache/FastCGI on the same box the plug-in doesn’t behave as I would  
expect and even more disturbing my logger statements aren’t writing to  
the log file. Either the Rails standard log or to the custom mylog.log  
I created just to see if I needed to define my own. I’m a bit stuck as  
to why the app logs just fine in Webrick and not with Apache/FastCGI.

Thanks,

Charles L.

module Authenticate  
def authenticate  
#mylog = Logger.new(“#{RAILS\_ROOT}/log/#{RAILS\_ENV}”)  
mylog = Logger.new(“#{RAILS\_ROOT}/log/mylog.log”)  
mylog.info(‘Application starting’)

```
mylog.debug "coming in with session: " + session.inspect

# We won't bother if the user is already authenticated
unless session["authenticated_user"]
  # Check to see if we have sent the session_id to the table yet
  unless session["sent_sessionid"]
    mylog.debug "sending session id"
    @url = request.env['REQUEST_URI']
    unless @url =~ /http/i
      @url = 'http://' + request.env['SERVER_NAME'] +

```

request.env[‘REQUEST\_URI’]  
end  
a\_session = SQLSession.new(  
:session\_id =\> session.session\_id,  
:url =\> @url,  
:created\_at =\> Time.now  
)  
a\_session.save  
session[“sent\_sessionid”] = true  
redirect\_to “[http://mckinley/authenticate?session\_id=](http://mckinley/authenticate?session_id=)” +  
session.session\_id and return  
else  
a\_session = SQLSession.find(:first, :conditions =\> [‘session\_id  
= ?’, session.session\_id ])  
if a\_session  
session[“authenticated\_user”] = a\_session.username  
#mylog.debug “redirecting to url”  
#redirect\_to a\_session.url and return  
true  
else  
mylog.debug “sent\_sessionid is false”  
true  
end  
end  
else  
# session[“authenticated\_user”] is already set  
mylog.debug “truth or dare!”  
true  
end  
end  
end

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [April 25, 2006, 3:58pm UTC](https://www.ruby-forum.com/t/authorisation-question/58735/5 "2006-04-25T15:58:33Z")

</div>

For anyone else running into this the problem was Apache was not killing  
the Ruby.exe processes as it ought to. There must have been forty stale  
Ruby processes and I was getting the old plug-in from one of them. The  
solution was to either kill them all or reboot.

Charles

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [April 25, 2006, 3:36pm UTC](https://www.ruby-forum.com/t/authorisation-question/58735/6 "2006-04-25T15:36:30Z")

</div>

On Tue, 2006-04-25 at 13:29 +0200, Rob B. wrote:

> > Available Now (!) from the Prags on PDF.
> > 
> > A.
> 
> Yeah I have that - his examples are hard to follow for a newbie like  
> myself. He uses the console to give privileges and doesn’t expand his  
> example any further. I have tried the main one but it locks me out of  
> the app completely, so Im looking for a more simple method!

* * *

agreed.

I set up the basic authentication using the methodology in AWDWR. I then  
switched it to use ruby::LDAP so users authenticate against my LDAP  
backend but the rest of the ‘User’ information comes from a ‘users’  
table.

Then I implemented the methodology from Chad’s Recipes which was a bunch  
of work because I hadn’t ever fooled with habtm before and that had its  
own learning curve but I now have it all working. I found the lack of  
view code examples in Chad’s recipe for Rights/Roles somewhat  
disconcerting but it is surmountable.

Craig
