Skip to content

Commit d4880bc

Browse files
committed
Add statics
1 parent 61ec48d commit d4880bc

File tree

13 files changed

+245
-66
lines changed

13 files changed

+245
-66
lines changed

pom.xml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,27 @@
8383
<version>0.9.1</version>
8484
</dependency>
8585

86+
<!-- #region Web Jars -->
87+
<!-- Locator -->
88+
<dependency>
89+
<groupId>org.webjars</groupId>
90+
<artifactId>webjars-locator</artifactId>
91+
<version>0.42</version>
92+
</dependency>
93+
<!-- Font Awesome -->
94+
<dependency>
95+
<groupId>org.webjars</groupId>
96+
<artifactId>font-awesome</artifactId>
97+
<version>5.15.4</version>
98+
</dependency>
99+
<!-- Bootstrap -->
100+
<dependency>
101+
<groupId>org.webjars</groupId>
102+
<artifactId>bootstrap</artifactId>
103+
<version>5.1.3</version>
104+
</dependency>
105+
<!-- #endregion -->
106+
86107
<dependency>
87108
<groupId>org.springframework.boot</groupId>
88109
<artifactId>spring-boot-devtools</artifactId>
@@ -160,7 +181,7 @@
160181
<artifactId>jib-maven-plugin</artifactId>
161182
<version>3.1.4</version>
162183
<configuration>
163-
<from>
184+
<from>
164185
<image>openjdk:16</image>
165186
</from>
166187
<to>

src/main/java/com/github/throyer/common/springboot/configurations/SpringSecurityConfiguration.java

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package com.github.throyer.common.springboot.configurations;
22

33
import static com.github.throyer.common.springboot.errors.ValidationHandlers.forbidden;
4-
import static com.github.throyer.common.springboot.utils.Constants.CONFIGURATIONS.EVERY_HTML;
5-
import static com.github.throyer.common.springboot.utils.Constants.CONFIGURATIONS.FIRST;
6-
import static com.github.throyer.common.springboot.utils.Constants.CONFIGURATIONS.SECOND;
7-
import static com.github.throyer.common.springboot.utils.Constants.CONFIGURATIONS.SWAGGER_DOCS;
84
import static com.github.throyer.common.springboot.utils.Constants.SECURITY.ACESSO_NEGADO_URL;
95
import static com.github.throyer.common.springboot.utils.Constants.SECURITY.DAY_MILLISECONDS;
106
import static com.github.throyer.common.springboot.utils.Constants.SECURITY.HOME_URL;
@@ -45,7 +41,7 @@
4541
public class SpringSecurityConfiguration {
4642

4743
@Autowired
48-
private SecurityService authService;
44+
private SecurityService securityService;
4945

5046
@Autowired
5147
private BCryptPasswordEncoder encoder;
@@ -59,13 +55,13 @@ public SpringSecurityConfiguration(@Value("${token.secret}") String secret) {
5955
SpringSecurityConfiguration.SECRET = secret;
6056
}
6157

62-
@Order(FIRST)
58+
@Order(1)
6359
@Configuration
6460
public class Api extends WebSecurityConfigurerAdapter {
6561

6662
@Override
6763
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
68-
auth.userDetailsService(authService)
64+
auth.userDetailsService(securityService)
6965
.passwordEncoder(encoder);
7066
}
7167

@@ -102,7 +98,7 @@ protected void configure(HttpSecurity http) throws Exception {
10298
public void configure(WebSecurity web) throws Exception {
10399
web
104100
.ignoring()
105-
.antMatchers(EVERY_HTML, SWAGGER_DOCS);
101+
.antMatchers(STATIC_FILES);
106102
}
107103

108104
@Bean
@@ -112,13 +108,13 @@ protected AuthenticationManager authenticationManager() throws Exception {
112108
}
113109
}
114110

115-
@Order(SECOND)
111+
@Order(2)
116112
@Configuration
117113
public class App extends WebSecurityConfigurerAdapter {
118114
@Override
119115
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
120116
auth.
121-
userDetailsService(authService)
117+
userDetailsService(securityService)
122118
.passwordEncoder(encoder);
123119
}
124120

@@ -128,38 +124,31 @@ protected void configure(HttpSecurity http) throws Exception {
128124
http
129125
.antMatcher("/app/**")
130126
.authorizeRequests()
131-
.antMatchers(GET, /*LOGIN_URL*/ "/app/**")
127+
.antMatchers(GET, LOGIN_URL)
132128
.permitAll()
133129
.anyRequest()
134-
.authenticated();
135-
// .and()
136-
// .csrf()
137-
// .disable()
138-
// .formLogin()
139-
// .loginPage(LOGIN_URL)
140-
// .failureUrl(LOGIN_ERROR_URL)
141-
// .defaultSuccessUrl(HOME_URL)
142-
// .usernameParameter(USERNAME_PARAMETER)
143-
// .passwordParameter(PASSWORD_PARAMETER)
144-
// .and()
145-
// .rememberMe()
146-
// .key(SECRET)
147-
// .tokenValiditySeconds(DAY_MILLISECONDS)
148-
// .and()
149-
// .logout()
150-
// .deleteCookies(SESSION_COOKIE_NAME)
151-
// .logoutRequestMatcher(new AntPathRequestMatcher(LOGOUT_URL))
152-
// .logoutSuccessUrl(LOGIN_URL)
153-
// .and()
154-
// .exceptionHandling()
155-
// .accessDeniedPage(ACESSO_NEGADO_URL);
130+
.authenticated()
131+
.and()
132+
.csrf()
133+
.disable()
134+
.formLogin()
135+
.loginPage(LOGIN_URL)
136+
.failureUrl(LOGIN_ERROR_URL)
137+
.defaultSuccessUrl(HOME_URL)
138+
.usernameParameter(USERNAME_PARAMETER)
139+
.passwordParameter(PASSWORD_PARAMETER)
140+
.and()
141+
.rememberMe()
142+
.key(SECRET)
143+
.tokenValiditySeconds(DAY_MILLISECONDS)
144+
.and()
145+
.logout()
146+
.deleteCookies(SESSION_COOKIE_NAME)
147+
.logoutRequestMatcher(new AntPathRequestMatcher(LOGOUT_URL))
148+
.logoutSuccessUrl("/app")
149+
.and()
150+
.exceptionHandling()
151+
.accessDeniedPage(ACESSO_NEGADO_URL);
156152
}
157-
158-
@Override
159-
public void configure(WebSecurity web) throws Exception {
160-
web
161-
.ignoring()
162-
.antMatchers(STATIC_FILES);
163-
}
164153
}
165154
}

src/main/java/com/github/throyer/common/springboot/configurations/SpringWebConfiguration.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.springframework.security.data.repository.query.SecurityEvaluationContextExtension;
77
import org.springframework.web.servlet.config.annotation.CorsRegistry;
88
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
9+
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
910
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
1011

1112
@EnableWebMvc
@@ -25,6 +26,17 @@ public BCryptPasswordEncoder passwordEncoder() {
2526
return new BCryptPasswordEncoder();
2627
}
2728

29+
@Override
30+
public void addResourceHandlers(ResourceHandlerRegistry registry) {
31+
registry
32+
.addResourceHandler("/**")
33+
.addResourceLocations("classpath:/static/");
34+
35+
registry
36+
.addResourceHandler("/webjars/**")
37+
.addResourceLocations("/webjars/");
38+
}
39+
2840
@Bean
2941
public SecurityEvaluationContextExtension securityEvaluationContextExtension() {
3042
return new SecurityEvaluationContextExtension();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.github.throyer.common.springboot.controllers.app;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
7+
@Controller
8+
@RequestMapping("/app/login")
9+
public class LoginController {
10+
@GetMapping
11+
public String login() {
12+
return "app/login/index";
13+
}
14+
}

src/main/java/com/github/throyer/common/springboot/domain/services/security/SecurityService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public SecurityService(@Value("${token.secret}") String secret) {
3535

3636
@Override
3737
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
38-
return new Authorized(repository.findOptionalByEmail(email)
38+
return new Authorized(repository.findOptionalByEmailFetchRoles(email)
3939
.orElseThrow(() -> new UsernameNotFoundException(INVALID_USERNAME)));
4040
}
4141

src/main/java/com/github/throyer/common/springboot/utils/Constants.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class SECURITY {
1919
public static final String HOME_URL = "/app";
2020
public static final String LOGIN_URL = "/app/login";
2121
public static final String LOGIN_ERROR_URL = LOGIN_URL + "?error=true";
22-
public static final String ACESSO_NEGADO_URL = LOGIN_URL + "?negado=true";
22+
public static final String ACESSO_NEGADO_URL = LOGIN_URL + "?denied=true";
2323
public static final String LOGOUT_URL = "/app/logout";
2424

2525
public static final String SESSION_COOKIE_NAME = "JSESSIONID";
@@ -31,15 +31,9 @@ public class SECURITY {
3131
"/webjars/**",
3232
"/webjars/",
3333
"/js/**",
34-
"/favicon.ico"
35-
};
36-
37-
}
38-
39-
public class CONFIGURATIONS {
40-
public static final int FIRST = 1;
41-
public static final int SECOND = 2;
42-
public static final String EVERY_HTML = "/**.html";
43-
public static final String SWAGGER_DOCS = "/documentation/**";
34+
"/favicon.ico",
35+
"/**.html",
36+
"/documentation/**"
37+
};
4438
}
4539
}
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
-- variables
22
SET @name = 'admin';
33
SET @email = 'admin@email.com';
4-
SET @password = '$2a$10$L9CP7W3JIKhVz5J/WiMP/.LEqvAMC915HxxON98MFtyJzXbIEnajS';
4+
SET @password = '$2a$10$QBuMJLbVmHzgvTwpxDynSetACNdCBjU5zgo.81RWEDzH46aUrgcNK';
55
SET @adm = 'ADM';
66
SET @user = 'USER';
77

88
-- insert admin
9-
INSERT INTO "user"
10-
("name", "email", "password")
9+
INSERT INTO user
10+
(name, email, password)
1111
VALUES
1212
(@name, @email, @password);
1313

1414
-- insert roles
15-
INSERT INTO "role"
16-
("name", "initials", "description", "created_by")
15+
INSERT INTO role
16+
(name, initials, description, created_by)
1717
VALUES
18-
('ADMINISTRADOR', @adm, 'Administrador do sistema', (SELECT id FROM "user" WHERE email = @email)),
19-
('USER', @user, 'Usuário do sistema', (SELECT id FROM "user" WHERE email = @email));
18+
('ADMINISTRADOR', @adm, 'Administrador do sistema', (SELECT id FROM user WHERE email = @email)),
19+
('USER', @user, 'Usuário do sistema', (SELECT id FROM user WHERE email = @email));
2020

2121
-- put roles into admin
22-
INSERT INTO "user_role"
23-
("user_id", "role_id")
22+
INSERT INTO user_role
23+
(user_id, role_id)
2424
VALUES
2525
(
26-
(SELECT id FROM "user" WHERE email = @email),
27-
(SELECT id FROM "role" WHERE initials = @adm)
26+
(SELECT id FROM user WHERE email = @email),
27+
(SELECT id FROM role WHERE initials = @adm)
2828
),(
29-
(SELECT id FROM "user" WHERE email = @email),
30-
(SELECT id FROM "role" WHERE initials = @user)
29+
(SELECT id FROM user WHERE email = @email),
30+
(SELECT id FROM role WHERE initials = @user)
3131
);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.form {
2+
width: 100%;
3+
max-width: 330px;
4+
padding: 15px;
5+
margin: auto;
6+
}
7+
8+
.form > .icon {
9+
display: flex;
10+
justify-content: center;
11+
}
12+
13+
.form .checkbox {
14+
font-weight: 400;
15+
}
16+
17+
.form .form-control {
18+
position: relative;
19+
box-sizing: border-box;
20+
height: auto;
21+
padding: 10px;
22+
font-size: 16px;
23+
}
24+
25+
.form .form-control:focus {
26+
z-index: 2;
27+
}
28+
29+
.form input[type="email"] {
30+
margin-bottom: -1px;
31+
border-bottom-right-radius: 0;
32+
border-bottom-left-radius: 0;
33+
}
34+
35+
.form input[type="password"] {
36+
margin-bottom: 10px;
37+
border-top-left-radius: 0;
38+
border-top-right-radius: 0;
39+
}

src/main/resources/static/css/styles.css

Whitespace-only changes.

src/main/resources/static/js/main.js

Whitespace-only changes.

0 commit comments

Comments
 (0)