Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
Ecsite
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shoei.kanno
Ecsite
Commits
a744b42e
Commit
a744b42e
authored
Oct 15, 2020
by
keita.onoguchi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ログイン機能途中
parent
8b7bed52
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
43 deletions
+27
-43
SecurityConfig.java
src/main/java/com/example/SecurityConfig.java
+4
-8
User.java
src/main/java/com/example/domain/User.java
+3
-1
UserRepository.java
src/main/java/com/example/repository/UserRepository.java
+1
-3
LoginUser.java
src/main/java/com/example/service/LoginUser.java
+8
-15
LoginUserDetailsService.java
...ain/java/com/example/service/LoginUserDetailsService.java
+9
-14
login.html
src/main/resources/templates/login.html
+2
-2
No files found.
src/main/java/com/example/SecurityConfig.java
View file @
a744b42e
...
...
@@ -14,19 +14,14 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
public
void
configure
(
WebSecurity
web
)
throws
Exception
{
web
.
debug
(
false
)
.
ignoring
()
.
antMatchers
(
"/images/**"
,
"/js/**"
,
"/css/**"
)
;
web
.
debug
(
false
).
ignoring
().
antMatchers
(
"/images/**"
,
"/js/**"
,
"/css/**"
);
}
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
.
authorizeRequests
()
.
mvcMatchers
(
"/
"
,
"/
signup"
,
"/limited/login"
).
permitAll
()
.
mvcMatchers
(
"/signup"
,
"/limited/login"
).
permitAll
()
.
mvcMatchers
(
"/limited/admin/**"
).
hasRole
(
"ADMIN"
)
.
anyRequest
().
authenticated
()
.
and
()
...
...
@@ -34,11 +29,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter{
.
loginProcessingUrl
(
"/login"
)
.
loginPage
(
"/limited/login"
)
.
defaultSuccessUrl
(
"/top"
)
.
usernameParameter
(
"email"
).
passwordParameter
(
"password"
)
.
and
()
.
logout
()
.
invalidateHttpSession
(
true
)
.
deleteCookies
(
"JSESSIONID"
)
.
logoutSuccessUrl
(
"/login"
);
.
logoutSuccessUrl
(
"/l
imited/l
ogin"
);
}
@Bean
...
...
src/main/java/com/example/domain/User.java
View file @
a744b42e
...
...
@@ -8,6 +8,8 @@ import javax.persistence.GeneratedValue;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
...
...
@@ -21,6 +23,7 @@ import lombok.ToString;
@Table
(
name
=
"users"
)
@ToString
(
exclude
=
{
"email"
,
"password"
})
public
class
User
{
@Id
@GeneratedValue
private
int
id
;
@Column
(
nullable
=
false
)
...
...
@@ -31,7 +34,6 @@ public class User {
private
String
address
;
@Column
(
nullable
=
false
)
private
String
phoneNumber
;
@Id
@Column
(
nullable
=
false
)
private
String
email
;
@Column
(
nullable
=
false
)
...
...
src/main/java/com/example/repository/UserRepository.java
View file @
a744b42e
package
com
.
example
.
repository
;
import
java.util.Optional
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
com.example.domain.User
;
public
interface
UserRepository
extends
JpaRepository
<
User
,
String
>{
Optional
<
User
>
findByEmail
(
String
email
);
User
findByEmail
(
String
email
);
}
src/main/java/com/example/
domain
/LoginUser.java
→
src/main/java/com/example/
service
/LoginUser.java
View file @
a744b42e
package
com
.
example
.
domain
;
package
com
.
example
.
service
;
import
java.util.Collections
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
org.springframework.security.core.authority.AuthorityUtils
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
lombok.extern.slf4j.Slf4j
;
import
com.example.domain.User
;
//ユーザーの認証・認可にかかわるクラス
@Slf4j
public
class
LoginUser
extends
org
.
springframework
.
security
.
core
.
userdetails
.
User
{
private
static
final
long
serialVersionUID
=
1L
;
private
User
user
;
public
LoginUser
(
User
user
){
super
(
user
.
getEmail
(),
user
.
getPassword
(),
convertGrantedAuthorities
(
user
.
getRoles
()));
super
(
user
.
getEmail
(),
user
.
getPassword
(),
AuthorityUtils
.
createAuthorityList
(
user
.
getRoles
()));
this
.
user
=
user
;
}
public
User
getUser
()
{
/*
public User getUser() {
return user;
}
}
*/
static
Set
<
GrantedAuthority
>
convertGrantedAuthorities
(
String
roles
){
/*
static Set<GrantedAuthority> convertGrantedAuthorities(String roles){
if(roles == null || roles.isEmpty()){
return Collections.emptySet();
}
...
...
@@ -35,5 +28,5 @@ public class LoginUser extends org.springframework.security.core.userdetails.Use
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toSet());
return authorities;
}
}
*/
}
src/main/java/com/example/service/LoginUserDetailsService.java
View file @
a744b42e
package
com
.
example
.
service
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.example.domain.
Login
User
;
import
com.example.domain.User
;
import
com.example.repository.UserRepository
;
import
lombok.extern.slf4j.Slf4j
;
@Service
@Slf4j
public
class
LoginUserDetailsService
implements
UserDetailsService
{
private
final
UserRepository
userRepository
;
public
LoginUserDetailsService
(
UserRepository
userRepository
){
this
.
userRepository
=
userRepository
;
}
@Autowired
UserRepository
userRepository
;
@Transactional
(
readOnly
=
true
)
@Override
public
UserDetails
loadUserByUsername
(
String
email
)
throws
UsernameNotFoundException
{
assert
(
email
!=
nul
l
);
log
.
debug
(
"loadUserByUsername(email):[{}]"
,
email
);
return
userRepository
.
findByEmail
(
email
)
.
map
(
LoginUser:
:
new
)
.
orElseThrow
(()
->
new
UsernameNotFoundException
(
"User not found by email:["
+
email
+
"]"
)
);
User
user
=
userRepository
.
findByEmail
(
emai
l
);
if
(
user
==
null
){
throw
new
UsernameNotFoundException
(
"The requested user is not found"
);
}
return
new
LoginUser
(
user
);
}
}
src/main/resources/templates/login.html
View file @
a744b42e
...
...
@@ -123,12 +123,12 @@
<!-- モーダル用 -->
<script
src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"
></script>
<!-- JQUERY -->
<script
src=
"js/vendor/jquery-1.11.2.min.js"
th:src=
"@{/js/vendor/jquery-1.11.2.min.js}"
></script>
<
!-- <
script src="js/vendor/jquery-1.11.2.min.js" th:src="@{/js/vendor/jquery-1.11.2.min.js}"></script>
<script src="js/vendor/bootstrap.min.js" th:src="@{/js/vendor/bootstrap.min.js}"></script>
<script src="js/isotope.pkgd.min.js" th:src="@{/js/isotope.pkgd.min.js}"></script>
<script src="js/owl.carousel.min.js" th:src="@{/js/owl.carousel.min.js}"></script>
<script src="js/wow.min.js" th:src="@{/js/wow.min.js}"></script>
<script
src=
"js/custom.js"
th:src=
"@{/js/custom.js}"
></script>
<script src="js/custom.js" th:src="@{/js/custom.js}"></script>
-->
<script
src=
"js/login.js"
th:src=
"@{/js/login.js}"
></script>
</body>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment