Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANGED:switch to H2 Database for more easier demostration; #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions polling-app-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ protected void configure(HttpSecurity http) throws Exception {
.permitAll()
.antMatchers(HttpMethod.GET, "/api/polls/**", "/api/users/**")
.permitAll()
.antMatchers("/h2-console/**")
.permitAll()
.anyRequest()
.authenticated();

// Add our custom JWT security filter
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);

// Allow H2-console
http.headers().frameOptions().sameOrigin();
}
}
10 changes: 6 additions & 4 deletions polling-app-server/src/main/resources/application.properties
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ server.port= 8080
server.compression.enabled=true

## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url= jdbc:mysql://localhost:3306/polling_app?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
spring.datasource.username= root
spring.datasource.password= callicoder

# spring.datasource.url= jdbc:mysql://localhost:3306/polling_app?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
# spring.datasource.username= root
# spring.datasource.password= callicoder
# Enabling H2 Console
spring.h2.console.enabled=true

## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
Expand All @@ -18,6 +19,7 @@ logging.level.org.hibernate.SQL= DEBUG

# Initialize the datasource with available DDL and DML scripts
spring.datasource.initialization-mode=always
#spring.datasource.data=classpath:/db/migration/V1__schema.sql,classpath:/db/migration/V2__default_roles.sql

## Jackson Properties
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS= false
Expand Down
6 changes: 4 additions & 2 deletions polling-app-server/src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
INSERT IGNORE INTO roles(name) VALUES('ROLE_USER');
INSERT IGNORE INTO roles(name) VALUES('ROLE_ADMIN');
--INSERT IGNORE INTO roles(name) VALUES('ROLE_USER');
--INSERT IGNORE INTO roles(name) VALUES('ROLE_ADMIN');
INSERT INTO roles(name) VALUES('ROLE_USER');
INSERT INTO roles(name) VALUES('ROLE_ADMIN');
21 changes: 11 additions & 10 deletions polling-app-server/src/main/resources/db/migration/V1__schema.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(40) NOT NULL,
Expand All @@ -11,25 +12,25 @@ CREATE TABLE `users` (
UNIQUE KEY `uk_users_email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


--DROP TABLE IF EXISTS `roles`;
CREATE TABLE `roles` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(60) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_roles_name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;


--DROP TABLE IF EXISTS `user_roles`;
CREATE TABLE `user_roles` (
`user_id` bigint(20) NOT NULL,
`role_id` bigint(20) NOT NULL,
PRIMARY KEY (`user_id`,`role_id`),
KEY `fk_user_roles_role_id` (`role_id`),
-- KEY `fk_user_roles_role_id` (`role_id`),
CONSTRAINT `fk_user_roles_role_id` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`),
CONSTRAINT `fk_user_roles_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


--DROP TABLE IF EXISTS `polls`;
CREATE TABLE `polls` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`question` varchar(140) NOT NULL,
Expand All @@ -41,17 +42,17 @@ CREATE TABLE `polls` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


--DROP TABLE IF EXISTS `choices`;
CREATE TABLE `choices` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`text` varchar(40) NOT NULL,
`poll_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_choices_poll_id` (`poll_id`),
-- KEY `fk_choices_poll_id` (`poll_id`),
CONSTRAINT `fk_choices_poll_id` FOREIGN KEY (`poll_id`) REFERENCES `polls` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


--DROP TABLE IF EXISTS `votes`;
CREATE TABLE `votes` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NOT NULL,
Expand All @@ -60,9 +61,9 @@ CREATE TABLE `votes` (
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `fk_votes_user_id` (`user_id`),
KEY `fk_votes_poll_id` (`poll_id`),
KEY `fk_votes_choice_id` (`choice_id`),
-- KEY `fk_votes_user_id` (`user_id`),
-- KEY `fk_votes_poll_id` (`poll_id`),
-- KEY `fk_votes_choice_id` (`choice_id`),
CONSTRAINT `fk_votes_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
CONSTRAINT `fk_votes_poll_id` FOREIGN KEY (`poll_id`) REFERENCES `polls` (`id`),
CONSTRAINT `fk_votes_choice_id` FOREIGN KEY (`choice_id`) REFERENCES `choices` (`id`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
INSERT IGNORE INTO roles(name) VALUES('ROLE_USER');
INSERT IGNORE INTO roles(name) VALUES('ROLE_ADMIN');
--INSERT IGNORE INTO roles(name) VALUES('ROLE_USER');
--INSERT IGNORE INTO roles(name) VALUES('ROLE_ADMIN');
INSERT INTO roles(name) VALUES('ROLE_USER');
INSERT INTO roles(name) VALUES('ROLE_ADMIN');