Revert "signinc"

This reverts commit 5c66212388.
This commit is contained in:
Siwat Sirichai 2025-06-09 00:20:38 +07:00
parent 5c66212388
commit 518c7df120
5 changed files with 17 additions and 166 deletions

View file

@ -1,13 +0,0 @@
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="SamlCallback.aspx.vb" Inherits="Security.SamlCallback" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>SAML Authentication</title>
</head>
<body>
<form id="form1" runat="server">
<div id="result" runat="server"></div>
</form>
</body>
</html>

View file

@ -1,121 +0,0 @@
Imports System.Web
Imports System.Web.UI
Imports BaseClasses
Imports BaseClasses.Configuration
Imports BaseClasses.Utils
Namespace Security
Partial Public Class SamlCallback
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)
Dim samlResponse = Request.Form("SAMLResponse")
If String.IsNullOrEmpty(samlResponse) Then
RedirectToSignInWithError("No SAML Response received")
Return
End If
' Certificate for validating SAML response
Dim cert As String = _
"-----BEGIN CERTIFICATE-----" & vbCrLf & _
"MIIE6DCCAtCgAwIBAgIQOQaY6KUdPItB52hpOsIBvjANBgkqhkiG9w0BAQsFADAw" & vbCrLf & _
"MS4wLAYDVQQDEyVBREZTIFNpZ25pbmcgLSBzc28uc2F0aXRtLmNodWxhLmFjLnRo" & vbCrLf & _
"MB4XDTI1MDQwNjEyNTQxNFoXDTI2MDQwNjEyNTQxNFowMDEuMCwGA1UEAxMlQURG" & vbCrLf & _
"UyBTaWduaW5nIC0gc3NvLnNhdGl0bS5jaHVsYS5hYy50aDCCAiIwDQYJKoZIhvcN" & vbCrLf & _
"AQEBBQADggIPADCCAgoCggIBAMlu6kjF9Ghsr9Z6+AIYRjHTx4OL6fROrCzq26/h" & vbCrLf & _
"YBfsrsL5QeJlWtYhRsbrW3wAFaQukNYal5LRJx8BXXlngIDIfoIEixT62BqFC2XO" & vbCrLf & _
"Ju7Rq+p1ei2WZb06V0It8ohmZVPqsDPzygjBblta27DBGQ8qQ4upGVTwOIBRisMj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rTTb" & vbCrLf & _
"ilCJsW3umI26/eFZAfZIA2n7/FKDcDXFCJOM1UV+09pZ12p0TAaA3nyA2TbdI+PM" & vbCrLf & _
"GtvvEK2PU+tdU64uAlOOaldk52dIuR7kOVBk53Gf3K2wY2U/oovLrlXLHb8NJD49" & vbCrLf & _
"Po6XT3w6WL+okyr7FgdmAHTNpTnthXG0pyN4KUFEAK9HWXdGRWUgFX4yBOjmPN1N" & vbCrLf & _
"Vx7G3klMd+ccQUU80lxDKQUbjhcWLloWNlg6w2SKk4Ku7/f8HmPkqppvFow+ytWm" & vbCrLf & _
"0abcCjptoUrFR1BCM86CIDCo9bEWIyWv+SHr2AvlQ8D0Z8aQRr6M73NN1PNWruPf" & vbCrLf & _
"bpD2ekhB2vZ9R2ij" & vbCrLf & _
"-----END CERTIFICATE-----"
Try
Dim resp = New SamlHelper.Response(cert, samlResponse)
If resp.IsValid() Then
' Extract user information from SAML response
Dim email = resp.GetEmail()
Dim firstName = resp.GetFirstName()
Dim lastName = resp.GetLastName()
' Authenticate user in the application
If AuthenticateSamlUser(email, firstName, lastName) Then
' Redirect to success page or back to original requested page
RedirectOnSuccess()
Else
RedirectToSignInWithError("User authentication failed")
End If
Else
RedirectToSignInWithError("Invalid SAML Response")
End If
Catch ex As Exception
RedirectToSignInWithError("Error processing SAML response: " & ex.Message)
End Try
End Sub
Private Function AuthenticateSamlUser(email As String, firstName As String, lastName As String) As Boolean
Try
' Create a base application page to access security methods
Dim basePage As BaseApplicationPage = DirectCast(Me.Page, BaseApplicationPage)
Dim errMessage As String = ""
' Use email as username for authentication
' This assumes your user table uses email as the primary identifier
Dim success As Boolean = basePage.CurrentSecurity.SetLoginInfo(email, "", errMessage)
If success Then
' User authenticated successfully
Return True
Else
' Log the authentication failure
System.Diagnostics.Debug.WriteLine("SAML Authentication failed: " & errMessage)
Return False
End If
Catch ex As Exception
System.Diagnostics.Debug.WriteLine("SAML Authentication error: " & ex.Message)
Return False
End Try
End Function
Private Sub RedirectOnSuccess()
' Check if there's a return URL in session or query string
Dim returnUrl As String = Request.QueryString("ReturnUrl")
If String.IsNullOrEmpty(returnUrl) Then
returnUrl = ApplicationSettings.Current.DefaultPageUrl()
End If
If String.IsNullOrEmpty(returnUrl) Then
returnUrl = "~/Default.aspx"
End If
Response.Redirect(returnUrl)
End Sub
Private Sub RedirectToSignInWithError(message As String)
Dim signInUrl As String = ApplicationSettings.Current.SignInPageUrl()
If String.IsNullOrEmpty(signInUrl) Then
signInUrl = "~/Security/SignIn.aspx"
End If
signInUrl &= "?message=" & Server.UrlEncode(message)
Response.Redirect(signInUrl)
End Sub
End Class
End Namespace

View file

@ -6,27 +6,15 @@
<%@ Register Tagprefix="BaseClasses" Namespace="BaseClasses.Web.UI.WebControls" Assembly="BaseClasses" %><asp:Content id="Content" ContentPlaceHolderID="PageContent" runat="server"> <%@ Register Tagprefix="BaseClasses" Namespace="BaseClasses.Web.UI.WebControls" Assembly="BaseClasses" %><asp:Content id="Content" ContentPlaceHolderID="PageContent" runat="server">
<a id="StartOfPageContent"></a> <a id="StartOfPageContent"></a>
<table class="dv" cellpadding="0" cellspacing="0" border="0"><tr><td class="dh"><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td class="dhel"><img src="../Images/space.gif" alt="" /></td><td class="dheci" valign="middle"><asp:CollapsiblePanelExtender id="SignInCPExtender" runat="server" TargetControlid="SignInCollapsibleRegion" ExpandControlID="SignInToggleIcon" CollapseControlID="SignInToggleIcon" ImageControlID="SignInToggleIcon" ExpandedImage="../images/icon_panelcollapse.gif" CollapsedImage="../images/icon_panelexpand.gif" SuppressPostBack="true" /> <asp:ImageButton id="SignInToggleIcon" runat="server" ToolTip="<%# GetResourceValue(&quot;Btn:ExpandCollapse&quot;, &quot;Persons&quot;) %>" causesvalidation="False" imageurl="../images/icon_panelcollapse.gif" /> <table class="dv" cellpadding="0" cellspacing="0" border="0"><tr><td class="dh"><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td class="dhel"><img src="../Images/space.gif" alt="" /></td><td class="dheci" valign="middle"><asp:CollapsiblePanelExtender id="SignInCPExtender" runat="server" TargetControlid="SignInCollapsibleRegion" ExpandControlID="SignInToggleIcon" CollapseControlID="SignInToggleIcon" ImageControlID="SignInToggleIcon" ExpandedImage="../images/icon_panelcollapse.gif" CollapsedImage="../images/icon_panelexpand.gif" SuppressPostBack="true" />
<asp:ImageButton id="SignInToggleIcon" runat="server" ToolTip="<%# GetResourceValue(&quot;Btn:ExpandCollapse&quot;, &quot;Persons&quot;) %>" causesvalidation="False" imageurl="../images/icon_panelcollapse.gif" />
</td><td class="dhb"><table cellpadding="0" cellspacing="0" border="0"><tr><td class="dht" valign="middle"><asp:Literal runat="server" id="DialogTitle" Text="&lt;%# GetResourceValue(&quot;Txt:SignIn&quot;, &quot;Persons&quot;) %>"> </asp:Literal></td></tr></table> </td><td class="dhb"><table cellpadding="0" cellspacing="0" border="0"><tr><td class="dht" valign="middle"><asp:Literal runat="server" id="DialogTitle" Text="&lt;%# GetResourceValue(&quot;Txt:SignIn&quot;, &quot;Persons&quot;) %>"> </asp:Literal></td></tr></table>
</td><td class="dher"><img src="../Images/space.gif" alt="" /></td></tr></table> </td><td class="dher"><img src="../Images/space.gif" alt="" /></td></tr></table>
</td></tr><tr><td class="dBody"><%= SystemUtils.GenerateEnterKeyCaptureBeginTag(FindControlRecursively("OKButton")) %><asp:panel id="SignInCollapsibleRegion" runat="server"><table cellpadding="0" cellspacing="0" border="0" width="325"><tr><td style="padding-left:8px; padding-right:8px; padding-top:4px"><table cellpadding="1" cellspacing="1" border="0"><tr><td colspan="4" style="height: 5px;"></td></tr><tr><td colspan="4"><asp:Label runat="server" id="LoginMessage"> </asp:Label></td></tr><tr><td colspan="4" style="height: 5px;"></td></tr><tr><td colspan="4" style="text-align: center; padding: 20px;"> <p>This application uses Single Sign-On (SSO) authentication through ADFS.</p> </td></tr><tr><td class="dBody"><%= SystemUtils.GenerateEnterKeyCaptureBeginTag(FindControlRecursively("OKButton")) %><asp:panel id="SignInCollapsibleRegion" runat="server"><table cellpadding="0" cellspacing="0" border="0" width="325"><tr><td style="padding-left:8px; padding-right:8px; padding-top:4px"><table cellpadding="1" cellspacing="1" border="0"><tr><td colspan="4" style="height: 5px;"></td></tr><tr><td colspan="4"><asp:Label runat="server" id="LoginMessage"> </asp:Label></td></tr><tr><td colspan="4" style="height: 5px;"></td></tr><tr><td class="field_label"><asp:Label runat="server" id="UserNameLabel" Text="&lt;%# GetResourceValue(&quot;Txt:UserName&quot;, &quot;Persons&quot;) %>"> </asp:Label></td><td class="field_value"><asp:TextBox runat="server" id="UserName" columns="50" commandname="TextBoxUserName_Command" cssclass="field_input"> </asp:TextBox>
<p>Click the button below to authenticate with your organizational credentials.</p> <asp:RequiredFieldValidator runat="server" id="UserNameRequiredFieldValidator" ControlToValidate="UserName" ErrorMessage="&lt;%# GetResourceValue(&quot;Val:ValueIsRequired&quot;, &quot;Persons&quot;).Replace(&quot;{FieldName}&quot;, &quot;UserName&quot;) %>" display="None" enabled="True"> </asp:RequiredFieldValidator></td><td><asp:CheckBox runat="server" id="RememberUserName" commandname="CheckBoxUN_Command" postback="True"> </asp:CheckBox></td><td class="field_label"><asp:Label runat="server" id="RememberUserNameLabel" Text="&lt;%# GetResourceValue(&quot;Txt:RememberUN&quot;, &quot;Persons&quot;) %>"> </asp:Label></td></tr><tr><td colspan="4" style="height: 5px;"></td></tr><tr><td class="field_label"><asp:Label runat="server" id="PasswordLabel" Text="&lt;%# GetResourceValue(&quot;Txt:Password&quot;, &quot;Persons&quot;) %>"> </asp:Label></td><td class="field_value"><asp:TextBox runat="server" id="Password" columns="50" commandname="TextBoxPassword_Command" cssclass="field_input" textmode="Password"> </asp:TextBox>
<asp:RequiredFieldValidator runat="server" id="PasswordRequiredFieldValidator" ControlToValidate="Password" ErrorMessage="&lt;%# GetResourceValue(&quot;Val:ValueIsRequired&quot;, &quot;Persons&quot;).Replace(&quot;{FieldName}&quot;, &quot;Password&quot;) %>" display="None" enabled="True"> </asp:RequiredFieldValidator></td><td><asp:CheckBox runat="server" id="RememberPassword" commandname="CheckBoxPass_Command" postback="True"> </asp:CheckBox></td><td class="field_label"><asp:Label runat="server" id="RememberPasswordLabel" Text="&lt;%# GetResourceValue(&quot;Txt:RememberPassword&quot;, &quot;Persons&quot;) %>"> </asp:Label></td></tr><tr><td colspan="4" style="height: 5px;"></td></tr><tr><td></td><td class="fyp_link"><asp:LinkButton runat="server" id="EmailLinkButton" causesvalidation="False" commandname="ForgotUser" consumers="page" text="&lt;%# GetResourceValue(&quot;Txt:ForgotPassword&quot;, &quot;Persons&quot;) %>">
<!-- Hidden controls to maintain compatibility with existing framework --> </asp:LinkButton></td><td><asp:CheckBox runat="server" id="AutomaticallySignIn" commandname="CheckBoxAutoLogin_Command" postback="True"> </asp:CheckBox></td><td class="field_label"><asp:Label runat="server" id="AutomaticallySignInLabel" Text="&lt;%# GetResourceValue(&quot;Txt:AutoLogin&quot;, &quot;Persons&quot;) %>"> </asp:Label></td></tr><tr><td colspan="4" style="height: 5px;"></td></tr><tr><td style="height: 5px;"></td><td style="height: 5px;" colspan="3"><asp:Label runat="server" id="PasswordMessage"> </asp:Label></td></tr></table>
<asp:TextBox runat="server" id="UserName" style="display:none;"> </asp:TextBox> </td></tr><tr><td><table cellpadding="0" cellspacing="0" border="0" style="padding-top:10px; padding-bottom:5px;" align="center"><tr><td><Persons:ThemeButton runat="server" id="OKButton" button-causesvalidation="True" button-commandname="Login" button-text="&lt;%# GetResourceValue(&quot;Btn:OK&quot;, &quot;Persons&quot;) %>" button-tooltip="&lt;%# GetResourceValue(&quot;Btn:OK&quot;, &quot;Persons&quot;) %>"></Persons:ThemeButton></td><td><Persons:ThemeButton runat="server" id="CancelButton" button-causesvalidation="False" button-commandname="Redirect" button-text="&lt;%# GetResourceValue(&quot;Btn:Cancel&quot;, &quot;Persons&quot;) %>" button-tooltip="&lt;%# GetResourceValue(&quot;Btn:Cancel&quot;, &quot;Persons&quot;) %>"></Persons:ThemeButton></td></tr></table>
<asp:TextBox runat="server" id="Password" style="display:none;" textmode="Password"> </asp:TextBox>
<asp:CheckBox runat="server" id="RememberUserName" style="display:none;"> </asp:CheckBox>
<asp:CheckBox runat="server" id="RememberPassword" style="display:none;"> </asp:CheckBox>
<asp:CheckBox runat="server" id="AutomaticallySignIn" style="display:none;"> </asp:CheckBox>
<asp:Label runat="server" id="UserNameLabel" style="display:none;"> </asp:Label>
<asp:Label runat="server" id="PasswordLabel" style="display:none;"> </asp:Label>
<asp:Label runat="server" id="RememberUserNameLabel" style="display:none;"> </asp:Label>
<asp:Label runat="server" id="RememberPasswordLabel" style="display:none;"> </asp:Label>
<asp:Label runat="server" id="AutomaticallySignInLabel" style="display:none;"> </asp:Label>
<asp:Label runat="server" id="PasswordMessage" style="display:none;"> </asp:Label>
<asp:LinkButton runat="server" id="EmailLinkButton" style="display:none;"> </asp:LinkButton>
</td></tr><tr><td colspan="4" style="height: 5px;"></td></tr></table>
</td></tr><tr><td><table cellpadding="0" cellspacing="0" border="0" style="padding-top:10px; padding-bottom:5px;" align="center"><tr><td> <Persons:ThemeButton runat="server" id="OKButton" button-causesvalidation="False" button-commandname="Login" button-text="Login with ADFS" button-tooltip="Login with ADFS Single Sign-On"></Persons:ThemeButton></td><td><Persons:ThemeButton runat="server" id="CancelButton" button-causesvalidation="False" button-commandname="Redirect" button-text="&lt;%# GetResourceValue(&quot;Btn:Cancel&quot;, &quot;Persons&quot;) %>" button-tooltip="&lt;%# GetResourceValue(&quot;Btn:Cancel&quot;, &quot;Persons&quot;) %>"></Persons:ThemeButton></td></tr></table>
</td></tr></table></asp:panel> </td></tr></table></asp:panel>
<%= SystemUtils.GenerateEnterKeyCaptureEndTag(FindControlRecursively("OKButton")) %></td></tr></table><div id="detailPopup" class="detailRolloverPopup" onmouseout="detailRolloverPopupClose();" onmouseover="clearTimeout(gPopupTimer);"></div> <%= SystemUtils.GenerateEnterKeyCaptureEndTag(FindControlRecursively("OKButton")) %></td></tr></table><div id="detailPopup" class="detailRolloverPopup" onmouseout="detailRolloverPopupClose();" onmouseover="clearTimeout(gPopupTimer);"></div>
<asp:ValidationSummary id="ValidationSummary1" ShowMessageBox="true" ShowSummary="false" runat="server"></asp:ValidationSummary> <asp:ValidationSummary id="ValidationSummary1" ShowMessageBox="true" ShowSummary="false" runat="server"></asp:ValidationSummary>

View file

@ -12,7 +12,6 @@ Imports System.Collections
Imports System.Collections.Generic Imports System.Collections.Generic
Imports System.ComponentModel Imports System.ComponentModel
Imports System.Web
Imports System.Web.UI Imports System.Web.UI
Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls
Imports BaseClasses Imports BaseClasses
@ -245,16 +244,11 @@ Partial Public Class SignIn
CancelButton_Click_Base(sender, args) CancelButton_Click_Base(sender, args)
' NOTE: If the Base function redirects to another page, any code here will not be executed. ' NOTE: If the Base function redirects to another page, any code here will not be executed.
End Sub End Sub
Public Sub OKButton_Click(ByVal sender As Object, ByVal args As EventArgs) Public Sub OKButton_Click(ByVal sender As Object, ByVal args As EventArgs)
' Click handler for OKButton. ' Click handler for OKButton.
' Redirect to SAML authentication instead of traditional login ' Customize by adding code before the call or replace the call to the Base function with your own code.
Try OKButton_Click_Base(sender, args)
Dim samlRequest As String = SamlHelper.CreateAuthRequest("https://cudreg.com", Request.Url.GetLeftPart(UriPartial.Authority) & "/Security/SamlCallback.aspx")
Dim redirectUrl As String = "https://sso.satitm.chula.ac.th/adfs/ls?SAMLRequest=" & HttpUtility.UrlEncode(samlRequest)
Response.Redirect(redirectUrl)
Catch ex As Exception
Me.ProcessLoginFailed("SAML Authentication Error: " & ex.Message, "")
End Try
' NOTE: If the Base function redirects to another page, any code here will not be executed. ' NOTE: If the Base function redirects to another page, any code here will not be executed.
End Sub End Sub

View file

@ -132,13 +132,16 @@
<Attribute> <Attribute>
<Name>Button-CommandName</Name> <Name>Button-CommandName</Name>
<Value>Login</Value> <Value>Login</Value>
</Attribute> <Attribute> </Attribute>
<Attribute>
<Name>Button-Text</Name> <Name>Button-Text</Name>
<Value>Login with ADFS</Value> <Value>Btn:OK</Value>
<Type>ResourceReference</Type>
</Attribute> </Attribute>
<Attribute> <Attribute>
<Name>Button-ToolTip</Name> <Name>Button-ToolTip</Name>
<Value>Login with ADFS Single Sign-On</Value> <Value>Btn:OK</Value>
<Type>ResourceReference</Type>
</Attribute> </Attribute>
</PassthroughAttributes> </PassthroughAttributes>
</ContainedComponent> </ContainedComponent>