Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #15 - Provide access to CAS attributes. #50

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions DotNetCasClient/Validation/Schema/Cas20/AuthenticationSuccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
#pragma warning disable 1591

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Xml;
using System.Xml.Serialization;

namespace DotNetCasClient.Validation.Schema.Cas20
Expand All @@ -41,6 +43,27 @@ public string User
set;
}

[XmlElement("attributes")]
public Object AttributesNodes { get; set; }

[XmlIgnore]
public Dictionary<String, IList<String>> Attributes
{
get
{
var result = new Dictionary<String, IList<String>>();
foreach (var element in AttributesNodes as IEnumerable<XmlNode>)
{
if (!result.ContainsKey(element.Name))
{
result[element.Name] = new List<string>();
}
result[element.Name].Add(element.InnerText);
}
return result;
}
}

[XmlElement("proxyGrantingTicket")]
public string ProxyGrantingTicket
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ protected override ICasPrincipal ParseResponseFromServer(string response, string

if (authSuccessResponse.Proxies != null && authSuccessResponse.Proxies.Length > 0)
{
return new CasPrincipal(new Assertion(authSuccessResponse.User), proxyGrantingTicketIou, authSuccessResponse.Proxies);
return new CasPrincipal(new Assertion(authSuccessResponse.User, authSuccessResponse.Attributes), proxyGrantingTicketIou, authSuccessResponse.Proxies);
}
else
{
return new CasPrincipal(new Assertion(authSuccessResponse.User), proxyGrantingTicketIou);
return new CasPrincipal(new Assertion(authSuccessResponse.User, authSuccessResponse.Attributes), proxyGrantingTicketIou);
}
}

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ Configure the ASP.NET Forms authentication section, `<forms>`, so that it points
### Configure Authorization
Configure authorization roles and resources using the familiar ASP.NET directives. We recommend the user of a role provider that queries a role store given the principal name returned from the CAS server. There is not support at present for extracting authorization data from the attributes released from CAS via the SAML protocol.

### CAS attributes

I added a hack so that you can access your CAS attributes. E.g., we have an attribute that's called `ad_nummer`, and I use it like this:

var principal = System.Web.HttpContext.Current.User as CasPrincipal;
myAdNr = int.Parse(principal.Assertion.Attributes["cas:ad_nummer"].First());

### Configure Diagnostic Tracing (optional)
`CasAuthenticationModule` uses the .NET Framework `System.Diagnostics` tracing facility for internal logging. Enabling the internal trace switches should be the first step taken to troubleshoot integration problems.

Expand Down