appendix-db-schema.xml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <appendix version="5.0" xml:id="appendix-schema" xmlns="http://docbook.org/ns/docbook"
  3. xmlns:xlink="http://www.w3.org/1999/xlink"
  4. xmlns:xi="http://www.w3.org/2001/XInclude">
  5. <info>
  6. <title>Security Database Schema</title>
  7. </info>
  8. <para>
  9. There are various database schema used by the framework and this appendix
  10. provides a single reference point to them all. You only need to
  11. provide the tables for the areas of functonality you require.
  12. </para>
  13. <para>
  14. DDL statements are given for the HSQLDB database. You can use these as a guideline for defining the
  15. schema for the database you are using.
  16. </para>
  17. <section>
  18. <title>User Schema</title>
  19. <para>
  20. The standard JDBC implementation of the <interfacename>UserDetailsService</interfacename> requires tables
  21. to load the password, account status (enabled or disabled) and a list of authorities (roles) for the user.
  22. <programlisting xml:id="db_schema_users_authorities">
  23. create table users(
  24. username varchar_ignorecase(50) not null primary key,
  25. password varchar_ignorecase(50) not null,
  26. enabled boolean not null);
  27. create table authorities (
  28. username varchar_ignorecase(50) not null,
  29. authority varchar_ignorecase(50) not null,
  30. constraint fk_authorities_users foreign key(username) references users(username));
  31. create unique index ix_auth_username on authorities (username,authority);;
  32. </programlisting>
  33. </para>
  34. <section>
  35. <title>Group Authorities</title>
  36. <para>
  37. Spring Security 2.0 introduced support for group authorities
  38. <programlisting xml:id="db-schema-groups">
  39. create table groups (
  40. id bigint generated by default as identity(start with 0) primary key,
  41. group_name varchar_ignorecase(50) not null);
  42. create table group_authorities (
  43. group_id bigint not null,
  44. authority varchar(50) not null,
  45. constraint fk_group_authorities_group foreign key(group_id) references groups(id));
  46. create table group_members (
  47. id bigint generated by default as identity(start with 0) primary key,
  48. username varchar(50) not null,
  49. group_id bigint not null,
  50. constraint fk_group_members_group foreign key(group_id) references groups(id));
  51. </programlisting>
  52. </para>
  53. </section>
  54. </section>
  55. <section>
  56. <title>Persistent Login (Remember-Me) Schema</title>
  57. <para>
  58. <programlisting xml:id="db-schema-remeber-me">
  59. create table persistent_logins (
  60. username varchar(64) not null,
  61. series varchar(64) primary key,
  62. token varchar(64) not null,
  63. last_used timestamp not null);
  64. </programlisting>
  65. </para>
  66. </section>
  67. <section>
  68. <title>ACL Schema</title>
  69. <para>
  70. <programlisting xml:id="dbschema-acl">
  71. create table acl_sid (
  72. id bigint generated by default as identity(start with 100) not null primary key,
  73. principal boolean not null,
  74. sid varchar_ignorecase(100) not null,
  75. constraint unique_uk_1 unique(sid,principal) );
  76. create table acl_class (
  77. id bigint generated by default as identity(start with 100) not null primary key,
  78. class varchar_ignorecase(100) not null,
  79. constraint unique_uk_2 unique(class) );
  80. create table acl_object_identity (
  81. id bigint generated by default as identity(start with 100) not null primary key,
  82. object_id_class bigint not null,
  83. object_id_identity bigint not null,
  84. parent_object bigint,
  85. owner_sid bigint,
  86. entries_inheriting boolean not null,
  87. constraint unique_uk_3 unique(object_id_class,object_id_identity),
  88. constraint foreign_fk_1 foreign key(parent_object)references acl_object_identity(id),
  89. constraint foreign_fk_2 foreign key(object_id_class)references acl_class(id),
  90. constraint foreign_fk_3 foreign key(owner_sid)references acl_sid(id) );
  91. create table acl_entry (
  92. id bigint generated by default as identity(start with 100) not null primary key,
  93. acl_object_identity bigint not null,ace_order int not null,sid bigint not null,
  94. mask integer not null,granting boolean not null,audit_success boolean not null,
  95. audit_failure boolean not null,constraint unique_uk_4 unique(acl_object_identity,ace_order),
  96. constraint foreign_fk_4 foreign key(acl_object_identity) references acl_object_identity(id),
  97. constraint foreign_fk_5 foreign key(sid) references acl_sid(id) );
  98. </programlisting>
  99. </para>
  100. </section>
  101. </appendix>