Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-----------------------------------------------------------------------------
- // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
- // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
- // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
- // PARTICULAR PURPOSE.
- // Copyright (c) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- namespace MyApp.Server.Web.TestSts
- {
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.IdentityModel.Services;
- using System.Security.Claims;
- using System.Security.Principal;
- using System.Web.Security;
- using System.Web.UI;
- /// <summary>
- /// The Default Page Class
- /// </summary>
- public partial class _Default : Page
- {
- /// <summary>
- /// The page_ load.
- /// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The e.
- /// </param>
- protected void Page_Load(object sender, EventArgs e)
- {
- string action = Request.QueryString["wa"];
- if (action == "wsignout1.0")
- {
- ClaimsPrincipal principal = User as ClaimsPrincipal;
- if (principal == null)
- {
- // This is a test STS which is not tracking authenticated users
- // Create a temporary principal as a workaround for the process request action
- principal = new ClaimsPrincipal(new GenericIdentity("Temp"));
- }
- FederatedPassiveSecurityTokenServiceOperations.ProcessRequest(
- Request,
- principal,
- CustomSecurityTokenServiceConfiguration.Current.CreateSecurityTokenService(),
- Response);
- }
- if (!IsPostBack)
- {
- txtUserName.Text = "TestUser";
- }
- }
- /// <summary>
- /// The btn submit_ click.
- /// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The e.
- /// </param>
- protected void btnSubmit_Click(object sender, EventArgs e)
- {
- var claims = new List<Claim>
- {
- new Claim(ClaimsIdentity.DefaultNameClaimType, txtUserName.Text)
- };
- if (chkIsAdmin.Checked)
- {
- claims.Add(new Claim(ClaimsIdentity.DefaultRoleClaimType, "Administrator"));
- }
- var additionalRoles = txtRoles.Text;
- if (string.IsNullOrWhiteSpace(additionalRoles) == false)
- {
- var roles = additionalRoles.Split(
- new[]
- {
- Environment.NewLine
- },
- StringSplitOptions.RemoveEmptyEntries);
- foreach (string role in roles)
- {
- if (string.IsNullOrWhiteSpace(role))
- {
- continue;
- }
- claims.Add(new Claim(ClaimsIdentity.DefaultRoleClaimType, role));
- }
- }
- var identity = new ClaimsIdentity(claims, ConfigurationManager.AppSettings["IssuerName"]);
- var principal = new ClaimsPrincipal(identity);
- FederatedPassiveSecurityTokenServiceOperations.ProcessRequest(
- Request,
- principal,
- CustomSecurityTokenServiceConfiguration.Current.CreateSecurityTokenService(),
- Response);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment