asp.net mvc - How can I retrieve the username from a CAS server in c# MVC -


i have searched boards , while have found information regarding cas(central authentication service), have not found information pertaining how 1 go retrieving username cas server after redirected client application.

i have followed guidelines configuring web.config file according steps on github when using dotnetcasclient.dll. below web.config code: (note: had replace server names privacy reasons)

    ?xml version="1.0" encoding="utf-8"?> <!--   more information on how configure asp.net application, please visit   http://go.microsoft.com/fwlink/?linkid=301880   --> <configuration>   <!-- cas configuration -->   <configsections>         <section name="casclientconfig" type="dotnetcasclient.configuration.casclientconfiguration, dotnetcasclient" />     </configsections>    <casclientconfig casserverloginurl="https://mycasserver/login"                    casserverurlprefix="https://mycasserver"                    servername="https://myappserver"                    notauthorizedurl="~/home"                    cookiesrequiredurl="~/home/cookiesrequired"                    redirectaftervalidation="true"                    gateway="false"                    renew="false"                    singlesignout="true"                    tickettimetolerance="5000"                    ticketvalidatorname="cas20"                    serviceticketmanager="cacheserviceticketmanager"                    gatewaystatuscookiename="casgatewaystatus" />    <system.webserver>     <validation validateintegratedmodeconfiguration="false" />     <!--<modules runallmanagedmodulesforallrequests="true">-->     <modules>           <remove name="dotnetcasclient" />       <add name="dotnetcasclient" type="dotnetcasclient.casauthenticationmodule,dotnetcasclient" />     </modules>   </system.webserver>   <!-- /cas configuration -->     <connectionstrings configsource="connectionstrings.config" />     <system.data>       <dbproviderfactories>         <remove invariant="oracle.dataaccess.client" />         <!-- if should in machine.config -->         <add name="oracle data provider .net"               invariant="oracle.dataaccess.client"               description="oracle data provider .net"               type="oracle.dataaccess.client.oracleclientfactory, oracle.dataaccess, version=2.112.1.0, culture=neutral, publickeytoken=89b483f429c47342" />       </dbproviderfactories>     </system.data>    <appsettings>     <add key="webpages:version" value="3.0.0.0" />     <add key="webpages:enabled" value="false" />     <add key="clientvalidationenabled" value="true" />     <add key="unobtrusivejavascriptenabled" value="true" />       <!-- cas configuration -->     <add key="enablesimplemembership" value="false" />     <add key="autoformsauthentication" value="false" />     <!-- /cas configuration -->    </appsettings>    <system.web>   <sessionstate mode="stateserver" />   <compilation debug="true" targetframework="4.5" />   <httpruntime targetframework="4.5" />    <!-- cas configuration -->    <authentication mode="forms">         <forms loginurl="https://mycasserver/login"                 cookieless="usecookies"                path="https://myappserver" />   </authentication>    <httpmodules>   <add name="dotnetcasclient" type="dotnetcasclient.casauthenticationmodule,dotnetcasclient" />   </httpmodules>      <!-- /cas configuration -->  </system.web>     <runtime>     <assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1">       <dependentassembly>         <assemblyidentity name="newtonsoft.json" culture="neutral" publickeytoken="30ad4fe6b2a6aeed" />         <bindingredirect oldversion="0.0.0.0-6.0.0.0" newversion="6.0.0.0" />       </dependentassembly>       <dependentassembly>         <assemblyidentity name="system.web.optimization" publickeytoken="31bf3856ad364e35" />         <bindingredirect oldversion="1.0.0.0-1.1.0.0" newversion="1.1.0.0" />       </dependentassembly>       <dependentassembly>         <assemblyidentity name="webgrease" publickeytoken="31bf3856ad364e35" />         <bindingredirect oldversion="0.0.0.0-1.5.2.14234" newversion="1.5.2.14234" />       </dependentassembly>       <dependentassembly>         <assemblyidentity name="system.web.helpers" publickeytoken="31bf3856ad364e35" />         <bindingredirect oldversion="1.0.0.0-3.0.0.0" newversion="3.0.0.0" />       </dependentassembly>       <dependentassembly>         <assemblyidentity name="system.web.webpages" publickeytoken="31bf3856ad364e35" />         <bindingredirect oldversion="0.0.0.0-3.0.0.0" newversion="3.0.0.0" />       </dependentassembly>       <dependentassembly>         <assemblyidentity name="system.web.mvc" publickeytoken="31bf3856ad364e35" />         <bindingredirect oldversion="0.0.0.0-5.2.3.0" newversion="5.2.3.0" />       </dependentassembly>     </assemblybinding>   </runtime>   <system.codedom>     <compilers>       <compiler language="c#;cs;csharp"                  extension=".cs"                  type="microsoft.codedom.providers.dotnetcompilerplatform.csharpcodeprovider, microsoft.codedom.providers.dotnetcompilerplatform, version=1.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"                  warninglevel="4"                  compileroptions="/langversion:6 /nowarn:1659;1699;1701" />        <compiler language="vb;vbs;visualbasic;vbscript"                  extension=".vb"                  type="microsoft.codedom.providers.dotnetcompilerplatform.vbcodeprovider, microsoft.codedom.providers.dotnetcompilerplatform, version=1.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"                  warninglevel="4"                  compileroptions="/langversion:14 /nowarn:41008 /define:_mytype=\&quot;web\&quot; /optioninfer+" />      </compilers>   </system.codedom> </configuration> 

as per instructions regarding cas client, placed authorize tag above login page when user wants log in, instead redirected cas server login, , upon successful validation, "login" actionresult redirects user specific page.

    [authorize]     public actionresult login()     {         return redirecttoaction("index", "departments");     } 

i have tested cas implementation , can confirm works expected, lost in regards how go getting information cas server after validates user.

any appreciated, , if duplicate post apologize unable find of sort while searching myself.

it looks may matter of pulling value httpcontext.current.user.identity.name, should return value of cas username of authenticated user. there post on jasig-cas-user mailing list tipped me off this.

another mailing list post suggests other returned information may accessible through casauthentication.currentprincipal.assertion.attributes, isn't particularly well-documented on wiki.

the implication accessing data cas return demonstrated in example web application distributed code, isn't intuitive there , not documented anywhere else. (i installed using nuget, , missed out on sample application altogether. found question before found answer myself!)


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -