ระบบความปลอดภัย web application aspnet

Post on 29-Jul-2015

259 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Uploaded from Google Docs

TRANSCRIPT

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

บทที่ 12แนวทางระบบความปลอดภัยของ

Web Application เบือ้งตน

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

เนื้อหาบทเรียน

รูจักกับแนวทางระบบความปลอดภยัของ ASP.NET Web Application

Forms-Based Authentication

สาธิต: Forms-Based Authentication

การประยุกตใชตวัแปรระดับ Session

สรุป

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

รูจักกบัแนวทางระบบความปลอดภัยของ ASP.NET Web Application

พื้นฐานของระบบความปลอดภัย

แนวทางการสรางระบบความปลอดภัยเบือ้งตน

ขอมูลเพิ่มเติม

ความปลอดภัยและถูกตองของขอมลู

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

พื้นฐานของระบบความปลอดภัย

Authentication – Login ผานหรือไม

Authorization – สิทธิ์ในการใชงานทรพัยากรตางๆ มีแคไหน

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

แนวทางการสรางระบบความปลอดภัยเบื้องตน

Windows-Based Authentication (ใชมากใน Intranet)อาศัย UserName และ Password ของ Windows บวกความสามารถของ IIS

Forms-Based Authentication (ใชมากใน Internet - กลาวถึงในรายละเอยีด)

เทียบไดกับการสรางระบบ Authentication ขึ้นมาเอง แตอาศัยความสามารถของ ASP.NET Security Service (Class FormsAuthentication)

Microsoft Passport Authenticationการใชบริการ Passport Service ของ Microsoft (เสียเงิน แต Login ครั้งเดียว – ไมแนะนํา – ตอง Site ใหญจริงๆ)

สรางระบบความปลอดภยัเอง + การประยกุตใชตัวแปรระดับ Session (ใชมากใน Internet กบั ASP แตก็ประยกุตใชกบั ASP.NET ได)

แนวทางคลาย Forms-Based แตอาศัยตัวแปรระดับ Session เปนตัวคุมในการเขาถึง Page เมือ่มีการ Login ผานแลว

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

หลกัการทํางานเพิม่เติมใน ASP.NET Resources Kit

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

ขอมูลเพิ่มเติม

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

ขอมูลเพิ่มเติม (ตอ)

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

ความปลอดภัยและถูกตองของขอมูล

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

Forms-Based Authentication

ขบวนการทํางานของ Forms-Based Authentication

การเซ็ตอัพ IIS

การกําหนด Authentication ในไฟล Web.Config

การกําหนด Authorization ในไฟล Web.Config

การสราง Login Form

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

ขบวนการทํางานของ Forms-Based Authentication

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

ขบวนการทํางานของ Forms-Based Authentication(ตอ)

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

การเซ็ตอัพ IIS

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

การกาํหนด Authentication ในไฟล Web.Config

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

การกําหนด Authorization ในไฟล Web.Config

URL Authorization: กําหนดในสวน system.web มีผลกระทบทั้ง Web App.

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

การกาํหนด Authorization ในไฟล Web.Config (ตอ)

URL Authorization: กําหนดในสวน location path มีผลกระทบทั้ง Page นัน้ๆ

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

การสราง Login Form

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

การสราง Login Form (ตอ)

FormsAuthentication Class: ให Methods ประเภท Shared มาเพื่อชวยในการจดัการกับ Authentication tickets (Cookies) – อยูภายใต Namespaces ชื่อ System.Web.Security (กอนใชตอง Imports)

Methods ที่สาํคัญ

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

การสราง Login Form (ตอ)

Methods ที่สาํคัญ (ตอ)

Identity Property ชวยในการเขาถงึขอมูลของ User ที่ Login

Properties ของ Identity ที่สาํคญั

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

สาธิต: Forms-Based Authentication

สรุปขั้นตอนการสาธิตสราง Project Web Application ใหมชื่อ Forms-Based-Demoเพิ่มไฟล .aspx ทั้งหมดที่อยูใน demo\ch12 (ไมรวมซับโฟเดอร) เขาสูโปรเจกตใช IIS ตรวจสอบ Enable anonynymous accessBuild และ รนั Project: ทําการ Browse ไฟล Default.aspx และ .aspx อื่นๆ โดยในกรณีนี้ยังไมมีการกําหนด Security ใดๆ ในไฟล Web.configเปดไฟล “eb.config สังเกตวายังไมมีการกําหนดเรื่อง Security เพิ่มไฟล Web.config.All และ Web.config.Location ที่อยูใน demo\ch12 เขาสูโปรเจกตRename ชื่อไฟล Web.config ใหเปน Web.config.bakRename ชื่อไฟล Web.config.Location ใหเปน Web.configเปดไฟล Web.config สังเกตการกําหนด Authentication ในสวน system.webเปดไฟล Web.config สังเกตการกําหนด Authorization ในไฟล Web.Config ในสวน system.web และ location

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

สาธิต: Forms-Based Authentication (ตอ)

สรุปขั้นตอนการสาธิต (ตอ)เปดไฟล Default.aspx, NonSecure.aspx, SecureForAdmin.aspx, SecureForMember.aspxและ Login.aspx ตามลําดับ ศึกษาการ UI และ Code behindBuild และ รัน Project (ไม Login และ Login) เพื่อทดสอบ Security ตามเงื่อนไขใน Web.config (ใหมกีารลอง Browse Page สลบัไปมา สังเกตวาไมตอง Login อกีในกรณีที่ Browse ไปที่อืน่หลังจาก Login ถามีสิทธิ์ในการใช Page นั้นๆRename ชือ่ไฟล Web.config ใหเปน Web.config.LocationRename ชือ่ไฟล Web.config.All ใหเปน Web.configเปดไฟล Web.config และ ทําการศกึษาการกําหนด SecurityBuild และ รัน Project (ไม Login และ Login) เพื่อทดสอบ Security ตามเงื่อนไขใน Web.config

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

การประยุกตใชตัวแปรระดับ Session

เมื่อ Login (Authentication) ผาน (เทียบกับ Database หรือ อื่นๆ) ก็ทําการสรางตัวแปรระดับ Session เพื่อเก็บสถานะ วา Login ผานแลว พรอมทั้งเก็บสถานะอื่นๆ หลังจากนัน้อาจจะสงตอไปยัง Page อื่นๆ

ตัวอยางโคดของ ASP

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

การประยุกตใชตัวแปรระดับ Session (ตอ)

ทุกๆ Page ทีม่ีการกําหนดสิทธิการเขาใชงาน (Authorize) ดานบนๆ ของ Page จะตองมีการตรวจสอบสิทธิ์ จากขอมูลในตัวแปรระดับ Session ถาผานก็สามารถใชงานได ถาไมก็สงตอไปยังหนา Login

ตัวอยางโคดของ ASP

© New Technology Information Co., Ltd. © NTSoft Corporation Limited.

สรุป

รูจักกับแนวทางระบบความปลอดภยัของ ASP.NET Web Application

Forms-Based Authentication

สาธิต: Forms-Based Authentication

การประยุกตใชตวัแปรระดับ Session

top related