いつもお世話になっております。
SpringSecurityのログイン画面を作成しております。
内容としましては、MysqlのNewaccountテーブルに登録しているユーザを
検索するものです。
名前とパスワードを入力し実行したのですが、下記のエラーが発生しました。
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed May 31 14:54:11 JST 2017
There was an unexpected error (type=Not Found, status=404).
No message available
原因が不明ですのでご回答宜しくお願い致します
-20170605追記
SecurityConfig.javaの箇所でブレークポイントし、デバックしたところ
Source not foundeエラーが出ました。
内容としましては
Spring-security-config-4-2-1RELEASE.jarファイルが
no source attachment
と出てきました。
gradleでSpring-security-config-4-2-1RELEASE.jarファイルを
入れるように設定しているため、設定しているはずなのですが
エラーが出てくるのが何故なのか不明です。
原因が不明ですのでご回答宜しくお願い致します
java
1//Datasource.java 2package com.tuyano.springboot.springsecurity; 3 4import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; 5import javax.sql.DataSource; 6import org.apache.commons.dbcp.BasicDataSource; 7import org.springframework.beans.factory.annotation.Value; 8import org.springframework.context.annotation.Bean; 9import org.springframework.context.annotation.Configuration; 10import org.springframework.context.annotation.PropertySource; 11import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; 12import org.springframework.core.io.ClassPathResource; 13import org.springframework.core.io.FileSystemResource; 14import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; 15@Configuration 16@PropertySource("application.properties") 17public class DataSourceConfig { 18 19 @Value("${spring.datasource.driverClassName}") 20 private String driverClassName; 21 @Value("${spring.datasource.url}") 22 private String url; 23 @Value("${spring.datasource.username}") 24 private String userName; 25 @Value("${spring.datasource.password}") 26 private String password; 27 28 @Bean 29 public static PropertySourcesPlaceholderConfigurer propertyConfig() { 30 return new PropertySourcesPlaceholderConfigurer(); 31 } 32 @Bean(destroyMethod="close") 33 public DataSource dataSource() { 34 35 BasicDataSource ds = new BasicDataSource() { 36 @Override 37 public String toString() { 38 return "[driverClassName=" + driverClassName + ",username=" + userName + ", password=" + password+ "]"; 39 } 40 }; 41 ds.setDriverClassName(driverClassName); 42 ds.setUrl(url); 43 ds.setUsername(userName); 44 ds.setPassword(password); 45 System.out.println("dsの値"+ds); 46 return ds; 47 48 }
HTML
1//First.html 2<!DOCTYPE html> 3<html xmlns:th="http://www.thymeleaf.org"> 4<head> 5<title>top page</title> 6<meta http-equiv="Content-Type" 7content="text/html" charset="UTF-8"/> 8</head> 9<body> 10<form action="/processLogin" > 11 <dl> 12 <dt> 13 ログイン名前 14 </dt> 15 <dd> 16 <input type="text" name="name"></input> 17</dd> 18 <dt> 19 ログインパスワード 20 </dt> 21 <dd> 22 <input type="password" name="password"></input> 23 </dd> 24 </dl> 25 <button>ログイン</button> 26</form> 27 <hr/> 28 <form action="urlForUpload" enctype="multipart/form-data" method="post"> 29 <div class="form-group"> 30 <label>■ファイル種類:</label> 31 <select id="select_file_type" name="select_file_type" required=""> 32 <option value="login-user">ログインユーザー</option> 33 <!-- アップロードするファイルを定義していく --> 34 </select> 35 </div> 36 <div class="form-group"> 37 <label>■ファイルパス:</label> 38 <input type="file" id="upload_file" name="upload_file" required="" /> 39 </div> 40 <div class="form-group"> 41 <input id="data_upload_button" type="submit" value="アップロード" /> 42 </div> 43 </form> 44 <table> 45<tr><th>名前</th><th>住所</th></tr> 46<tr th:each="obj :${datalist}"> 47<td th:text="${obj.name}"></td> 48 49</tr> 50</table> 51 <div id ="map"></div> 52<script type="text/javascript" src="js/main.js" 53 54</body> 55 56</html>
java
1//Security.config 2package com.tuyano.springboot.springsecurity; 3 4import org.springframework.context.annotation.Bean; 5import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 8import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 9import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 10 11import javax.sql.DataSource; 12 13import org.springframework.beans.factory.annotation.Autowired; 14import org.springframework.beans.factory.annotation.Qualifier; 15 16 17 18@EnableWebSecurity 19public class SecurityConfig extends WebSecurityConfigurerAdapter{ 20 @Autowired 21 private DataSource dataSource; 22 23 private static final String USER_QUERY="select name, password, 1 from Newaccount where name = ?"; 24 private static final String ROLES_QUERY="select username, authority from AUTHORITIES where username = ?"; 25 26 @Override 27 protected void configure(HttpSecurity http) throws Exception{ 28 http 29 .authorizeRequests() 30 .antMatchers("/First.html").permitAll() 31 .antMatchers("/templates/**").hasAnyAuthority("ROLE_ADMIN") 32 .anyRequest().authenticated() 33 .and() 34 .formLogin() 35 .loginPage("/First.html") 36 .loginProcessingUrl("/processLogin") 37 .defaultSuccessUrl("/sucess.html") 38 .failureUrl("/faliure.html") 39 .usernameParameter("name") 40 .passwordParameter("password") 41 .and() 42 .csrf() 43 .disable(); 44 45 } 46 @Override 47 public void configure(AuthenticationManagerBuilder auth) throws Exception { 48 auth.jdbcAuthentication() 49 .dataSource(dataSource) 50 .usersByUsernameQuery(USER_QUERY) 51 .authoritiesByUsernameQuery(ROLES_QUERY); 52 //passwordEncoder(new BCryptPasswordEncoder()); 53 //.authoritiesByUsernameQuery( 54 // "select mail_address, role from accounts where mail_address = ?"); 55 } 56 57 58}
gradle
1buildscript { 2 ext { 3 springBootVersion = '1.5.1.RELEASE' 4 } 5 repositories { 6 mavenCentral() 7 } 8 dependencies { 9 classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 } 11} 12 13apply plugin: 'java' 14apply plugin: 'eclipse-wtp' 15apply plugin: 'org.springframework.boot' 16apply plugin: 'war' 17 18war { 19 baseName = 'MybootApp' 20 version = '0.0.1-SNAPSHOT' 21} 22 23sourceCompatibility = 1.8 24 25repositories { 26 mavenCentral() 27} 28 29configurations { 30 providedRuntime 31} 32 33dependencies { 34 //SpringSecurityを使うため、追加 35 compile('org.springframework.boot:spring-boot-starter-security') 36 compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity4') 37 compile('org.springframework.boot:spring-boot-starter-data-jpa') 38 compile('org.springframework.boot:spring-boot-starter-thymeleaf') 39 compile('org.springframework.boot:spring-boot-starter-web') 40 runtime('mysql:mysql-connector-java') 41 providedRuntime('org.springframework.boot:spring-boot-starter-tomcat') 42 testCompile('org.springframework.boot:spring-boot-starter-test') 43 // MySQL 44 //compile ("mysql:mysql-connector-java:$mySQLVersion") 45 //追記したMysqlのデータソース用 46 compile ('mysql:mysql-connector-java') 47 compile ('com.fasterxml.jackson.core:jackson-databind:2.8.8') 48 compile("org.springframework.boot:spring-boot-starter-thymeleaf") 49 compile 'commons-dbcp:commons-dbcp:1.4' 50 51} 52
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/31 09:28 編集
2017/06/04 06:21
2017/06/04 13:01
2017/06/04 14:28
2017/06/04 16:05