private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here IAuthn authn = AAFactory.getAuthn(this); // Decode the request from the GSA. // This isn't used but shows how it could be. // Since this requires version 2.0 of the .NET Framework, it's commented out for now // DecodeRequest(); Diagnose(); }
private void Page_Load(object sender, System.EventArgs e) { Common.debug("Login Request is: " + Request.RawUrl); Common.debug("before Login::entering pageload"); // create an IAutn instance IAuthn authn = AAFactory.getAuthn(this); String samlRequest = Request.Params["SAMLRequest"]; if (samlRequest == null || "".Equals(samlRequest)) { Diagnose(); return; } //Decode request and extract the AuthNRequestId AuthNRequest authNRequest = ExtractAuthNRequest(samlRequest); if (authNRequest.Id == null || authNRequest.Id.Equals("")) { Common.error("Couldn't extract AuthN Request Id from SAMLRequest"); throw new Exception("Failed to extract AuthN Request Id from SAML Request"); } Common.debug("Extracted AuthNRequestId is :" + authNRequest.Id); String subject = authn.GetUserIdentity(); // Get the user's identity (silently, if properly configured). if (subject == null || subject.Equals("")) { Common.error("Couldn't get user name, check your system setup"); throw new Exception("Failed to get user name"); } Common.debug("The user is: " + subject); // Generate a random string (artifact) that the GSA // will use later to confirm the user's identity String artifactId = Common.GenerateRandomString(); // Set an application level name/value pair for storing the user ID // and the AuthN request Id with the artifact string. // This is used later when the GSA asks to verify the artifact and obtain the // user ID (in ResolveArt.aspx.cs). SamlArtifactCacheEntry samlArtifactCacheEntry = new SamlArtifactCacheEntry(subject, authNRequest.Id); Application[Common.ARTIFACT + "_" + artifactId] = samlArtifactCacheEntry; // Get the relay state, which is the search URL to which the user // is redirected following authentication and verification String relayState = Request.Params["RelayState"]; // Look up the GSA host name (stored in Web.config) String gsa; // Encode the relay state for building the redirection URL (back to the GSA) relayState = HttpUtility.UrlEncode(relayState); gsa = Common.GSAAssertionConsumer + "?SAMLart=" + artifactId + "&RelayState=" + relayState; if (!gsa.StartsWith("http")) { gsa = "http://" + Request.Headers["Host"] + gsa; } Common.debug("before Login::redirect"); Common.debug(" to: " + gsa); // Redirect back to the GSA, which will theb contact the Artifact verifier service // with the artifact, to ensure its validity and obtain the user's ID Response.Redirect(gsa); }