The CalendarUser authority SQL

You can view the CalendarUser authority mappings in the following code snippet:

    //src/main/resources/database/h2/calendar-authorities.sql

create table calendar_user_authorities (
id bigint identity,
calendar_user bigint not null,
authority varchar(256) not null,
);
-- user1@example.com
insert into calendar_user_authorities(calendar_user, authority)
select id,'ROLE_USER' from calendar_users where
email='user1@example.com';
-- admin1@example.com
insert into calendar_user_authorities(calendar_user, authority)
select id,'ROLE_ADMIN' from calendar_users where
email='admin1@example.com';
insert into calendar_user_authorities(calendar_user, authority)
select id,'ROLE_USER' from calendar_users where
email='admin1@example.com';
-- user2@example.com
insert into calendar_user_authorities(calendar_user, authority)
select id,'ROLE_USER' from calendar_users where
email='user2@example.com';

Notice that we use the id as the foreign key, which is better than utilizing the username as a foreign key (as Spring Security does). By using the id as the foreign key, we can allow users to easily change their username.