記錄、分享

          2013年1月31日

          spring-security3 入門篇[轉(zhuǎn)載]

          1.下載spring security的最新版本,工程下載的是3.1

          2. 新建工程,結(jié)構(gòu)如下:



           其中,涉及到的jar包可以在spring-security包中的例子中獲取

          3、配置spring-security.xml

          Xml代碼  收藏代碼
          1. <? xml   version = "1.0"   encoding = "UTF-8" ?>   
          2. < beans   xmlns = "http://www.springframework.org/schema/beans"   
          3.     xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"   xmlns:security ="http://www.springframework.org/schema/security"   
          4.     xsi:schemaLocation ="http://www.springframework.org/schema/beans   
          5.             http://www.springframework.org/schema/beans/spring-beans.xsd  
          6.             http://www.springframework.org/schema/security   
          7.             http://www.springframework.org/schema/security/spring-security.xsd">   
          8.   
          9.     <!-- 保護(hù)應(yīng)用程序的所有URL,只有擁有ROLE_USER才可以訪問 -->   
          10.     < security:http   auto-config = "true" >   
          11.         < security:intercept-url   pattern = "/**"   access = "ROLE_USER"   />   
          12.     </ security:http >   
          13.       
          14.     <!--配置認(rèn)證管理器,只有用戶名為user,密碼為user的用戶,角色為ROLE_USER可訪問指定的資源 -->  
          15.     < security:authentication-manager >   
          16.         < security:authentication-provider >   
          17.             < security:user-service >   
          18.                 < security:user   name = "user"    password = "user"   authorities ="ROLE_USER" />   
          19.             </ security:user-service >   
          20.         </ security:authentication-provider >   
          21.     </ security:authentication-manager >   
          22. </ beans >   

           4.配置web.xml

          Xml代碼  收藏代碼
          1. <? xml   version = "1.0"   encoding = "UTF-8" ?>   
          2. < web-app   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"   xmlns ="http://java.sun.com/xml/ns/javaee"   xmlns:web ="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"   xsi:schemaLocation ="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  id = "WebApp_ID"   version = "2.5" >   
          3.   < display-name > springSecurity </ display-name >   
          4.     <!--******************************** -->   
          5.     <!--*******log4j日志信息的配置****** -->   
          6.     <!--******************************* -->   
          7.     < context-param >   
          8.         < param-name > log4jConfigLocation </ param-name >   
          9.         < param-value > classpath:log4j.xml </ param-value >   
          10.     </ context-param >   
          11.     <!--Spring默認(rèn)刷新Log4j配置文件的間隔,單位為millisecond,可以不設(shè)置 -->   
          12.     < context-param >   
          13.         < param-name > log4jRefreshInterval </ param-name >   
          14.         < param-value > 60000 </ param-value >   
          15.     </ context-param >   
          16.   
          17.     <!--******************************** -->   
          18.     <!--*******spring bean的配置******** -->   
          19.     <!--******************************* -->   
          20.     < context-param >   
          21.         < param-name > contextConfigLocation </ param-name >   
          22.         < param-value > classpath:applicationContext.xml </ param-value >   
          23.     </ context-param >   
          24.       
          25.     < listener >   
          26.         < listener-class > org.springframework.web.util.Log4jConfigListener </listener-class >   
          27.     </ listener >   
          28.     < listener >   
          29.         < listener-class > org.springframework.web.context.ContextLoaderListener </listener-class >   
          30.     </ listener >   
          31.     < listener >   
          32.         < listener-class > org.springframework.web.util.IntrospectorCleanupListener </listener-class >   
          33.     </ listener >   
          34.     <!--******************************** -->   
          35.     <!--*******字符集 過濾器************ -->   
          36.     <!--******************************* -->   
          37.     < filter >   
          38.         < filter-name > CharacterEncodingFilter </ filter-name >   
          39.         < filter-class > org.springframework.web.filter.CharacterEncodingFilter </filter-class >   
          40.         < init-param >   
          41.             < param-name > encoding </ param-name >   
          42.             < param-value > UTF-8 </ param-value >   
          43.         </ init-param >   
          44.         < init-param >   
          45.             < param-name > forceEncoding </ param-name >   
          46.             < param-value > true </ param-value >   
          47.         </ init-param >   
          48.     </ filter >   
          49.     < filter-mapping >   
          50.         < filter-name > CharacterEncodingFilter </ filter-name >   
          51.         < url-pattern > /* </ url-pattern >   
          52.     </ filter-mapping >   
          53.   
          54.     <!--******************************** -->   
          55.     <!--*******session的配置************ -->   
          56.     <!--******************************* -->   
          57.     < session-config >   
          58.         < session-timeout > 30 </ session-timeout >   
          59.     </ session-config >   
          60.       
          61.     <!-- SpringSecurity必須的begin -->   
          62.     < filter >   
          63.         < filter-name > springSecurityFilterChain </ filter-name >   
          64.         < filter-class > org.springframework.web.filter.DelegatingFilterProxy </filter-class >   
          65.     </ filter >   
          66.     <!-- 攔截所有的請(qǐng)求 -->   
          67.     < filter-mapping >   
          68.         < filter-name > springSecurityFilterChain </ filter-name >   
          69.         < url-pattern > /* </ url-pattern >   
          70.     </ filter-mapping >   
          71.     <!-- SpringSecurity必須的end -->   
          72.       
          73.   < welcome-file-list >   
          74.     < welcome-file > index.jsp </ welcome-file >   
          75.   </ welcome-file-list >   
          76. </ web-app >   

           

          5.index.jsp

          Html代碼  收藏代碼
          1. < %@ page  language = "java"   contentType = "text/html; charset=UTF-8"   
          2.     pageEncoding = "UTF-8" % >   
          3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">   
          4. < html >   
          5. < head >   
          6. < meta   http-equiv = "Content-Type"   content = "text/html; charset=UTF-8" >   
          7. < title > 首頁(yè) </ title >   
          8. </ head >   
          9. < body >   
          10.     < h1 > 這里是首頁(yè),歡迎你! </ h1 >   
          11.     < %   
          12.         String[] str  =  session .getValueNames();  
          13.         for(int i = 0 ;i < str.length ;i++){  
          14.             out.println("key =="+str[i]);  
          15.             out.println("value =="+session.getAttribute(str[i]));  
          16.         }  
          17.     %>   
          18. </ body >   
          19. </ html >   

           

          6部署應(yīng)用,在首次瀏覽index.jsp時(shí),由于沒登錄,spring security會(huì)自動(dòng)生成登錄頁(yè)面,頁(yè)面內(nèi)容如下:

           



           7輸入用戶名和密碼,user,則進(jìn)入首頁(yè)

           

           

           至此,簡(jiǎn)單的權(quán)限控制完成,在index頁(yè)面中通過session可以看到存入session中的用戶信息。

          posted @ 2013-12-02 19:00 張生 閱讀(324) | 評(píng)論 (0)編輯 收藏

          轉(zhuǎn)載:CentOS6 安裝 Xen 4.1.2

          轉(zhuǎn)載:

          http://www.cnblogs.com/liuan/archive/2012/06/13/2548558.html



          系統(tǒng):CentOS6.0  安裝的Xen版本:4.1.2

          在centos下安裝xen不是很順利,遇到很多問題。安裝過程主要參考了以下兩個(gè)文檔:

          http://wiki.xen.org/xenwiki/RHEL6Xen4Tutorial?action=fullsearch&value=linkto%3A%22RHEL6Xen4Tutorial%22&context=180

          這個(gè)方法可以正常安裝xen,并指出RedHat 6 下安裝xen 會(huì)遇到的問題,只是安裝過程復(fù)雜,不是源碼安裝。

          http://www.cnblogs.com/feisky/archive/2012/04/10/2441307.html

          這個(gè)是xen的源碼編譯安裝,也是centos下,安裝xen 4.1.2,但是經(jīng)過實(shí)踐,這樣安裝出來存在一些問題,很意外的。解決起來很頭痛。

          在上面這個(gè)方法上,具體的描述我的安裝過程。

          系統(tǒng)和安裝的xen版本上面有介紹,開始著手安裝xen了。

          1.下載Xen的源碼

          1 wget http://bits.xensource.com/oss-xen/release/4.1.2/xen-4.1.2.tar.gz

           

          2.安裝必備軟件包

          復(fù)制代碼
          1 yum groupinstall "Development Libraries" 2 yum groupinstall "Development Tools" 3 yum install transfig wget texi2html libaio-devel dev86 glibc-devel e2fsprogs-devel gitk mkinitrd iasl xz-devel 4 bzip2-devel pciutils-libs pciutils-devel SDL-devel libX11-devel gtk2-devel bridge-utils PyXML qemu-common qemu-img mercurial libidn-devel 5 yum -y install glibc-devel.i686texinfo libuuid-devel iasl python-lxml 6 yum -y install openssl openssl-devel 7 yum -y install ncurses ncurses-* 8 yum -y install python-devel
          復(fù)制代碼

           

          3.編譯安裝Xen hypervisor

          1 tar zxvf xen-4.1.2.tar.gz 2 cd xen-4.1.2 3 make world

          在此可能會(huì)遇到如下問題:

          解決辦法:yum –y install texinfo

          1 make install

          4.將Xen加入到啟動(dòng)腳本:

          1 /sbin/chkconfig --add xend 2 /sbin/chkconfig --add xencommons 3 /sbin/chkconfig --add xendomains 4 /sbin/chkconfig xend on 5 /sbin/chkconfig xendomains on 6 /sbin/chkconfig xencommons on

          5.編譯安裝Linux3.1.2內(nèi)核

          復(fù)制代碼
           1 wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.1.2.tar.bz2  2 tar -jxvf linux-3.1.3.tar.bz2  3 make menuconfig  4   5 Processor type and features --- >  6      選中Paravirtualized Guest Support  7   Device Drivers --->   8       Xen driver support --->   9         全部選* 10  11 修改:CONFIG_XEN_DEV_EVTCHN=y(如果是m,開機(jī)時(shí)無法啟動(dòng)xencommons)
          復(fù)制代碼

           注意:僅僅上面的是不夠的,還需要修改:否則在創(chuàng)建虛擬機(jī)的過程中遇到這樣的問題:

          注意:Device 0 (vif) could not be connected. HotPlug scripts not working.

          在.config文件中做如下修改,就可以解決問題了

           

          1 CONFIG_XEN_BLKDEV_BACKEND=m 2 CONFIG_XEN_NETDEV_BACKEND=m

          接下來開始編譯安裝了:

          1 make 2 make modules 3 make modules_install 4 make install  5 depmod 3.1.2 6 mkinitrd -v -f --with=aacraid --with=sd_mod --with=scsi_mod initramfs-3.1.2.img 3.1.2

          6.配置grub:

          復(fù)制代碼
          1 title Xen (3.1.2-xen) 2         root (hd0,0) 3         kernel /xen-4.1.2.gz dom0_mem=512M 4         module /vmlinuz-3.1.2 ro root=UUID=3f920108-b74b-46b9-81c2-aff834494381   5 rd_DM_UUID=ddf1_4c5349202020202010000055000000004711471100001450 rd_NO_LUKS rd_NO_LVM rd_NO_MD LANG=en_US.UTF-8   6 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet 7         module /initramfs-3.1.2.img
          復(fù)制代碼

          這個(gè)配置在第4行后面root=UUID隨自己的系統(tǒng)

          7.安裝virt-manager

          1 yum install libvirt virt-manager xorg-x11-xauth

           8. 重新編譯libvirt

            在文章前面第一個(gè)鏈接中,說明了,redhat6系統(tǒng)中,默認(rèn)的libvirt是不支持xen的,如果直接使用默認(rèn)的這會(huì)出現(xiàn)如下的問題:

            注意virt-manager & 這個(gè)命令中的'&' 代表該進(jìn)程后臺(tái)運(yùn)行

          復(fù)制代碼
           1 [root@el6 ~]# virt-manager &  2 [1] 2867  3 Unable to open connection to hypervisor URI 'xen:///':  4 no connection driver available for xen:///  5 Traceback (most recent call last):  6   File "/usr/share/virt-manager/virtManager/connection.py", line 992, in _try_open  7     None], flags)  8   File "/usr/lib64/python2.6/site-packages/libvirt.py", line 111, in openAuth  9     if ret is None:raise libvirtError('virConnectOpenAuth() failed') 10 libvirtError: no connection driver available for xen:///
          復(fù)制代碼

           開始重新編譯libvirt解決以上的問題。

          以下的操作都在非xen系統(tǒng)中進(jìn)行:

          沒個(gè)系統(tǒng)遇到的缺的包不一樣,我的系統(tǒng)中還缺失xen-devel包,并且在yum

          復(fù)制代碼
           1 [root@el6 ~]# cd /root/src  2 [root@el6 src]# wget ftp://ftp.redhat.com/pub/redhat/linux/enterprise/6Server/en/os/SRPMS/libvirt-0.8.1-27.el6.src.rpm  3 [root@el6 src]# rpm -i libvirt-0.8.1-27.el6.src.rpm  4 [root@el6 src]# wget http://pasik.reaktio.net/xen/patches/libvirt-spec-rhel6-enable-xen.patch  5 [root@el6 src]# cd /root/rpmbuild/SPECS  6 [root@el6 SPECS]# cp -a libvirt.spec libvirt.spec.orig  7 [root@el6 SPECS]# patch -p0 < ~/src/libvirt-spec-rhel6-enable-xen.patch  8 patching file libvirt.spec  9  10 [root@el6 SPECS]# rpmbuild -bb libvirt.spec 11 error: Failed build dependencies: 12         libnl-devel >= 1.1 is needed by libvirt-0.8.1-27.el6.x86_64 13         xhtml1-dtds is needed by libvirt-0.8.1-27.el6.x86_64 14         libudev-devel >= 145 is needed by libvirt-0.8.1-27.el6.x86_64 15         libpciaccess-devel >= 0.10.9 is needed by libvirt-0.8.1-27.el6.x86_64 16         yajl-devel is needed by libvirt-0.8.1-27.el6.x86_64 17         libpcap-devel is needed by libvirt-0.8.1-27.el6.x86_64 18         avahi-devel is needed by libvirt-0.8.1-27.el6.x86_64 19         parted-devel is needed by libvirt-0.8.1-27.el6.x86_64 20         device-mapper-devel is needed by libvirt-0.8.1-27.el6.x86_64 21         numactl-devel is needed by libvirt-0.8.1-27.el6.x86_64 22         netcf-devel >= 0.1.4 is needed by libvirt-0.8.1-27.el6.x86_64 23  [root@el6 SPECS]# yum install libnl-devel xhtml1-dtds libudev-devel libpciaccess-devel yajl-devel libpcap-devel avahi-devel parted-devel device-mapper-devel numactl-devel netcf-devel
          復(fù)制代碼

          安裝的時(shí)候,提示No packages xen-devel available 。

          在多次替換yum源之后,依然無法解決這個(gè)xen-devel包缺失的問題。

          隨后的解決方案如下:

          在網(wǎng)上下載xen-devel rpm 包,安裝遇到依賴問題,接著下載xen-libs rpm 包,接著還有其他的依賴問題,同樣查找。

          具體鏈接: 搜索xen-devel,找到符合系統(tǒng)版本的

          1 http://rpm.pbone.net/index.php3

          我下載的版本是:
          xen-devel-4.1.2_03-1.1.x86_64.rpm

          安裝xen-devel還依賴其他的包,如下:

          xen-libs-4.1.2_03-1.1.x86_64.rpm

          liblzma5-5.0.3-7.1.x86_64.rpm

          glibc-common-2.14.90-14.x86_64.rpm

          glibc-2.14.90-14.x86_64.rpm

          強(qiáng)制安裝如上的包。

          如果缺少依賴包,依次去下載對(duì)應(yīng)版本,解決問題。這個(gè)過程很蛋疼。

          如果所有的依賴包都安裝上后,接著下面的操作:

          復(fù)制代碼
          1 [root@gb31 SPECS]# rpmbuild -bb libvirt.spec 2 After a while you'll see:  3 Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-0.8.1-27.el6.x86_64.rpm 4 Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-client-0.8.1-27.el6.x86_64.rpm 5 Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-devel-0.8.1-27.el6.x86_64.rpm 6 Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-python-0.8.1-27.el6.x86_64.rpm 7 Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-debuginfo-0.8.1-27.el6.x86_64.rpm
          復(fù)制代碼

          如果有如上的顯示則安裝成功。

          如果遇到屏幕顯示test 。。 一直卡住之后,卸載掉系統(tǒng)中已經(jīng)安裝的libvirt包,再重新嘗試,即可。
          接著如下:注意,可能版本不一樣

          如果還顯示存在test失敗,make失敗,與libvirt版本相關(guān),這個(gè)問題很蛋疼,多試下幾個(gè)版本吧。就可以解決。

          復(fù)制代碼
          1 [root@el6 ~]# cd /root/rpmbuild/RPMS/x86_64/ 2 [root@el6 x86_64]# rpm -Uvh --force libvirt-0.8.1-27.el6.x86_64.rpm libvirt-client-0.8.1-27.el6.x86_64.rpm libvirt-python-0.8.1-27.el6.x86_64.rpm 3 Preparing...                ########################################### [100%] 4    1:libvirt-client         ########################################### [ 33%] 5    2:libvirt                ########################################### [ 67%] 6    3:libvirt-python         ########################################### [100%]
          復(fù)制代碼

          9.進(jìn)入xen系統(tǒng)

          重啟系統(tǒng),進(jìn)入xen系統(tǒng)。

          嘗試輸入如下命令:xm-list ,xm-info

          再接著嘗試如下命令:virt-install,嘗試著安裝虛擬機(jī)

          如果顯示的錯(cuò)誤如下:

          1 ERROR unable to connect to ‘localhost:8000′: Connection refused

          則需要去做如下修改:

          1 解決方案:查看libvirtd服務(wù)是否啟動(dòng),關(guān)閉防火墻,在/etc/xen/xend-config.sxp  2 (xend-http-server yes) 3 # Port xend should use for the HTTP interface, if xend-http-server is set. 4 (xend-port 8000) 5 去掉上面兩個(gè)括弧的注釋,ok

          再重新啟動(dòng)xend服務(wù)

          1 service xend restart

           

          至此,可以嘗試在桌面上氣筒virtual machine manager 去創(chuàng)建虛擬機(jī)。
          創(chuàng)建過程如果如下問題:

          可以系統(tǒng)路勁的問題,在usr/lib/xen/bin下找到qemu-dm放到lib64下對(duì)應(yīng)的路徑。

          就ok。

           

          10.配置網(wǎng)橋橋接模式

          修改ifcfg-eth0如下:

          復(fù)制代碼
           1 DEVICE="eth0"  2 BOOTPROTO="static"  3 HWADDR="**********“  4 NM_CONTROLLED="no"  5 ONBOOT="yes"  6 IPADDR="*******”  7 NETMASK="255.255.0.0"  8 GATEWAY="********"  9 TYPE=Ethernet 10 DNS1="8.8.8.8" 11 DNS2="8.8.4.4" 12 BRIDGE=br100
          復(fù)制代碼

          創(chuàng)建ifcfg-br100文件,內(nèi)容如下:

          復(fù)制代碼
           1 DEVICE="br100"  2 BOOTPROTO="static"  3 HWADDR="*********"  4 NM_CONTROLLED="no"  5 ONBOOT="yes"  6 IPADDR="*******"  7 NETMASK="255.255.0.0"  8 GATEWAY="*******"  9 TYPE=Bridge 10 DEFROUTE=yes 11 DNS1="8.8.8.8" 12 DNS2="8.8.4.4"
          復(fù)制代碼

          11.ok,至此,xen的安裝結(jié)束了,可以放心大膽的創(chuàng)建虛擬機(jī)了。

          posted @ 2013-01-31 11:13 張生 閱讀(1668) | 評(píng)論 (0)編輯 收藏

          <2013年1月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 南陵县| 沙湾县| 和顺县| 通河县| 准格尔旗| 海原县| 甘南县| 双辽市| 肇州县| 调兵山市| 广安市| 辛集市| 文登市| 阳原县| 乐平市| 二连浩特市| 九江县| 武定县| 武夷山市| 武清区| 滨州市| 昔阳县| 新建县| 枣强县| 全椒县| 阳东县| 大城县| 休宁县| 汨罗市| 昆明市| 金塔县| 阳原县| 康保县| 祁连县| 建水县| 南雄市| 韶关市| 临海市| 武安市| 盐池县| 资溪县|