46
SLIBRARY Cài đặt hệ thống Ngày 08 09, 2010 Phiên bản 1.0 Trạng thái Hoàn thành Tác giả Trần Trọng Thoàng 1

sLibrary@SystemInstallationGuide

  • Upload
    tu-minh

  • View
    47

  • Download
    1

Embed Size (px)

Citation preview

Page 1: sLibrary@SystemInstallationGuide

SLIBRARY

Cài đặt hệ thống

Ngày 08 09, 2010

Phiên bản 1.0

Trạng thái Hoàn thành

Tác giả Trần Trọng Thoàng

1

Page 2: sLibrary@SystemInstallationGuide

Lịch sử thay đổi

Ngày Phiên bản Chi tiết Người thực hiện

08 09, 2010 1.008 09, 2010 1.0

Hướng dẫn cài đặt hệ thống

sLibarryTrần Trọng Thoàng

2

Page 3: sLibrary@SystemInstallationGuide

Mục lục

1 GIỚI THIỆU................................................................................4

1.1 MỤC ĐÍCH..................................................................................................................................................4

1.2 PHẠM VI....................................................................................................................................................4

1.3 ĐỊNH NGHĨA CÁC TỪ VIẾT TẮT................................................................................................................4

1.4 THAM KHẢO..............................................................................................................................................4

1.5 TỔNG QUAN...............................................................................................................................................4

2 GIỚI THIỆU CHUNG VỀ SLIBRARY................................................5

3 HƯỚNG DẪN CÀI ĐẶT HỆ THỐNG................................................5

3.1 THƯ VIỆN VẬT LÝ......................................................................................................................................5

3.2 THƯ VIỆN SỐ..............................................................................................................................................5

3.3 QUẢN LÝ NGƯỜI DÙNG TẬP TRUNG...........................................................................................................5

3.3.1 LDAP..................................................................................................................................................5

3.3.2 CAS – Central Authentication Service.............................................................................................12

3.3.3 Build CAS và LDAP.........................................................................................................................20

3.3.4 Cấu hình SingleSignOn trên KOHA.................................................................................................23

3.3.5 Cấu hình SignleSignOn trên Dspace................................................................................................23

3.3.5.1 Cơ chế Single Sign On của Dspace dựa vào CAS và LDAP.............................................................233.3.5.2 Cấu hình xác thực CAS và LDAP.....................................................................................................24

3.3.5.2.1 Cấu hình lại trong file build của Maven – để tải Casclient........................................................243.3.5.2.2 Thêm bản vá để xác thực với CAS server – Dspace v1.6.0 trở về trước...................................243.3.5.2.3 Cấu hình xác thực qua CAS và LDAP trong file dspace.cfg.....................................................433.3.5.2.4 Rebuild gói ứng dụng DSpace...................................................................................................443.3.5.2.5 Cập nhật tất cả các thư mục DSpace webapps tại [dspace]/webapps.......................................443.3.5.2.6 Khởi động lại webserver Tomcat...............................................................................................45

4 THUẬT NGỮ.............................................................................45

5 Tham Khảo..............................................................................45

3

Page 4: sLibrary@SystemInstallationGuide

1

2 Giới Thiệu

2.1 Mục Đích

Hướng dẫn cài đặt hệ thống sLibrary trên môi trường thật để vận hành. Cài đặt hệ thống gồm cài đặt

thư viện thật, thư viện số và quản lí người dùng tập trung.

2.2 Phạm Vi

Tài liệu này chỉ tập trung vào việc hướng dẫn cài đặt hệ thống, mọi yêu cầu đối với các module cần

phải được đáp ứng để có thể cài đặt và vận hành tốt nhất.

2.3 Định Nghĩa Các Từ Viết Tắt

STT Term Định nghĩa

1 sLibarry Hệ thống thư viện

2 KOHA Gói cài đặt thư viện vật lý

3 DSpace Gói cài đặt thư viện số

4 CAS Server Hệ thống chứng thực tập trung

5 LDAP Server Hệ thống quản lí người dùng tập trung

2.4 Tham Khảo

2.5 Tổng Quan

4

Page 5: sLibrary@SystemInstallationGuide

3 Giới thiệu chung về sLibrary

sLibrary là hệ thống thư viện đáp ứng mọi yêu cầu của một thư viện hiện đại theo tiêu chuẩn quốc tế tích hợp:

hệ thống quản lí thư viện vật lý

hệ thống thư viện số

hệ thống quản lí người dùng tập trung nhờ kết hợp đăng nhập một lần theo chuẩn công nghiệp LDAP.

Đem lại tiện ích đáng kể cho hệ thống thư viện trong quy trình nghiệp vụ và quản trị người dùng một cách thông minh

4 Hướng dẫn cài đặt hệ thống

Yêu cầu phải cài đặt các biến môi trường cho java, tomcat, ant, maven – được hướng dẫn trong tài liệu cài đặt thư viện số

Bước 1: Lựa chọn hệ điều hành để cài đặt cả hệ thống: Windown hoặc UbuntuBước 2: Xem tài liệu và làm theo hướng dẫn cà đặt từng module của hệ thống trên HĐH đã chọn

- Thư viện vật lý- Thư viện số- Quản lí người dùng tập trung

Cài đặt LDAPserver Deploy CAS Server kết nối tới Ldapserver trên host

4.1 Thư viện vật lý

Tài liệu hướng dẫn : [email protected]

4.2 Thư viện số

Tài liệu hướng dẫn: [email protected]

4.3 Quản lý người dùng tập trung

4.3.1 CAS – Central Authentication Service

Tài liệu hướng dẫn: LV 05\200909_LV_DH_Liferay_Sakai_SSO.doc

(Mục 1.3 Central Authenticate Service – Giới thiệu – trang 20/127)

5

Page 6: sLibrary@SystemInstallationGuide

CAS là gì?

Là một giải pháp Single Sign On, ma nguôn mơ được phát triển bơi đại hoc Yale.

Hô trợ nhiêu thư viện phía client được viết bơi nhiêu ngôn ngữ: PHP, Java, PL/SQL, …

CAS lây thông tin Single Sign On thông qua cookie. Cookie này se bị hủy khi user đăng xuât khỏi CAS hoặc đóng trình duyệt. Cookie được sinh ra bơi CAS, con được gọi là TGT Cookie (Ticket Granting Cookie) chứa một id duy nhât và thời gian hết hạn. Thời gian hết hạn là 8 giờ.

CAS cung câp nhiêu trình quản lý xác thực (authenticate handler) khác nhau. CAS xác thực nhiêu loại thông tin người dùng như username/password, X509 Certificate, ...để xác thực thông tin người dùng.

1) Các phiên bản cua CAS

o CAS 1.0 Được tạo bơi Yale University, khơi đầu tư năm 1999. Là một Web Single Sign On, dê sư dụng.

o CAS 2.0 Cung được tạo ra bơi Yale University. Giới thiệu thêm tính năng mới là Proxy Authentication.

o JA-SIG CAS 3.0 Trơ thành JA-SIG project vào 2004. Mục đích là làm cho CAS tương thích cao hơn, mêm deo hơn. 100% tương thích với CAS 2.0

2) CAS URIs

CAS thực hiện Single Sign On thông qua những URI và sinh ra những ticket khác nhau. CAS se sư dụng những URI sau:

o /logout Hủy Single Sign On session và ticket granting cookie Hiển thị một trang trạng thái để báo với user đa đăng xuât. Tham số “url” có thể được chi định đến /logout và nếu được chi định, “url” se

được hiển thị trong trang logout cùng với thông báo đăng xuât.

o /validate Kiểm tra tính hợp lệ của service. CAS làm service ticket có hiệu lực, service

ticket được sinh ra tư thông tin xác thực lây tư request. Những tham số sau có thể chi định đến /validate URI

o Service (bắt buộc) o Ticket (bắt buộc) – service ticket được sinh ra bơi /logino Renew (không bắt buộc) – nếu tham số này được thiết lập.o Ptgurl – url của proxy callback

o /serviceValidate se trả vê một xml-formatted response. Khi thành công, response chứa username và proxy-granting ticket. Khi thât bại, response chứa một ma lôi với thông điệp thât bại tương ứng. Sau đây là một số ma lôi được trả vê response nếu /serviceValidate thât bại.

INVALID_REQUEST: Không tìm thây tham số cần tìm trong request. INVALID_TICKET: Ticket được cung câp không hợp lệ hoặc ticket không đến tư

login và “renew” được thiết lập trên validation. INVALID_SERVICE: Ticket được cung câp không hợp lệ nhưng service được chi

định không khớp với service mà liên kết với ticket.6

Page 7: sLibrary@SystemInstallationGuide

INTERNAL_ERROR: Lôi cục bộ xuât hiện trong khi kiểm tra tinh hợp lệ của ticket.

o /proxyValidate làm việc giống như /serviceValidate, ngoại trư nó làm cho proxy ticket có hiệu lực. Những tham số và ma lôi giống tương tự. Khi thành công, respone chứa PGT và danh sách các proxy cá mà việc xác thực được thực thi. Những proxy được viếng thăm gần nhât se năm trên đinh, và ngược lại

o /proxy Cung câp proxy ticket đến những service, lây PTG thông qua /proxyValidate

hoặc /serviceValidate Những tham số sau được yêu cầu cho /proxy URI

o Pgt – proxy granting ticketo TargetService – service identifier của back-end service. Service identifier

phải khớp với service identifier được chi định đến /proxyValidate nhờ vào sự hợp lệ của proxy ticket.

/proxy se trả vê xml-formatted service response. Thành công, response se chứa đựng proxy ticket. Thât bại, response chứa đựng ma lôi với thông điệp tương ứng. Các ma lôi se được trả vê trong /proxy: INVALID_REQUEST, BAD_PGT, INTERNAL_ERROR. BAD_PGT có nghia là pgt không hợp lệ.

o /samlValidate : SAML (Secuirty Assertion Markup Language) framework.

URI Mô tả/login Hiển thị khung đăng nhập yêu cầu người dùng xác thực/logout Hủy Single Sign On session và ticket granting cookie/validate Kiểm tra tính hợp lệ của Service Ticket. Nếu nó không

sư dụng proxy authentication/serviceValidate Kiểm tra tính hợp lệ của Service Ticket và trả vể một

XML-fragment và sinh ra proxy-granting ticket khi được yêu cầu

/proxyValidate Thực thi giống như /serviceValidate và ngoài ra con kiểm tra tính hợp của proxy ticket

/proxy Cung câp Proxy Ticket đến service/samlValidate/services/add.html Một tính năng admin. Thêm những service đến danh

sách Registered Services./services/edit.html Chinh sưa những service đa đăng ký/services/manage.html Quản lý những service đa đăng ký như: thêm, xóa, sưa./services/logout.html Đăng xuât tư trang admin service/services/deleteRegisteredService.html

Xóa service bơi tham số “id” được cung câp

3) CAS Tickets.

Ticket đơn giản là một chuôi ký tự ngẫu nhiên và bắt đầu với một tiên tố như (ST-,TGC-,…) và nó là id duy nhât cho một thao tác nào đó. Trong quá trình xác thực của CAS, một số ticket được tạo ra với mục đích lưu trữ thông tin và bảo mật. Sau đây là khái niệm một số ticket được sư dụng trong CAS.

o Ticket-Granting Ticket (TGT). Là một chuôi ký tự chứa dữ liệu bảo mật ngẫu nhiên và bắt đầu băng “TGT”,

chứa id duy nhât và thời gian hết hạn. TGT được tạo ra CAS Server xác thực thành công.

7

Page 8: sLibrary@SystemInstallationGuide

Không có TGT, user của CAS không thể Single Sign On TGT se được thêm vào HTTP Cookie (cơ sơ để Single Sign On) và nó se được

kiểm tra khi truy cập ứng dụng. Ví dụ: TGT se được lưu xuống browser là TGC (Ticket Granting Cookie) là một

HTTP Cookie của CAS. Cookie này duy trì trạng thái đăng nhập cho client. Khi client chuyển đến các ứng dụng khác, cookie này se được kiểm tra đế tự động đăng nhập cho user. TGC se bị hủy khi đóng trình duyệt hay client chọn logout tư ứng dụng. Giá trị của TGC bắt đầu băng “TGC-“.

o Service Ticket (ST) Service Ticket se được tạo ra khi CAS Url có chứa tham số service và thông tin

xác thực được truyên đến và xác thực thành công. Ví dụ: https://server/CAS/login?service=http%3A%2F%2Fwww.service.com Môi Service chi có một service ticket duy nhât và được sư dụng một lần duy

nhât. ST là một chuôi ký tự, được sư dụng bơi client như là thông tin xác thực để truy

cập đến dịch vụ. Service ticket phải bắt đầu với ký tự “ST-“. Ví dụ: ticket=ST-1856339-aA5Yuvrxzpv8Tau1cYQ7

o Proxy Ticket (PT) CAS Proxy là một service muốn truy xuât những service khác thay mặt cho một

user riêng biệt. Proxy Ticket (PT) được sinh ra tư CAS nhờ vào một service thể hiện của một Proxy Granting Ticket hợp lệ và một service identifier (giá trị của tham số “url” của /proxy url) cho back-end service đến cái nó kết nối.

Proxy Ticket là một chuôi ký tự ngẫu nhiên mà một service sư dụng như thông tin đăng nhập để truy cập vào một back-end service thay mặt cho client.

Proxy ticket chi hợp lệ cho service identifier được chi định đến /proxy url khi chung được sinh ra.

Proxy ticket bắt đầu băng “PT”.

o Proxy-Granting Ticket (PGT) PGT được lây tư CAS nhờ vào sự hợp lệ của service ticket hoặc proxy ticket. Nếu

một service mong muốn proxy xác thực client đến một back-end service, nó yêu cầu một proxy-granting ticket.

o Proxy-Granting Ticket IOU Trên một ticket hợp lệ, một service có thể yêu cầu một proxy ticket. Trong CAS

2.0, cách chung ta xác thực service được yêu cầu để gơi PGT, PGTIOU đến proxy callback url được chi định như một request parameter. Proxy callback url phải chạy thông qua kênh bảo mật. Chung ta xác minh certificate của nó. Sau đó, trả vê trong ticket hợp lệ, phản hôi TGTIOU. Tư response này, service se rut TGTIOU và sư dụng nó để tìm TGT tư bộ nhớ.

o Login Ticket Là một chuôi ký tự, được sinh ra bơi /login, là một thông tin đăng nhập và được

đưa đến /login. Mục đích là ngăn cản sư phản hôi lại thông tin xác thực. Login ticket được sinh ra bơi /login, phải là duy nhât và bắt đầu với “LT-”.

4) Nguyên tắc hoạt đông cua CAS

o Chứng thực người dùng với CAS server.

Người dùng nhập UserId / Password vào khung đăng nhập. Các thông tin này được truyên cho CAS server thông qua giao thức HTTPS là một giao thức bảo đảm dữ liệu được ma hóa trước truyên đi.

8

Page 9: sLibrary@SystemInstallationGuide

Xác thực thành công, TGC được sinh ra và thêm vào trình duyệt dưới hình thức là cookie.TGC này se được sư dụng để Single Sign On với tât cả các ứng dụng

o Truy cập vào ứng dụng.

Người dùng truy cập vào ứng dụng khi đa chứng thực với CAS server.o Người dùng truy xuât ứng dụng thông qua trình duyệt.o Ứng dụng lây TGC tư trình duyệt và chuyển nó cho CAS server thông qua

giao thức HTTPS.o Nếu TGC này là hợp lệ, CAS server trả vê một Service Ticket cho trình

duyệt, trình duyệt truyên ST vưa nhận cho ứng dụng.o Ứng dụng sư dụng ST nhận được tư trình duyệt và sau đó chuyển nó cho

CAS server.o CAS server se trả vê ID của người dùng cho ứng dụng, mục đích là để

thông báo với ứng dụng người dùng này đa được chứng thực bơi CAS server.

o Ứng dụng đăng nhập cho người dùng và bắt đầu phục vụ người dùng.

Người dùng truy cập vào ứng dụng khi đa chứng thực với CAS server

Người dùng truy cập vào ứng dụng mà chưa chứng thực với CAS servero Người dùng truy xuât ứng dụng thông qua trình duyệt. Vì chưa nhận

được TGC nên ứng dụng se chuyển hướng người dùng cho CAS server.o Người dùng cung câp UserId / Password của mình thông qua khung đăng

nhập để CAS xác thực. Thông tin được truyên đi thông qua giao thức HTTPS.

o Xác thực thành công, CAS server se trả vê cho trình duyệt đông thời TGC và ST.

9

Page 10: sLibrary@SystemInstallationGuide

o Ứng dụng se giữ lại TGC để sư dụng cho các ứng dụng khác (nếu có) và truyên ST cho ứng dụng.

o Ứng dụng chuyển ST cho CAS server và nhận vê ID của người dùng.o Ứng dụng đăng nhập cho người dùng và bắt đầu phục vụ người dùng.

Người dùng truy cập vào ứng dụng mà chưa chứng thực với CAS server

5) CAS Architecture

o CAS – Login Flow

10

Page 11: sLibrary@SystemInstallationGuide

Người dùng có thể truy xuât thông qua nhiêu URI khác nhau. URI chủ yếu là /login. Khi người dùng nhập địa chi http://server/CAS/login tư trình duyệt, CAS se kiểm tra Ticket granting cookie (TGC) đa tôn tại chưa. Nếu TGC đa tôn tại, thì nó se kiểm tra thời gian hết hạn của cookie và nếu con thời hạn thì Service Ticket (ST) se được sinh ra. Nếu TGC không tôn tại hay đa hết hạn thì CAS se buộc người dùng nhập thông tin đăng nhập vào khung đăng nhập.

Người dùng nhập thông tin đăng nhập và chọn Submit, CAS se lây danh sách AuthenticationHanders tư deployerConfigContext.xml và kiểm tra xem nó hô trợ AuthenticationHander nào. Nó se đưa thông tin đăng nhập cho AuthenticationHander mà nó hô trợ và kiểm tra thông tin đăng nhập của người

11

Page 12: sLibrary@SystemInstallationGuide

dùng. Nếu người dùng xác thực không hợp lệ se được chuyển đến khung đăng nhập để đăng nhập lại. Nếu người dùng hợp lệ thì một Ticket-granting Ticket (TGT) se được sinh ra và thêm vào cookie.

CAS tạo ra một Service Ticket (ST) và thêm Service Ticket này đến Ticket Registry. CAS kiểm tra có hay không service parameter thông qua /login URL.

Ví dụ: https://server/CAS/login?service=http://www.findtechies.com/auth.jsp o CAS gọi Service Identifier với ticket là tham số, giá trị là service ticket

(st). Các client có trách nhiệm gọi /serviceValidate URI của CAS để kiểm tra service và service ticket. /serviceValidate se được gọi bơi filter của client

o Service param name: serviceo Service Identifier value: https://www.servertechies.com/auth.jspo Ticket param name: ticketo Service Ticket value: ST-1856339-aA5Yuvrxzpv8Tau1cYQ7o Proxy param name: pgtUrlo Proxy-granting Url value: https://server/test.jsp

o Proxy Flow

o Logout Flow

12

Page 13: sLibrary@SystemInstallationGuide

Khi người dùng muốn đăng xuât khỏi một service, người dùng phải gọi logout URI. CAS se hủy Ticket-Granting Cookie và kiểm tra /logout URI có chứa parameter url hay không. Nếu parameter “url” có giá trị, một thông báo đăng xuât thành công se được hiển thị với một liên kết đến giá trị url, ngược lại thì chi có thông báo đăng xuât thành công.

o Hạn chế CAS chi giải quyết authenticate, không authorization. Không Single Sign-Off. Ít tài liệu tham khảo.

4.3.2 Build CAS và LDAP

Phần này hướng dẫn triển khai CAS Server kết nối đến LDAP Server và deploy CASServer trên tomcat.

Hình 1 - Mô hình triển khai Sakai - Liferay – CAS

Bước 1: Câu hình CAS Server xác thực thông qua LDAP

Sau khi tải CAS Server vê, bung ra một thự mục CAS-server-3.3.2.

- Mơ pom.xml trong %CAS_HOME%/CAS-server-webapp, thêm phần sau:

<dependency> <groupId>${project.groupId}</groupId> <artifactId>cas-server-support-ldap</artifactId> <version>${project.version}</version></dependency>

- Mơ deployerConfigContext.xml trong thư mục CAS_home/CAS-server-webapp/src/main/webapp/WEB-INF và sưa lại nội dung như sau:

o Trong the <beans>…</beans> thay thế AuthenticatedLDAPContextSource băng nội dung như sau:

13

Page 14: sLibrary@SystemInstallationGuide

<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">

<property name="pooled" value="true"/> <property name="urls"> <list><value>ldap://nonglam.cntt.com:5389</value></list> </property> <property name="userDn" value="cn=Directory Manager"/> <property name="password" value="123456"/></bean>

Trong đó: ldap://nonglam.cntt.com:5389 là đường dẫn kết nối tới LDAP servercn=Directory Manager là tên đăng nhập root của LDAP Server123456 là password ứng với tài khoản đăng nhập trên

o Thiết lập AuthenticationHander: Thêm nội dung sau vào bên trong the <bean id=authenticationManager”>…</bean>

<property name="authenticationHandlers" ><list> <bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"> <property name="httpClient" ref="httpClient" /> </bean> <bean class="org.jasig.cas.adaptors.ldap.BindLdapAuthenticationHandler" > <property name="filter" value="uid=%u" /> <property name="searchBase" value="ou=cntt,o=nonglam,dc=com" /> <property name="contextSource" ref="contextSource" /> </bean></list</property>

Trong đó:uid=%u là trường định danh của người dùng trong LDAP Serverou=cntt,o=nonglam,dc=com là câu truc cây để tìm kiếm tài khoản người dùng

- Build và Deploy.o Build lại CAS-server với lệnh: mvn package install (đa cài đặt maven).o Sau build thành công chép CAS.war trong thư mục %CAS_HOME%/CAS-server-

webppp/target vào thư mục webapp của tomcat.

Bước 2: Câu hình Tomcat Server để chạy CAS

CAS sư dụng giao thức SSL cho nên cần phải câu hình Tomcat để hô trợ SSL.

- Sư dụng keytool để self-sign một certificate

14

Page 15: sLibrary@SystemInstallationGuide

o Chạy cmd – Windown (hoặc Terminal - Linux) với quyên Administrator và chuyển đến thư mục bin của [JDK_Home]

//tao keystore[JDK_Home]>cd bin[JDK_Home]\bin>keytool -genkey -alias tomcat -keypass changeit -keyalg RSAEnter keystore password: changeitWhat is your first and last name? [Unknown]: nonglam.cntt.com What is the name of your organizational unit? [Unknown]: Information SystemsWhat is the name of your organization? [Unknown]: Pacific Disaster CenterWhat is the name of your City or Locality? [Unknown]: KiheiWhat is the name of your State or Province? [Unknown]: HIWhat is the two-letter country code for this unit? [Unknown]: USIs CN=localhost, OU=Information Systems, O=Pacific Disaster Center, L=Kihei, ST=HI, C=US correct? [no]: yes

//xuất ra file certificate[JDK_Home]\bin>keytool -export -alias tomcat -keypass changeit -file serverEnter keystore password: changeitCertificate stored in file <server>

//self-sign [JDK_Home]\bin>keytool -import -file server -keypass changeit -keystore ..\jre\lib\security\cacertsEnter keystore password: changeitOwner: CN=localhost, OU=Information Systems, O=Pacific Disaster Center, L=Kihei, ST=HI, C=USIssuer: CN=localhost, OU=Information Systems, O=Pacific Disaster Center, L=Kihei, ST=HI, C=USSerial number: 462030d8Valid from: Fri Apr 13 15:39:36 HST 2007 until: Thu Jul 12 15:39:36 HST 2007Certificate fingerprints:MD5: CC:3B:FB:FB:AE:12:AD:FB:3E:D 5:98:CB:2E:3B:0A:ADSHA1: A1:16:80:68:39:C7:58:EA:2F:48:59:AA:1D:73:5F:56:78:CE:A4:CETrust this certificate? [no]: yesCertificate was added to keystore

o Chu ý: khi keystore được tạo, mặt đinh se được lưu trong C:/Document and Setting/User/.Keystore – trên Windown hoặc /home/[user]/.keystores – trên Linux

- Câu hình tomcat server.xml

Mơ file server.xml trong thư mục config của Tomcat. Bỏ comment element “connector” cho cổng 8843 (SSL). Thêm vào những parameter cho keystore file, keystore pass, trustore file và SSLEnable = true.

15

Ch nay ph i điô a ên full domain

Page 16: sLibrary@SystemInstallationGuide

<!-- Define a SSL HTTP/1.1 Connector on port 8443 --><Connector port="8443" maxHttpHeaderSize="8192" SSLEnabled=”true”maxThreads="150" minSpareThreads="25" maxSpareThreads="75"enableLookups="false" disableUploadTimeout="true"acceptCount="100" scheme="https" secure="true"clientAuth="false" sslProtocol="TLS"keystoreFile="C:/Documents and Settings/[user]/.keystore"keystorePass="changeit"truststoreFile="[JDK_Home]/jre/lib/security/cacerts" />

- Chạy tomcat server và chạy https://[host]:8443/CAS/login

Demo CAS Server xác thực thông qua LDAP

Các bước thực hiện:

- Giải nén file down vê (Link LV 05\cas_Current.rar)

- Câu hình đường dẫn kết nối tới LDAP Server (giống với bước trên)

- Câu hình tomcat sư dụng giao thức https (giống với bước trên)

- Câu hình đường dẫn tomcat đến thư mục CAS Server trong file [Tomcat_home]/conf/server.xml

<Host>. . .

<Context path="/cas" docBase="[đường dẫn đến thư mục vừa giải nén]" debug="0" reloadable="true" cachingAllowed="false" allowLinking="true"/>

</Host>

4.3.3 Cấu hình SingleSignOn trên KOHA

4.3.4 Cấu hình SignleSignOn trên Dspace

4.3.4.1 Cơ chế Single Sign On của Dspace dựa vào CAS và LDAP

Phương thức canSelfRegister trả vê true/false (đung/sai) tùy thuộc vào webui.cas.autoregister theo quy định tại dspace.cfg – bước câu hình ơ trên

Phương thức isimplicit trả vê true (đung) bởi vì username/password (tên đăng nhập/ mật khẩu) ơ ngoài CSDL của Dspace

Phương thức allowSetPassword trả vê false (sai) – không cho chinh sưa mật khẩu

16

Page 17: sLibrary@SystemInstallationGuide

Phương thức authenticate làm việc theo dong tuần tự sau:

1. Đầu tiên sẽ kiểm tra nếu người dùng đã đăng nhập vào CAS (được nhận một ticket từ CAS Server)

2. Nếu ticket tồn tại, xác nhận lại ticket bằng cách gọi đến cas.validate.url, nếu hợp lệ thì ID của người dùng được trả lại

3. Nếu người dùng có ID tồn tại trong Dspace thì họ thành công trong việc xác thực

4. Nếu không, nếu SelfRegistration là đúng: người sử dụng sẽ được tự động tạo và đăng ký bằng cách dùng ID. Điều này ngụ ý rằng các email, họ tên phải được thêm vào bằng tay bởi người sử được phép đăng nhập. Nếu bạn muốn trích xuất thông tin về người dùng tự động, phải sử dụng truy vấn thông qua LDAP hoặc Database vv..

5. Nếu người dùng không đăng nhập được vào Dspace, chuyển họ dến trang đăng nhập của CAS

6. Nếu nguồi dùng được xác thực thành công, CASServer trả về một ticket

7. Trở lại bước 1

4.3.4.2 Cấu hình xác thực CAS và LDAP

4.3.4.2.1Cấu hình lại trong file build cua Maven – để tải Casclient

Thêm những dong sau vào trong the <dependencies> của 2 file: [dspace-source]/dspace-api/pom.xml [dspace-source]/dspace-xmlui/dspace-xmlui-api/pom.xml

<dependency><groupId>cas</groupId><artifactId>casclient</artifactId><version>2.1.1</version>

</dependency>

Thêm những dong sau vào trong the <dependencies> của file: [dspace-source]/dspace-xmlui/dspace-xmlui-webapps/pom.xml

<dependency><groupId>cas</groupId><artifactId>casclient</artifactId><version>2.1.1</version><scope>runtime</scope>

</dependency>

Những dong mới thêm giup Maven download thư viện CAS vê cho ứng dụng Dspace. Ứng dụng Dspace se là một CasClient - ứng dụng dùng cas – se nhờ CAS server xác thực người dùng

4.3.4.2.2Thêm bản vá để xác thực với CAS server – Dspace v1.6.0 trở về trước

17

Page 18: sLibrary@SystemInstallationGuide

1. Thêm file CASAuthentication.java vào thư mục [DSPACE_Source]\dspace-api\src\main\java\org\dspace\authenticate\ với nội dung sau:

package org.dspace.authenticate;

import org.apache.commons.lang.StringUtils;import org.apache.log4j.Logger; // import org.dspace.app.webui.util.JSPManager;import org.dspace.core.ConfigurationManager;import org.dspace.core.Context;import org.dspace.core.I18nUtil;import org.dspace.core.LogManager;import org.dspace.eperson.*;

//import org.dspace.app.webui.util.Authenticate;import org.dspace.authenticate.*;import org.dspace.authorize.AuthorizeException; //import javax.servlet.jsp.PageContext;import javax.naming.NamingEnumeration;import javax.naming.NamingException;import javax.naming.directory.Attribute;import javax.naming.directory.Attributes;import javax.naming.directory.BasicAttribute;import javax.naming.directory.BasicAttributes;import javax.naming.directory.DirContext;import javax.naming.directory.InitialDirContext;import javax.naming.directory.SearchControls;import javax.naming.directory.SearchResult;import javax.servlet.*; //import javax.servlet.jsp.jstl.fmt.LocaleSupport;

import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.BufferedReader;import java.sql.SQLException;import java.io.IOException;import java.io.InputStreamReader;import java.net.URL;

// we use the Java CAS clientimport edu.yale.its.tp.cas.client.*;import edu.yale.its.tp.cas.util.SecureURL;

import java.sql.SQLException;import javax.servlet.http.HttpServletRequest;import java.util.Collection;import java.util.Hashtable; //import java.util.Locale;

import javax.servlet.http.HttpServletResponse; //import javax.servlet.jsp.jstl.core.Config;

import org.apache.log4j.Logger;import org.dspace.authorize.AuthorizeException;

import org.dspace.core.Context;import org.dspace.core.ConfigurationManager;

18

Page 19: sLibrary@SystemInstallationGuide

import org.dspace.core.LogManager;import org.dspace.authenticate.AuthenticationManager;import org.dspace.authenticate.AuthenticationMethod;import org.dspace.authenticate.LDAPAuthentication.SpeakerToLDAP;import org.dspace.eperson.EPerson;import org.dspace.eperson.Group;

public class CASAuthentication implements AuthenticationMethod {// implements AuthenticationManager {

/** log4j category */private static Logger log =

Logger.getLogger(CASAuthentication.class);

private static String casServicevalidate; // URL to validate ST tickets

private static String casProxyvalidate; // URL to validate PT tickets

// (optional) store user's details for self registration, can get this info

// from LDAP, RDBMS etcprivate String email;private String firstName;private String lastName;

/** * Predicate, can new user automatically create EPerson. Checks * configuration value. You'll probably want this to be true to

take * advantage of a Web certificate infrastructure with many more

users than * are already known by DSpace. */public boolean canSelfRegister(Context context, HttpServletRequest

request,String username) throws SQLException {

return ConfigurationManager.getBooleanProperty("webui.cas.autoregister");

}

/** * Nothing extra to initialize. */public void initEPerson(Context context, HttpServletRequest

request,EPerson eperson) throws SQLException {

}

/** * We don't use EPerson password so there is no reason to change

it. */public boolean allowSetPassword(Context context,

HttpServletRequest request, String username) throws SQLException {

return false;}

19

Page 20: sLibrary@SystemInstallationGuide

/** * Returns true, CAS is an implicit method */public boolean isImplicit() {

return true;}

/** * No special groups. */public int[] getSpecialGroups(Context context, HttpServletRequest

request) {return new int[0];

}

/** * CAS authentication. * * @return One of: SUCCESS, BAD_CREDENTIALS, NO_SUCH_USER, BAD_ARGS *//* * String SUCCESS = "SUCCESS"; String BAD_CREDENTIALS =

"BAD_CREDENTIALS"; * String NO_SUCH_USER = "NO_SUCH_USER"; String BAD_ARGS =

"BAD_ARGS"; */

public int authenticate(Context context, String netid, String password,

String realm, HttpServletRequest request) throws SQLException {

final String ticket = (String) request.getParameter("ticket");

final String service = (String) request.getRequestURL().toString();

casServicevalidate = netid;

if (ticket != null) {

try {// Determine CAS validation URLString validate = ConfigurationManager

.getProperty("cas.validate.url");// log.info(LogManager.getHeader(context,

"login",// "CAS validate: " + validate));if (validate == null) {

throw new ServletException("No CAS validation URL

specified. You need to set property 'cas.validate.url'");}

// Validate ticket (it is assumed that CAS validator returns the

// user network ID)netid = validate(service, ticket, validate);System.out.println("NETID:....................."

+ netid);

20

Page 21: sLibrary@SystemInstallationGuide

if (netid == null) {throw new ServletException(

"*****************ko ton tai NetID trong ticket***************");

}

// Locate the eperson in DSpaceEPerson eperson = null;try {

System.out.println("vao try");eperson = EPerson.findByNetid(context,

netid.toLowerCase());//

System.out.println("eperson:....................."// + eperson.getEmail());

} catch (SQLException e) {

System.out.println("SQLException :....................." + e.getMessage());

}

System.out.println("ra khoi catch__________________________");

// if they entered a netd that matches an eperson and they are

// allowed to loginif (eperson != null) {

request.getSession().setAttribute("serviceLogout", service);System.out.println("setbien de logout");try{

System.out.println("if eperson != null:.....................");

// e-mail address corresponds to active account

if (eperson.getRequireCertificate()) {

// they must use a certificateSystem.out

.println("CERT_REQUIRED:....................."

+ CERT_REQUIRED);

return CERT_REQUIRED;} else if (!eperson.canLogIn()) {

System.out.println("BAD_ARGS:....................."+ BAD_ARGS);

return BAD_ARGS;}// Logged in OK.context.setCurrentUser(eperson);//

log.info(LogManager.getHeader(context, "authenticate",// "type=CAS"));

return SUCCESS;}catch(Exception e){

21

Page 22: sLibrary@SystemInstallationGuide

log.error("Unexpected exception caught", e);

}

}

// the user does not exist in DSpace so create an eperson

else {System.out.println("eperson ==

null:.....................");

if (canSelfRegister(context, request, netid)) {

// TEMPORARILY turn off authorisation// Register the new user

automaticallycontext.setIgnoreAuthorization(true);eperson = EPerson.create(context);// use netid only but this implies

that user has to// manually update their profileeperson.setNetid(netid);

// if you wish to automatically extract further user

// details: email, first_name and last_name

// enter your method here: e.g. query LDAP or RDBMS etc.

/* * e.g. */// lam viec voi LDAP{

SpeakerToLDAP ldap = new SpeakerToLDAP(log);

String adminUser = ConfigurationManager.getProperty("ldap.search.user");

String adminPassword = ConfigurationManager.getProperty("ldap.search.password");

String dn = ldap.getDNOfUser(adminUser, adminPassword, context, netid);

ldap.getDNOfUser(adminUser, adminPassword, context, netid);

email = ldap.ldapEmail;firstName = ldap.ldapGivenName;lastName = ldap.ldapSurname;String phone = ldap.ldapPhone;

System.out.println("....................................");System.out.println("email: " +

email);System.out.println("firstName:

" + firstName);System.out.println("lastName: "

+ lastName);

22

Page 23: sLibrary@SystemInstallationGuide

System.out.println("phone: " + phone);

System.out.println(".....................................");

}{

registerUser(netid);eperson.setEmail(email);

eperson.setFirstName(firstName);eperson.setLastName(lastName);

eperson.setCanLogIn(true);

AuthenticationManager.initEPerson(context, request,eperson);eperson.update();context.commit();

context.setIgnoreAuthorization(false);

context.setCurrentUser(eperson);}

return SUCCESS;} else {

// No auto-registration for valid netid

// log.warn(LogManager.getHeader(context,

// "authenticate","type=netid_but_no_record, cannot auto-register"));

return NO_SUCH_USER;}

}

} catch (Exception e) {System.out.println(e.getMessage());log.error("Unexpected exception caught", e);// throw new ServletException(e);

}}return BAD_ARGS;

}

/** * Returns the NetID of the owner of the given ticket, or null if

the ticket * isn't valid. * * @param service * the service ID for the application validating the

ticket * @param ticket * the opaque service ticket (ST) to validate */public static String validate(String service, String ticket,

String validateURL) throws IOException, ServletException {

23

Page 24: sLibrary@SystemInstallationGuide

ServiceTicketValidator stv = null;String validateUrl = null;

if (ticket.startsWith("ST")) {stv = new ServiceTicketValidator();validateUrl = casServicevalidate;

} else {// uPortal uses thisstv = new ProxyTicketValidator();validateUrl = casProxyvalidate;

}

System.out.println("validateURL == :....................."+ validateURL);

System.out.println("service == :....................." + service);

System.out.println("ticket == :....................." + ticket);

System.out.println("---------------------------------------

--------------------------------------------");System.out

.println("-----------------------------------------------------------------------------------");

{// boolean attemptedAuthentication = true;StringBuffer sb = new StringBuffer();sb.append(validateURL);if (validateURL.indexOf('?') == -1)

sb.append('?');else

sb.append('&');sb.append("service=" + service + "&ticket=" + ticket);// if (proxyCallbackUrl != null) sb.append("&pgtUrl=" +// proxyCallbackUrl);// if (renew) sb.append("&renew=true");String url = sb.toString();String response = SecureURL.retrieve(url);System.out.println("url :....................." + url);System.out.println("response :....................." +

response);}

stv.setCasValidateUrl(validateURL);stv.setService(java.net.URLEncoder.encode(service));stv.setServiceTicket(ticket);

{// public static void main(String args[]) throws

Exception {// System.setProperty("java.protocol.handler.pkgs",// "com.sun.net.ssl.internal.www.protocol");// ServiceTicketValidator sv// = new ServiceTicketValidator();//

sv.setCasValidateUrl("https://portal1.wss.yale.edu/cas/serviceValidate");//

sv.setProxyCallbackUrl("https://portal1.wss.yale.edu/casProxy/receptor");// sv.setService(args[0]);

24

Page 25: sLibrary@SystemInstallationGuide

// sv.setServiceTicket(args[1]);// sv.validate();// System.out.println(sv.getResponse());// System.out.println();// if (sv.isAuthenticationSuccesful()) {// System.out.println("user: " + sv.getUser());// System.out.println("pgtIou: " + sv.getPgtIou());// } else {// System.out.println("error code: " +

sv.getErrorCode());// System.out.println("error message: " +

sv.getErrorMessage());// }// }

}try {

stv.validate();System.out

.println("stv.isAuthenticationSuccesful() :....................."

+ stv.isAuthenticationSuccesful());

System.out.println("stv.getUser(): " + stv.getUser());

System.out.println("stv.getResponse(): " + stv.getResponse());

System.out.println("getErrorMessage(): " +

stv.getErrorMessage());} catch (Exception e) {

log.error("Unexpected exception caught", e);System.out.println("error code: " +

stv.getErrorCode());System.out.println("error message: " +

stv.getErrorMessage());throw new ServletException(e);

}if (!stv.isAuthenticationSuccesful())

return null;String netid = stv.getUser();

// System.out.println("netid :....................." + netid);

return netid;

}

/** * Add code here to extract user details email, firstname, lastname

from * LDAP or database etc */

public void registerUser(String netid) throws ClassNotFoundException,

SQLException {// add your code here

25

Page 26: sLibrary@SystemInstallationGuide

}

/* * Returns URL to which to redirect to obtain credentials (either

password * prompt or e.g. HTTPS port for client cert.); null means no

redirect. * * @param context DSpace context, will be modified (ePerson set)

upon * success. * * @param request The HTTP request that started this operation, or

null if * not applicable. * * @param response The HTTP response from the servlet method. * * @return fully-qualified URL */public String loginPageURL(Context context, HttpServletRequest

request,HttpServletResponse response) {

// Determine CAS server URLfinal String authServer = ConfigurationManager

.getProperty("cas.server.url");

final String service = request.getRequestURL().toString();

// final String service =// ConfigurationManager.getProperty("dspace.validate.url");

// log.info("CAS server: " + authServer);

String url = authServer + "?service=" + service;// Redirect to CAS server

return response.encodeRedirectURL(url);

};

public String loginPageURL_old(Context context, HttpServletRequest request,

HttpServletResponse response) {

// Determine CAS server URLfinal String authServer = ConfigurationManager

.getProperty("cas.server.url");final String service = request.getRequestURL().toString();// log.info("CAS server: " + authServer);

String url = authServer + "?service=" + service;// Redirect to CAS server

return response.encodeRedirectURL(url);

};

26

Page 27: sLibrary@SystemInstallationGuide

/* * Returns message key for title of the "login" page, to use in a

menu * showing the choice of multiple login methods. * * @param context DSpace context, will be modified (ePerson set)

upon * success. * * @return Message key to look up in i18n message catalog. */public String loginPageTitle(Context context) {

// return null;return "org.dspace.eperson.CASAuthentication.title";

}

// class them vao de goi toi LDAPpublic class SpeakerToLDAP {

private Logger log = null;

protected String ldapEmail = null; protected String ldapGivenName = null; protected String ldapSurname = null; protected String ldapPhone = null;

/** LDAP settings */String ldap_provider_url =

ConfigurationManager.getProperty("ldap.provider_url");String ldap_id_field =

ConfigurationManager.getProperty("ldap.id_field");String ldap_search_context =

ConfigurationManager.getProperty("ldap.search_context");String ldap_object_context =

ConfigurationManager.getProperty("ldap.object_context");String ldap_search_scope =

ConfigurationManager.getProperty("ldap.search_scope");

String ldap_email_field = ConfigurationManager.getProperty("ldap.email_field");

String ldap_givenname_field = ConfigurationManager.getProperty("ldap.givenname_field");

String ldap_surname_field = ConfigurationManager.getProperty("ldap.surname_field");

String ldap_phone_field = ConfigurationManager.getProperty("ldap.phone_field");

SpeakerToLDAP(Logger thelog) { log = thelog; }

protected String getDNOfUser(String adminUser, String adminPassword, Context context, String netid)

{// The resultant DNString resultDN;

27

Page 28: sLibrary@SystemInstallationGuide

// The search scope to use (default to 0)int ldap_search_scope_value = 0;try{

ldap_search_scope_value = Integer.parseInt(ldap_search_scope.trim());

}catch (NumberFormatException e){

// Log the error if it has been set but is invalid

if (ldap_search_scope != null){

log.warn(LogManager.getHeader(context,"ldap_authentication",

"invalid search scope: " + ldap_search_scope));}

}

// Set up environment for creating initial context

Hashtable env = new Hashtable(11);

env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

env.put(javax.naming.Context.PROVIDER_URL, ldap_provider_url);

if ((adminUser != null) && (!adminUser.trim().equals("")) &&

(adminPassword != null) && (!adminPassword.trim().equals("")))

{ // Use admin credencials for search// Authenticate

env.put(javax.naming.Context.SECURITY_AUTHENTICATION, "simple"); env.put(javax.naming.Context.SECURITY_PRINCIPAL,

adminUser); env.put(javax.naming.Context.SECURITY_CREDENTIALS,

adminPassword); } else { // Use anonymous authentication

env.put(javax.naming.Context.SECURITY_AUTHENTICATION, "none"); }

DirContext ctx = null;try{

// Create initial contextctx = new InitialDirContext(env);

Attributes matchAttrs = new BasicAttributes(true);

matchAttrs.put(new

28

Page 29: sLibrary@SystemInstallationGuide

BasicAttribute(ldap_id_field, netid));

// look up attributestry{

SearchControls ctrls = new SearchControls();

ctrls.setSearchScope(ldap_search_scope_value);

NamingEnumeration<SearchResult> answer = ctx.search(

ldap_provider_url + ldap_search_context,

"(&({0}={1}))", new Object[] { ldap_id_field,

netid }, ctrls);

while (answer.hasMoreElements()) {SearchResult sr =

answer.next(); if

(StringUtils.isEmpty(ldap_search_context)) { resultDN = sr.getName(); } else { resultDN = (sr.getName() + "," +

ldap_search_context); }

String attlist[] = {ldap_email_field, ldap_givenname_field,

ldap_surname_field, ldap_phone_field};

Attributes atts = sr.getAttributes();

Attribute att;

if (attlist[0] != null) {att =

atts.get(attlist[0]);if (att != null)

ldapEmail = (String) att.get();

}

if (attlist[1] != null) {att =

atts.get(attlist[1]);if (att != null)

ldapGivenName = (String) att.get();

}

if (attlist[2] != null) {att =

atts.get(attlist[2]);if (att != null)

ldapSurname =

29

Page 30: sLibrary@SystemInstallationGuide

(String) att.get();}

if (attlist[3] != null) {att =

atts.get(attlist[3]);if (att != null)

ldapPhone = (String) att.get();

}

if (answer.hasMoreElements()) {// Oh dear - more than

one match// Ambiguous user, can't

continue

} else {

log.debug(LogManager.getHeader(context, "got DN", resultDN));return resultDN;

}}

}catch (NamingException e){

// if the lookup fails go ahead and create a new record for them because the authentication

// succeeded

log.warn(LogManager.getHeader(context,"ldap_attribute_loo

kup", "type=failed_search "+ e));

}}catch (NamingException e){

log.warn(LogManager.getHeader(context,"ldap_authentication",

"type=failed_auth " + e));}finally{

// Close the context when we're donetry{

if (ctx != null)ctx.close();

}catch (NamingException e){}

}

// No DN match foundreturn null;

}

30

Page 31: sLibrary@SystemInstallationGuide

/** * contact the ldap server and attempt to authenticate */

protected boolean ldapAuthenticate(String netid, String password,

Context context) {System.out.println("ldapAuthenticate");

// if (!password.equals("")) {// Set up environment for creating initial

contextHashtable<String, String> env = new

Hashtable<String, String>();

env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFacto

ry");env.put(javax.naming.Context.PROVIDER_URL,

ldap_provider_url);

// Authenticate

env.put(javax.naming.Context.SECURITY_AUTHENTICATION, "Simple");

env.put(javax.naming.Context.SECURITY_PRINCIPAL, netid);//

env.put(javax.naming.Context.SECURITY_CREDENTIALS, password);// env.put(javax.naming.Context.AUTHORITATIVE, "true");

env.put(javax.naming.Context.AUTHORITATIVE, "false");

env.put(javax.naming.Context.REFERRAL, "follow");

DirContext ctx = null;try {

// Try to bindctx = new InitialDirContext(env);

} catch (NamingException e) {

log.warn(LogManager.getHeader(context,"ldap_authentication",

"type=failed_auth " + e));return false;

} finally {// Close the context when we're donetry {

if (ctx != null)ctx.close();

} catch (NamingException e) {}

}// } else {// return false;// }

return true;}

}}

31

Page 32: sLibrary@SystemInstallationGuide

Thay thế file chooser.jsp trong folder [DSPACE_Source]\dspace\target\dspace-1.6.0-build.dir\webapps\jspui\login\

<%@ page contentType="text/html;charset=UTF-8" %>

<%@ page import="java.util.Iterator" %>

<%@ page import="javax.servlet.jsp.jstl.fmt.LocaleSupport" %>

<%@ page import="java.sql.SQLException" %>

<%@ page import="org.apache.log4j.Logger" %>

<%@ page import="org.dspace.app.webui.util.JSPManager" %><%@ page import="org.dspace.app.webui.util.UIUtil" %><%@ page import="org.dspace.authenticate.AuthenticationManager" %><%@ page import="org.dspace.authenticate.AuthenticationMethod" %><%@ page import="org.dspace.core.Context" %><%@ page import="org.dspace.core.LogManager" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<%@ taglib uri="http://www.dspace.org/dspace-tags.tld" prefix="dspace" %>

<%@page import="org.dspace.authenticate.CASAuthentication"%><%@page import="org.dspace.core.ConfigurationManager"%><%@page import="org.dspace.app.webui.util.Authenticate"%>

<%@page import="java.util.Locale"%><%@page import="org.dspace.core.I18nUtil"%><%@page import="javax.servlet.jsp.jstl.core.Config"%><dspace:layout navbar="off" locbar="off" titlekey="jsp.login.chooser.title" nocache="true">

<table border="0" width="90%"> <tr> <td align="left"> <%-- <H1>Log In to DSpace</H1> --%> <h1><fmt:message key="jsp.login.chooser.heading"/></h1> </td> <td align="right" class="standard"> <dspace:popup page="<%= LocaleSupport.getLocalizedMessage(pageContext, \"help.index\") + \"#login\" %>"><fmt:message key="jsp.help"/></dspace:popup> </td> </tr> </table> <p></p> <table class="miscTable" align="center" width="70%"> <tr> <td class="evenRowEvenCol"> <h2><fmt:message key="jsp.login.chooser.chooseyour"/></h2>

32

Page 33: sLibrary@SystemInstallationGuide

<ul> <% Iterator ai = AuthenticationManager.authenticationMethodIterator(); AuthenticationMethod am; Context context = null; try { context = UIUtil.obtainContext(request); int count = 0; String url = null; //---------------------------------- them moi

final String ticket = (String)request.getParameter("ticket"); final String service = (String)request.getRequestURL().toString(); String validate = ConfigurationManager.getProperty("cas.validate.url"); if (ticket != null){ CASAuthentication cas = new CASAuthentication(); int result = cas.authenticate(context, null, null, null, request);

%>

<%= result %><%= AuthenticationMethod.SUCCESS %><%

if (result == AuthenticationMethod.SUCCESS) { // Logged in OK. Authenticate.loggedIn(context, request, context.getCurrentUser()); // Set the Locale according to user preferences Locale epersonLocale = I18nUtil.getEPersonLocale(context.getCurrentUser()); context.setCurrentLocale(epersonLocale); Config.set(request.getSession(), Config.FMT_LOCALE, epersonLocale);

String index =

ConfigurationManager.getProperty("dspace.url"); //response.encodeRedirectURL(index);

request.getSession().setAttribute("serviceLogout", "serviceLogout");System.out.println("setbien de logout");

JSPManager.showJSP(request, response, "/index.jsp"); } } //---------------------------------- them moi if (ticket == null){ while (ai.hasNext()) { am = (AuthenticationMethod)ai.next();

33

Page 34: sLibrary@SystemInstallationGuide

if ((url = am.loginPageURL(context, request, response)) != null) { %> <li><p><strong><a href="<%= url %>">

<%-- This kludge is necessary because fmt:message won't evaluate its attributes, so we can't use it on java expr --%> <%= javax.servlet.jsp.jstl.fmt.LocaleSupport.getLocalizedMessage(pageContext, am.loginPageTitle(context)) %> </a></strong></p></li><% } } } } catch(SQLException se) { // Database error occurred. Logger log = Logger.getLogger("org.dspace.jsp"); log.warn(LogManager.getHeader(context, "database_error", se.toString()), se);

// Also email an alert UIUtil.sendAlert(request, se); JSPManager.showInternalError(request, response); } finally { context.abort(); } %> </ul> </td> </tr> </table>

</dspace:layout>

3. Thay thế file LogoutServlet.java trong folder [DSPACE_Source]\dspace-jspui\dspace-jspui-api\src\main\java\org\dspace\app\webui\servlet để đăng xuất ra khỏi CASServer

package org.dspace.app.webui.servlet;

import java.io.IOException;import java.sql.SQLException;

import javax.servlet.RequestDispatcher;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

34

Page 35: sLibrary@SystemInstallationGuide

import org.dspace.app.webui.util.Authenticate;import org.dspace.app.webui.util.JSPManager;import org.dspace.authorize.AuthorizeException;import org.dspace.core.ConfigurationManager;import edu.yale.its.tp.cas.client.ServiceTicketValidator;import edu.yale.its.tp.cas.util.SecureURL;import org.dspace.core.Context;import org.dspace.core.LogManager;

/** * Servlet that logs out any current user if invoked. * * @author Robert Tansley * @version $Revision: 3705 $ */public class LogoutServlet extends DSpaceServlet{ /** log4j logger */ private static Logger log = Logger.getLogger(LogoutServlet.class);

protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { log.info(LogManager.getHeader(context, "logout", ""));

String urlLogout = ""; String serviceLogout = (String)request.getSession().getAttribute("serviceLogout"); if(serviceLogout == null){ // Display logged out message

urlLogout = "/login/logged-out.jsp"; Authenticate.loggedOut(context, request); JSPManager.showJSP(request, response, urlLogout);

} if(serviceLogout != null) {

String casLogout = ConfigurationManager.getProperty("cas.logout.url"); String homeApplication = ConfigurationManager.getProperty("dspace.url.logout"); // ServiceTicketValidator stv = new ServiceTicketValidator(); //stv.setRenew(true); // request.getSession().removeAttribute("serviceLogout");

request.getSession().removeAttribute("serviceLogout");System.out.println(" logout");

urlLogout = casLogout+"?url="+homeApplication; Authenticate.loggedOut(context, request);

35

Page 36: sLibrary@SystemInstallationGuide

response.sendRedirect(urlLogout); } }}

4.3.4.2.3Cấu hình xác thực qua CAS và LDAP trong file dspace.cfg

Yêu cầu:

Làm việc với CAS 2.0 nghia là: user/net ID nhận được tư CAS là định dạng XML

Yêu cầu thư viện Cas Client – đưa vào lib của ứng dụng theo bước 5.1.1

Yêu cầu sư dụng giao thức bảo mật https để giao tiếp với CasServer

Sư dụng ID của người dùng (qua trình duyệt web) tư CasServer khi xác thực thành công – chứ không phải lây email

Cách câu hình: Thay đổi file dspace.cfg trong [DSPACE SOURCE]\dspace\config

plugin.sequence.org.dspace.eperson.AuthenticationMethod = \org.dspace.eperson.CASAuthentication

dspace.url = https://hcmuaf.edu.vn:8080/dspace/index.jspdspace.url.logout = http://dspace.myftp.org:8080/dspace/logout

##cas.server.url= URL đến trang đăng nhập CAS.cas.server.url= https://hcmuaf.edu.vn:8443/cas/login

## cas.validate.url= URL nơi một CAS ticket có thể được xác nhậncas.validate.url= https://hcmuaf.edu.vn:8443/cas/serviceValidate

##cas.logout.url= URL đến trang đăng xuất CAScas.logout.url= https://hcmuaf.edu.vn:8443/cas/logout

## tạo người dùng trong ứng dụng sau xác thực thành côngwebui.cas.autoregister = true

Config LDAP để làm việc với CASServer trong file dspace.cfg

# ví dụ có nhánh quản lí user trong LDAP là : o=it,dc=hcmuaf,dc=edu,dc=vn

# Mở kết nối LDAPldap.enable = true

# Url kết nối đến LDAPldap.provider_url = ldap://localhost:389/

# Thiết lập trường để tìm kiếm có thể là UIL hoặc emailldap.id_field = uid

36

Page 37: sLibrary@SystemInstallationGuide

# Đối tượng và url tìm kiếmldap.object_context = o=it,dc=hcmuaf,dc=edu,dc=vnldap.search_context = dc=hcmuaf,dc=edu,dc=vn

# Thiết lập các trường khác để lấy dữ liệu người dùngldap.email_field = mailldap.surname_field = snldap.givenname_field = givenNameldap.phone_field = telephoneNumber

# Bật tính năng tự động cập nhật tài khoản người dùngwebui.ldap.autoregister = true

# Xác định giới hạn tìm kiếmldap.search_scope = 2

# Thông tin đăng nhập của quản trị LDAP serverldap.search.user = cn=Directory Managerldap.search.password = admin

Tiến hành rebuild lại ứng dụng

4.3.4.2.4Rebuild gói ứng dụng DSpace

Chạy dong lệnh sau trong cmd (tư thư mục [dspace-source]/dspace/ ):

Cd [dspace-source]/dspace/

mvn package

4.3.4.2.5Cập nhật tất cả các thư mục DSpace webapps tại [dspace]/webapps

Chạy dong lệnh sau trong cmd (tư thư mục [dspace-source]/dspace/target/dspace-[version]-build.dir ):

Cd [dspace-source]/dspace/target/dspace-[version]-build.dir

Ant update

Hoặc

Cd [dspace-source]/dspace/target/dspace-[version]-build.dir

ant -Dconfig=[dspace]/config/dspace.cfg update

## Deploy the the new webapps:

37

Page 38: sLibrary@SystemInstallationGuide

cp -R /[dspace]/webapps/* /[tomcat]/webapps

4.3.4.2.6Khởi đông lại webserver Tomcat

- Windown: vào thư mục bin trong thư mục cài đặt Tomcat chạy file startup.bat

- Unix/ Linux: vào thư mục bin trong thư mục cài đặt Tomcat chạy file startup.sh

5 Thuật Ngữ

6 Tham Khảo

38