asp net 2.0 security membership and role management - Pdf 13


Professional
ASP.NET 2.0 Security,
Membership, and Role
Management
Stefan Schackow
01_596985 ffirs.qxp 12/14/05 7:45 PM Page i
Professional
ASP.NET 2.0 Security,
Membership, and Role
Management
Stefan Schackow
01_596985 ffirs.qxp 12/14/05 7:45 PM Page i
Professional ASP.NET 2.0 Security, Membership, and
Role Management
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2006 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN-13: 978-0-7645-9698-8
ISBN-10: 0-7645-9698-5
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
1MA/QV/QR/QW/IN
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by
any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted
under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permis-
sion of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright

be available in electronic books.
01_596985 ffirs.qxp 12/14/05 7:45 PM Page ii
Credits
Senior Acquisitions Editor
Jim Minatel
Development Editor
Sydney Jones
Technical Editors
Jeffrey Palermo
Scott Spradin
Production Editor
Pamela Hanley
Copy Editor
Foxxe Editorial Services
Editorial Manager
Mary Beth Wakefield
Vice President & Executive Group Publisher
Richard Swadley
Vice President and Publisher
Joseph B. Wikert
Graphics and Production Specialists
Denny Hager
Alicia B. South
Quality Control Technicians
Amanda Briggs
John Greenough
Joe Niesen
Proofreading and Indexing
TECHBOOKS Production Services
01_596985 ffirs.qxp 12/14/05 7:45 PM Page iii

Who Is This Book For? xix
What Does This Book Cover? xix
What You Need to Run the Examples xxi
Conventions xxii
Customer Support xxiii
How to Download the Sample Code for the Book xxiii
Errata xxiii
Email Support xxiii
p2p.wrox.com xxiv
Chapter 1: Initial Phases of a Web Request 1
IIS Request Handling 2
Http.sys 3
aspnet_filter.dll 5
Processing Headers 6
Blocking Restricted Directories 8
Dynamic versus Static Content 9
MIME Type Mappings 9
ISAPI Extension Mappings 10
Wildcard Application Mappings 13
aspnet_isapi.dll 14
Starting Up an Application Domain 15
First Request Initialization 23
Summary 28
Chapter 2: Security Processing for Each Request 31
IIS Per-Request Security 32
ASP.NET Per-Request Security 33
Where Is the Security Identity for a Request? 34
Establishing the Operating System Thread Identity 38
The ASP.NET Processing Pipeline 41
Thread Identity and Asynchronous Pipeline Events 43

Reading and Writing Configuration 153
Permissions Required for Reading Local Configuration 155
Permissions Required for Writing Local Configuration 157
Permissions Required for Remote Editing 159
Using Configuration in Partial Trust 161
The requirePermission Attribute 163
Demanding Permissions from a Configuration Class 165
FileIOPermission and the Design-Time API 166
Protected Configuration 166
What Can’t You Protect? 168
Selecting a Protected Configuration Provider 169
Defining Protected Configuration Providers 172
DpapiProtectedConfigurationProvider 172
02_596985 ftoc.qxp 12/14/05 7:45 PM Page xii
xiii
Contents
RsaProtectedConfigurationProvider 175
Aspnet_regiis Options 181
Using Protected Configuration Providers in Partial Trust 182
Redirecting Configuration with a Custom Provider 184
Summary 190
Chapter 5: Forms Authentication 191
Quick Recap on Forms Authentication 192
Understanding Persistent Tickets 192
How Forms Authentication Enforces Expiration 194
Securing the Ticket on the Wire 198
How Secure Are Signed Tickets? 198
New Encryption Options in ASP.NET 2.0 201
Setting Cookie-Specific Security Options 204
requireSSL 204

Passing Username to ASP 276
Authorizing Classic ASP with ASP.NET 276
Passing User Roles to Classic ASP 277
Safely Passing Sensitive Data to Classic ASP 278
Full Code Listing of the Hash Helper 284
Summary 285
Chapter 7: Session State 287
Does Session State Equal Logon Session? 287
Session Data Partitioning 290
Cookie-Based Sessions 291
Cookie Sharing across Applications 292
Protecting Session Cookies 293
Session ID Reuse 294
Cookieless Sessions 294
Session ID Reuse and Expired Sessions 296
Session Denial of Service Attacks 297
Trust Levels and Session State 300
Serialization and Deserialization Requirements 302
Database Security for SQL Session State 304
Security Options for the OOP State Server 306
Summary 307
Chapter 8: Security for Pages and Compilation 309
Request Validation and Viewstate Protection 309
Request Validation 310
Securing viewstate 311
Page Compilation 314
Fraudulent Postbacks 318
Site Navigation Security 322
Summary 327
Chapter 9: The Provider Model 329

General Error Handling Approaches 393
The “Primary Key” for Membership 394
Supported Environments 396
Using Custom Hash Algorithms 399
Summary 402
Chapter 11: SqlMembershipProvider 403
Understanding the Common Database Schema 404
Storing Application Name 404
The Common Users Table 405
Versioning Provider Schemas 408
Querying Common Tables with Views 410
Linking Custom Features to User Records 410
Why Are There Calls to the LOWER Function? 414
The Membership Database Schema 415
SQL Server–Specific Provider Configuration Options 418
Working with SQL Server Express 419
02_596985 ftoc.qxp 12/14/05 7:45 PM Page xv
xvi
Contents
Sharing Issues with SSE 424
Changing the SSE Connection String 425
Database Security 426
Database Schemas and the DBO User 428
Changing Password Formats 430
Custom Password Generation 432
Implementing Custom Encryption 435
Enforcing Custom Password Strength Rules 437
Hooking the ValidatePassword Event 439
Implementing Password History 440
Account Lockouts 451

Contents
PostAuthenticateRequest 531
EndRequest 534
Role Cache Cookie Settings and Behavior 535
Working with Multiple Providers during GetRoles 537
RoleProvider 542
Basic Configuration 544
Authorization Methods 544
Managing Roles and Role Associations 544
WindowsTokenRoleProvider 546
Summary 551
Chapter 14: SqlRoleProvider 553
SqlRoleProvider Database Schema 553
SQL Server–Specific Provider Configuration Options 555
Transaction Behavior 556
Provider Security 556
Trust-Level Requirements and Configuration 557
Database Security 563
Working with Windows Authentication 563
Running with a Limited Set of Roles 565
Authorizing with Roles in the Data Layer 570
Supporting Dynamic Applications 571
Summary 572
Chapter 15: AuthorizationStoreRoleProvider 573
Provider Design 573
Supported Functionality 576
Using a File-Based Policy Store 578
Using a Directory-Based Policy Store 580
Working in Partial Trust 589
Using Membership and Role Manager Together 592

will be immediately useful to you. After you have read through these topics, you will definitely have a
thorough understanding of why ASP.NET security works the way it does, and you will have insights
into just how far you can “stretch” ASP.NET 2.0 to match your application’s security requirements.
What Does This Book Cover?
The subject of ASP.NET security can refer to a lot of different concepts: security features, best coding
practices, lockdown procedures, and so on. This book addresses ASP.NET security features from the
developer’s point of view. It gives you detailed information on every major area of ASP.NET security
03_596985 flast.qxp 12/14/05 7:45 PM Page xix
xx
Introduction
you will encounter while developing web applications. And it shows you how you can extend or modify
these features.
❑ Chapter 1 walks you through the internal processing ASP.NET performs when it starts up an
application domain. You will see how control passes from IIS to ASP.NET, and you will learn
about the special processing ASP.NET performs during the very first request to an app domain.
❑ Chapter 2 gives you a detailed walk through of the security processing ASP.NET performs in
its pipeline for each HTTP request. You will see how the default authentication and authoriza-
tion modules work, as well as how ASP.NET blocks access to content with special handlers.
This chapter also describes subtleties in how request identity works with ASP.NET 2.0’s asyn-
chronous pipeline events and asynchronous page model.
❑ Chapter 3 describes what an ASP.NET trust level is and how ASP.NET trust levels work to pro-
vide more secure environments for running web applications. The chapter goes into detail on
how you can customize trust levels and how to write privileged code that works in partial trust
applications.
❑ Chapter 4 covers the new security features in the 2.0 Framework’s configuration system. It dis-
cusses new configuration options for locking down configuration sections as well as protecting
configuration sections from prying eyes. It also discusses how ASP.NET trust levels and config-
uration system security work together.
❑ Chapter 5 explains new ASP.NET 2.0 features for forms authentication. You will learn about the
new integrated cookieless support and the new support forms authentication has for passing

its functionality onto Active Directory, and you will see how to set up both Active Directory
and Active Directory Application Mode servers to work with the provider.
❑ Chapter 13 describes the new Role Manager feature that provides built-in authorization support
for ASP.NET 2.0. You will learn about the core classes in Role Manager. The chapter also details
how the
RoleManagerModule is able to automatically set up a principle for downstream autho-
rization and how the module and Role Manager’s caching work hand in hand. Chapter 13 also
covers the
WindowsTokenRoleProvider, which is one of the providers that ships with Role
Manager.
❑ Chapter 14 discusses the
SqlRoleProvider and its underlying SQL schema. You will learn
about using the provider in conjunction with Windows authentication, extending the provider
to support custom authorization logic, and how you can use its database schema for data layer
authorization logic. Although not specific to just
SqlRoleProvider, the chapter covers how to
get the provider working in a partial trust non-ASP.NET environment.
❑ Chapter 15 covers the
AuthorizationStoreRoleProvider — a provider that maps Role
Manager functionality to the Authorization Manager feature that first shipped in Windows Server
2003. You will learn how to set up and use both file-based and directory-based policy stores with
the provider. The chapter covers special Authorization Manager functionality that is supported
by the provider, as well as how to use both the
ActiveDirectoryMembershipProvider and
AuthorizationStoreRoleProvider to provide Active Directory based authentication and
authorization in your web applications.
What You Need to Run the Examples
This book was written using various Beta 2 and RC releases of the 2.0 Framework on Windows Server
2003 SP1. The sample code in the book has been verified to work with late RC builds of the 2.0
Framework. To run all of the samples in the book, you will need the following:

objAbout.ShowDialog(Me)
objAbout = Nothing
End Sub
Configuration information and the results from running code use a similar font, but do not have a back-
ground color:
<connectionStrings>
<add name=”myDatabase” connectionString=”some connection string”/>
</connectionStrings>
Sometimes you’ll see code in a mixture of styles, like this:
Private Sub mnuHelpAbout_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles mnuHelpAbout.Click
Dim objAbout As New About
objAbout.ShowDialog(Me)
objAbout.Dispose()
objAbout = Nothing
End Sub
In cases like this, the code with the gray background is code you are already familiar with; the line in the
bolded font is a new addition to the code.
03_596985 flast.qxp 12/14/05 7:45 PM Page xxii
xxiii
Introduction
Customer Support
We always value hearing from our readers, and we want to know what you think about this book: what
you liked, what you didn’t like, and what you think we can do better next time. You can send us your
comments either by returning the reply card in the back of the book or by email to

Please be sure to mention the book’s title in your message.
How to Download the Sample Code for the Book
When you visit the Wrox site (wrox.com) simply locate the title through our Search facility or by clicking
the Download Code link at the top of the main page, then find the book in the title list. Click the HTTP

general about the book or the Web site immediately.
03_596985 flast.qxp 12/14/05 7:45 PM Page xxiii


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status