在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>