trying to cassify Dotnetnuke i wrote an ugly code to do auth on Dotnetnuke 5.x. I can't used incubating cas client, becouse my lack of .net knowledge.
DNN auth provider are a special module, that has some ascx. I used only Login.ascx and i want to share with you.
---------- Login.ascx code --------------------
<%@ Control language="vb" Inherits="DotNetNuke.Modules.Admin.CAS.Authentication.Login" CodeFile="Login.ascx.vb" AutoEventWireup="false" Explicit="True" %>
<%@ Register TagPrefix="dnn" Assembly="DotNetNuke" Namespace="DotNetNuke.UI.WebControls"%>
<%@ Register TagPrefix="dnn" TagName="Label" Src="" %>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<dl id="CasLogin">
<dt><dnn:label id="plUsername" controlname="txtUsername" runat="server" resourcekey="Username" /></dt>
<dd><asp:textbox id="txtUsername" columns="9" width="150" cssclass="NormalTextBox" runat="server" /></dd>
<dt><dnn:label id="plPassword" controlname="txtPassword" runat="server" resourcekey="Password" /></dt>
<dd><asp:textbox id="txtPassword" columns="9" width="150" textmode="Password" cssclass="NormalTextBox" runat="server" /></dd>
<dt id="rowVerification1" runat="server" visible="false"><dnn:label id="plVerification" controlname="txtVerification" runat="server"/></dt>
<dd id="rowVerification2" runat="server" visible="false"><asp:textbox id="txtVerification" runat="server" visible="false" /></dd>
</dl>
<!--
<div id="trCaptcha1" runat="server">
<dnn:label id="plCaptcha" controlname="ctlCaptcha" runat="server" resourcekey="Captcha" />
</div>
<div id="trCaptcha2" runat="server">
<dnn:captchacontrol id="ctlCaptcha" captchawidth="130" captchaheight="40" cssclass="Normal" runat="server" errorstyle-cssclass="NormalRed" textboxstyle-cssclass="NormalTextBox" />
</div>
-->
<asp:button id="cmdLogin" resourcekey="cmdLogin" cssclass="StandardButton" text="Login" runat="server" />
---------------------------------------------------------------------
This are only Page_load and Page_preRender, that make auth work.
I used an ugly code to get cas netID, but i get trouble on reading cas resonse as XML
--------------Login.ascx.vb ---------------------------------------
Imports DNNUserController = DotNetNuke.Entities.Users.UserController
Imports DNNUserInfo = DotNetNuke.Entities.Users.UserInfo
Namespace DotNetNuke.Modules.Admin.CAS.Authentication
Partial Class Login
Inherits AuthenticationLoginBase
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DotNetNuke.UI.Utilities.ClientAPI.RegisterKeyCapture(Me.Parent, Me.cmdLogin, Asc(vbCr))
'captcha disabled
'trCaptcha1.Visible = UseCaptcha
'trCaptcha2.Visible = UseCaptcha
Dim netId As String = ""
Dim objUserInfo As DNNUserInfo
Dim casauth As Boolean = False
'Congig in web.config or dotnetcasclient?
Dim casServerLoginUrl As String = "http://intranet.enasco.it:8080/cas/login"
Dim serverName = "http://localhost:3404/dnn523/"
'Set service url for CAS callback
'Dim service As String = Request.Url.GetLeftPart(UriPartial.Path)
Dim casServerUrlPrefix As String = "http://intranet.enasco.it:8080/cas/"
Dim dnnLoginPageRedirect As String = "login.aspx"
'Get ticket from querystring
Dim tkt As String = Context.Request.QueryString("ticket")
Try
'Check if ticket exist
If (Not tkt Is Nothing) Then
'Need of an https/SSL stream reader
'used a non ssl cas instance
'ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
Dim validateurl As String = casServerUrlPrefix + "serviceValidate?" + "ticket=" + tkt + "&" + "service=" + serverName + dnnLoginPageRedirect
'get cas response
Dim Reader As New StreamReader(New WebClient().OpenRead(validateurl))
Dim resp As String = Reader.ReadToEnd()
'ugly methot to get netid from cas
'-----------------------------------------------
Dim s As String = resp.Replace(vbTab, "")
Dim arrS As String() = s.Split(vbLf)
Dim username, mystringu As String
If arrS(1).IndexOf("authenticationSuccess") > 0 Then
username = arrS(2)
mystringu = username.Substring(10, arrS(2).IndexOf("</cas:user>") - 10)
netId = mystringu
casauth = True
Else
casauth = False
End If
'-----------------------------------------------
If casauth = False Then
'notify some message
Else
'do a DotNetNuke login
'FormsAuthentication.RedirectFromLoginPage(netId, False)
objUserInfo = DNNUserController.GetUserByName(PortalId, netId)
If Not objUserInfo Is Nothing Then
DNNUserController.UserLogin(PortalId, objUserInfo, PortalSettings.PortalName, Request.UserHostAddress, True)
'try to redirect to prevento user on click login button
'but it seems doesn't work
Response.Redirect(serverName)
End If
End If
Else
'page first call, or non authenticated on cas
If (tkt Is Nothing) Then
Dim redir As String = casServerLoginUrl + "?" + "service=" + serverName + dnnLoginPageRedirect
Response.Redirect(redir)
End If
End If
Catch ex As Exception
End Try
End Sub
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
' txtPassword.Attributes.Add("value", txtPassword.Text)
' 'custom styles
' 'CType(Me.Page, CDefault).AddStyleSheet("CasAuthStyles", Me.ControlPath & "CasAuth.css", False)
txtUsername.Visible = False
txtPassword.Visible = False
End Sub
End Class
End Namespace
----------------------------------------
It's all. If someone want to leave me a feedback... are welcome
[md]
-------------------------------------------------------------------------------
Valore legale alle tue mail
InterfreePEC - la tua Posta Elettronica Certificata
http://pec.interfree.it
-------------------------------------------------------------------------------
--
You are currently subscribed to [email protected] as: [email protected]
To unsubscribe, change settings or access archives, see http://www.ja-sig.org/wiki/display/JSG/cas-dev
