RedgoodBreaker
RedgoodBreaker

Reputation: 310

Forms Authentication with JASIG CAS Custom operation after logon

It's my First question here so i apologize for my english :)

we are building MVC 4 application with authentication made by Jasig CAS SSO.

It works pretty good but i need to do custom action after authentication of user.

Steps should look like:

  1. User goes to our site to HomeController which is decorated by AuthorizeAttribute
  2. Controller redirects user to CAS
  3. User pass his username and password
  4. CAS properly authenticates user and redirects to our site
  5. (here goes custom action) After logon we build up Session (get user parameters from DB and put them in to chache and etc)

action 5. is run only once after successful logon! every next request skips this step.

I have read documentation of CAS and MSDN about forms authentication but i couldn't any information.

I found that i could extend AuthorizeAttribute and override AuthorizeCore method but it is ran every request.

thanks for help

Upvotes: 0

Views: 360

Answers (1)

RedgoodBreaker
RedgoodBreaker

Reputation: 310

I found answer by myself. Maybe there are better resolutions but this one makes what i wanted.

To make some custom action after logon in Jasig CAS you need to implement

protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)

in Global.asax

sample code:

protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            //must check if user is authenticated (this method can be called before authentication) 
            if (Context.User.Identity.IsAuthenticated && Context.Session != null && Context.Session["IsLogged"] == null)
            {
               Context.Session.Add("YourKey", YourData);
               Context.Session.Add("IsLogged", true);
            }

        }

Probably the same approach could be used in standard forms authentication if needed

Upvotes: 0

Related Questions