質問編集履歴
3
mailsend\.html追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -231,3 +231,53 @@
|
|
231
231
|
|
232
232
|
|
233
233
|
```
|
234
|
+
|
235
|
+
```html
|
236
|
+
|
237
|
+
mailsend.html
|
238
|
+
|
239
|
+
<!DOCTYPE html>
|
240
|
+
|
241
|
+
<html xmlns:th="http://www.thymeleaf.org">
|
242
|
+
|
243
|
+
<head>
|
244
|
+
|
245
|
+
<title>top page</title>
|
246
|
+
|
247
|
+
<meta http-equiv="Content-Type"
|
248
|
+
|
249
|
+
content="text/html" charset="UTF-8"/>
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
<!-- css -->
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
<style>
|
258
|
+
|
259
|
+
html { height: 100% }
|
260
|
+
|
261
|
+
body { height: 100%; margin: 0; padding: 0 }
|
262
|
+
|
263
|
+
#map { height: 100% }
|
264
|
+
|
265
|
+
</style>
|
266
|
+
|
267
|
+
</head>
|
268
|
+
|
269
|
+
<body>
|
270
|
+
|
271
|
+
<h1>メール送信完了</h1>
|
272
|
+
|
273
|
+
<form action="/mailsend" method="POST">
|
274
|
+
|
275
|
+
<button>メール送信</button>
|
276
|
+
|
277
|
+
</form>
|
278
|
+
|
279
|
+
</body>
|
280
|
+
|
281
|
+
</html>
|
282
|
+
|
283
|
+
```
|
2
security\.config\.javaを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
```html
|
8
8
|
|
9
|
+
First.html
|
10
|
+
|
9
11
|
<form action="/mailsend" method="POST">
|
10
12
|
|
11
13
|
<button>メール送信</button>
|
@@ -89,3 +91,143 @@
|
|
89
91
|
|
90
92
|
|
91
93
|
```
|
94
|
+
|
95
|
+
```java
|
96
|
+
|
97
|
+
Securityconfig.java
|
98
|
+
|
99
|
+
package com.tuyano.springboot.springsecurity;
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
import org.springframework.context.annotation.Bean;
|
104
|
+
|
105
|
+
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
106
|
+
|
107
|
+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
108
|
+
|
109
|
+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
110
|
+
|
111
|
+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
112
|
+
|
113
|
+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
import javax.sql.DataSource;
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
122
|
+
|
123
|
+
import org.springframework.beans.factory.annotation.Qualifier;
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
@EnableWebSecurity
|
132
|
+
|
133
|
+
public class SecurityConfig extends WebSecurityConfigurerAdapter{
|
134
|
+
|
135
|
+
@Autowired
|
136
|
+
|
137
|
+
private DataSource dataSource;
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
private static final String USER_QUERY="select name, password, 1 from Newaccount where name = ?";
|
142
|
+
|
143
|
+
private static final
|
144
|
+
|
145
|
+
String ROLES_QUERY="select username, authority from AUTHORITIES where username = ?";
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
@Override
|
150
|
+
|
151
|
+
protected void configure(HttpSecurity http) throws Exception{
|
152
|
+
|
153
|
+
http
|
154
|
+
|
155
|
+
.authorizeRequests()
|
156
|
+
|
157
|
+
.antMatchers("/First.html").permitAll()
|
158
|
+
|
159
|
+
.antMatchers("/sucess.html").permitAll()
|
160
|
+
|
161
|
+
.antMatchers("/failure.html").permitAll()
|
162
|
+
|
163
|
+
.antMatchers("/mailsend.html").permitAll()
|
164
|
+
|
165
|
+
.antMatchers("/js/**").permitAll()
|
166
|
+
|
167
|
+
.antMatchers("/templates/**").hasAnyAuthority("ROLE_ADMIN")
|
168
|
+
|
169
|
+
.anyRequest().authenticated()
|
170
|
+
|
171
|
+
.and()
|
172
|
+
|
173
|
+
.formLogin()
|
174
|
+
|
175
|
+
.loginPage("/First.html")
|
176
|
+
|
177
|
+
.loginProcessingUrl("/processLogin")
|
178
|
+
|
179
|
+
.defaultSuccessUrl("/sucess.html")
|
180
|
+
|
181
|
+
.failureUrl("/failure.html")
|
182
|
+
|
183
|
+
.usernameParameter("name")
|
184
|
+
|
185
|
+
.passwordParameter("password")
|
186
|
+
|
187
|
+
.and()
|
188
|
+
|
189
|
+
.logout()
|
190
|
+
|
191
|
+
.logoutUrl("/processLogout")
|
192
|
+
|
193
|
+
.logoutSuccessUrl("/First.html")
|
194
|
+
|
195
|
+
.and()
|
196
|
+
|
197
|
+
.csrf()
|
198
|
+
|
199
|
+
.disable();
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
@Override
|
206
|
+
|
207
|
+
public void configure(AuthenticationManagerBuilder auth) throws Exception {
|
208
|
+
|
209
|
+
auth.jdbcAuthentication()
|
210
|
+
|
211
|
+
.dataSource(dataSource)
|
212
|
+
|
213
|
+
.usersByUsernameQuery(USER_QUERY)
|
214
|
+
|
215
|
+
.authoritiesByUsernameQuery(ROLES_QUERY);
|
216
|
+
|
217
|
+
//passwordEncoder(new BCryptPasswordEncoder());
|
218
|
+
|
219
|
+
//.authoritiesByUsernameQuery(
|
220
|
+
|
221
|
+
// "select mail_address, role from accounts where mail_address = ?");
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
```
|
1
メール送信のクラス名を記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -25,6 +25,8 @@
|
|
25
25
|
下記がメール送信するためのjavaソースとなります。
|
26
26
|
|
27
27
|
```java
|
28
|
+
|
29
|
+
Mailsend.java
|
28
30
|
|
29
31
|
package com.tuyano.springboot.mail;
|
30
32
|
|