Browse Source

add db init script for pgsql

add data-context example with pgsql db initializer
pull/1079/merge
Neths 8 years ago committed by Justin Richer
parent
commit
cbe6b9e1df
  1. 66
      openid-connect-server-webapp/src/main/resources/db/psql/clients.sql
  2. 33
      openid-connect-server-webapp/src/main/resources/db/psql/scopes.sql
  3. 55
      openid-connect-server-webapp/src/main/resources/db/psql/users.sql
  4. 9
      openid-connect-server-webapp/src/main/webapp/WEB-INF/data-context.xml

66
openid-connect-server-webapp/src/main/resources/db/psql/clients.sql

@ -0,0 +1,66 @@
--
-- Turn off autocommit and start a transaction so that we can use the temp tables
--
--SET AUTOCOMMIT = OFF;
START TRANSACTION;
--
-- Insert client information into the temporary tables. To add clients to the HSQL database, edit things here.
--
INSERT INTO client_details_TEMP (client_id, client_secret, client_name, dynamically_registered, refresh_token_validity_seconds, access_token_validity_seconds, id_token_validity_seconds, allow_introspection) VALUES
('client', 'secret', 'Test Client', false, null, 3600, 600, true);
INSERT INTO client_scope_TEMP (owner_id, scope) VALUES
('client', 'openid'),
('client', 'profile'),
('client', 'email'),
('client', 'address'),
('client', 'phone'),
('client', 'offline_access');
INSERT INTO client_redirect_uri_TEMP (owner_id, redirect_uri) VALUES
('client', 'http://localhost/'),
('client', 'http://localhost:8080/');
INSERT INTO client_grant_type_TEMP (owner_id, grant_type) VALUES
('client', 'authorization_code'),
('client', 'urn:ietf:params:oauth:grant_type:redelegate'),
('client', 'implicit'),
('client', 'refresh_token');
--
-- Merge the temporary clients safely into the database. This is a two-step process to keep clients from being created on every startup with a persistent store.
--
INSERT INTO client_details (client_id, client_secret, client_name, dynamically_registered, refresh_token_validity_seconds, access_token_validity_seconds, id_token_validity_seconds, allow_introspection)
SELECT client_id, client_secret, client_name, dynamically_registered, refresh_token_validity_seconds, access_token_validity_seconds, id_token_validity_seconds, allow_introspection FROM client_details_TEMP
ON CONFLICT
DO NOTHING;
INSERT INTO client_scope (scope)
SELECT scope FROM client_scope_TEMP, client_details WHERE client_details.client_id = client_scope_TEMP.owner_id
ON CONFLICT
DO NOTHING;
INSERT INTO client_redirect_uri (redirect_uri)
SELECT redirect_uri FROM client_redirect_uri_TEMP, client_details WHERE client_details.client_id = client_redirect_uri_TEMP.owner_id
ON CONFLICT
DO NOTHING;
INSERT INTO client_grant_type (grant_type)
SELECT grant_type FROM client_grant_type_TEMP, client_details WHERE client_details.client_id = client_grant_type_TEMP.owner_id
ON CONFLICT
DO NOTHING;
--
-- Close the transaction and turn autocommit back on
--
COMMIT;
--SET AUTOCOMMIT = ON;

33
openid-connect-server-webapp/src/main/resources/db/psql/scopes.sql

@ -0,0 +1,33 @@
--
-- Turn off autocommit and start a transaction so that we can use the temp tables
--
--SET AUTOCOMMIT = OFF;
START TRANSACTION;
--
-- Insert scope information into the temporary tables.
--
INSERT INTO system_scope_TEMP (scope, description, icon, restricted, default_scope, structured, structured_param_description) VALUES
('openid', 'log in using your identity', 'user', false, true, false, null),
('profile', 'basic profile information', 'list-alt', false, true, false, null),
('email', 'email address', 'envelope', false, true, false, null),
('address', 'physical address', 'home', false, true, false, null),
('phone', 'telephone number', 'bell', false, true, false, null),
('offline_access', 'offline access', 'time', false, false, false, null);
--
-- Merge the temporary scopes safely into the database. This is a two-step process to keep scopes from being created on every startup with a persistent store.
--
INSERT INTO system_scope (scope, description, icon, restricted, default_scope, structured, structured_param_description)
SELECT scope, description, icon, restricted, default_scope, structured, structured_param_description FROM system_scope_TEMP
ON CONFLICT(scope)
DO NOTHING;
COMMIT;
--SET AUTOCOMMIT = ON;

55
openid-connect-server-webapp/src/main/resources/db/psql/users.sql

@ -0,0 +1,55 @@
--
-- Turn off autocommit and start a transaction so that we can use the temp tables
--
--SET AUTOCOMMIT FALSE;
START TRANSACTION;
--
-- Insert user information into the temporary tables. To add users to the HSQL database, edit things here.
--
INSERT INTO users_TEMP (username, password, enabled) VALUES
('admin','password',true),
('user','password',true);
INSERT INTO authorities_TEMP (username, authority) VALUES
('admin','ROLE_ADMIN'),
('admin','ROLE_USER'),
('user','ROLE_USER');
-- By default, the username column here has to match the username column in the users table, above
INSERT INTO user_info_TEMP (sub, preferred_username, name, email, email_verified) VALUES
('90342.ASDFJWFA','admin','Demo Admin','admin@example.com', true),
('01921.FLANRJQW','user','Demo User','user@example.com', true);
--
-- Merge the temporary users safely into the database. This is a two-step process to keep users from being created on every startup with a persistent store.
--
INSERT INTO users
SELECT username, password, enabled FROM users_TEMP
ON CONFLICT(username)
DO NOTHING;
INSERT INTO authorities
SELECT username, authority FROM authorities_TEMP
ON CONFLICT(username, authority)
DO NOTHING;
INSERT INTO user_info (sub, preferred_username, name, email, email_verified)
SELECT sub, preferred_username, name, email, email_verified FROM user_info_TEMP
ON CONFLICT
DO NOTHING;
--
-- Close the transaction and turn autocommit back on
--
COMMIT;
--SET AUTOCOMMIT TRUE;

9
openid-connect-server-webapp/src/main/webapp/WEB-INF/data-context.xml

@ -74,6 +74,15 @@
<property name="password" value="oic" /> <property name="password" value="oic" />
</bean> </bean>
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="classpath:/db/tables/psql_database_tables.sql"/>
<jdbc:script location="classpath:/db/tables/security-schema.sql"/>
<jdbc:script location="classpath:/db/tables/loading_temp_tables.sql"/>
<jdbc:script location="classpath:/db/psql/users.sql"/>
<jdbc:script location="classpath:/db/psql/clients.sql"/>
<jdbc:script location="classpath:/db/psql/scopes.sql"/>
</jdbc:initialize-database>
<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"> <bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="databasePlatform" value="org.eclipse.persistence.platform.database.PostgreSQLPlatform" /> <property name="databasePlatform" value="org.eclipse.persistence.platform.database.PostgreSQLPlatform" />
<property name="showSql" value="true" /> <property name="showSql" value="true" />

Loading…
Cancel
Save