在Spring Security的官方文檔上面只給出了關於security ACL的hsql指令碼,但是在使用MySQL資料庫時spring沒有明確給出資料庫建立指令碼和配置說明,以下是自己在使用MySQL資料庫時使用到的sql指令碼和配置
sql指令碼如下
CREATE TABLE `acl_class` (<br /> `ID` bigint(20) NOT NULL auto_increment,<br /> `CLASS` varchar(100) NOT NULL,<br /> PRIMARY KEY (`ID`),<br /> UNIQUE KEY `UNIQUE_UK_2` (`CLASS`)<br />) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;<br />CREATE TABLE `acl_entry` (<br /> `ID` bigint(20) NOT NULL auto_increment,<br /> `ACL_OBJECT_IDENTITY` bigint(20) NOT NULL,<br /> `ACE_ORDER` int(11) NOT NULL,<br /> `SID` bigint(20) NOT NULL,<br /> `MASK` int(11) NOT NULL,<br /> `GRANTING` tinyint(1) NOT NULL,<br /> `AUDIT_SUCCESS` tinyint(1) NOT NULL,<br /> `AUDIT_FAILURE` tinyint(1) NOT NULL,<br /> PRIMARY KEY (`ID`),<br /> UNIQUE KEY `UNIQUE_UK_4` (`ACL_OBJECT_IDENTITY`,`ACE_ORDER`),<br /> KEY `SID` (`SID`)<br />) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;<br />CREATE TABLE `acl_object_identity` (<br /> `ID` bigint(20) NOT NULL auto_increment,<br /> `OBJECT_ID_CLASS` bigint(20) NOT NULL,<br /> `OBJECT_ID_IDENTITY` bigint(20) NOT NULL,<br /> `PARENT_OBJECT` bigint(20) default NULL,<br /> `OWNER_SID` bigint(20) default NULL,<br /> `ENTRIES_INHERITING` tinyint(1) NOT NULL,<br /> PRIMARY KEY (`ID`),<br /> UNIQUE KEY `UNIQUE_UK_3` (`OBJECT_ID_CLASS`,`OBJECT_ID_IDENTITY`),<br /> KEY `OWNER_SID` (`OWNER_SID`),<br /> KEY `PARENT_OBJECT` (`PARENT_OBJECT`)<br />) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;<br />CREATE TABLE `acl_sid` (<br /> `ID` bigint(20) NOT NULL auto_increment,<br /> `PRINCIPAL` tinyint(1) NOT NULL,<br /> `SID` varchar(100) NOT NULL,<br /> PRIMARY KEY (`ID`),<br /> UNIQUE KEY `UNIQUE_UK_1` (`PRINCIPAL`,`SID`)<br />) ENGINE=InnoDB DEFAULT CHARSET=latin1;<br />
spring配置片段如下
<beans:bean id="aclService" class="org.springframework.security.acls.jdbc.JdbcMutableAclService"><br /><beans:constructor-arg ref="dataSource" /><br /><beans:constructor-arg ref="lookupStrategy" /><br /><beans:constructor-arg ref="aclCache" /></p><p><beans:property name="classIdentityQuery" value="SELECT @@IDENTITY"/><br /><beans:property name="sidIdentityQuery" value="SELECT @@IDENTITY"/><br /></beans:bean>