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