Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
springBoot
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
WitCloud
springBoot
Commits
4b9fb717
Commit
4b9fb717
authored
Feb 08, 2017
by
杨伊博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MD5 encryption is ok
parent
adb725fb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
1 deletion
+65
-1
WebSocketController.java
...n/java/com/us/example/controller/WebSocketController.java
+1
-0
WebSecurityConfig.java
...rc/main/java/com/us/example/config/WebSecurityConfig.java
+18
-1
MD5Util.java
...ngSecurity/src/main/java/com/us/example/util/MD5Util.java
+46
-0
No files found.
springWebSocket/src/main/java/com/us/example/controller/WebSocketController.java
View file @
4b9fb717
...
...
@@ -50,6 +50,7 @@ public class WebSocketController {
/**
* 此处是一段硬编码。如果发送人是wyf 则发送给 wisely 如果发送人是wisely 就发送给 wyf。
* 通过当前用户,然后查找消息,如果查找到未读消息,则发送给当前用户。
*/
if
(
principal
.
getName
().
equals
(
"wyf"
))
{
//通过convertAndSendToUser 向用户发送信息,
...
...
springboot-SpringSecurity/src/main/java/com/us/example/config/WebSecurityConfig.java
View file @
4b9fb717
package
com
.
us
.
example
.
config
;
import
com.us.example.security.CustomUserService
;
import
com.us.example.util.MD5Util
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
/**
* Created by yangyibo on 17/1/18.
*/
...
...
@@ -20,8 +25,17 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected
void
configure
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
auth
.
userDetailsService
(
customUserService
());
//user Details Service验证
auth
.
userDetailsService
(
customUserService
()).
passwordEncoder
(
new
PasswordEncoder
(){
@Override
public
String
encode
(
CharSequence
rawPassword
)
{
return
MD5Util
.
encode
((
String
)
rawPassword
);
}
@Override
public
boolean
matches
(
CharSequence
rawPassword
,
String
encodedPassword
)
{
return
encodedPassword
.
equals
(
MD5Util
.
encode
((
String
)
rawPassword
));
}});
//user Details Service验证
}
@Override
...
...
@@ -38,5 +52,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
}
}
springboot-SpringSecurity/src/main/java/com/us/example/util/MD5Util.java
0 → 100644
View file @
4b9fb717
package
com
.
us
.
example
.
util
;
/**
* Created by yangyibo on 17/2/7.
*/
import
java.security.MessageDigest
;
/**
* MD5加密工具
*
*/
public
class
MD5Util
{
private
static
final
String
SALT
=
"tamboo"
;
public
static
String
encode
(
String
password
)
{
password
=
password
+
SALT
;
MessageDigest
md5
=
null
;
try
{
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
char
[]
charArray
=
password
.
toCharArray
();
byte
[]
byteArray
=
new
byte
[
charArray
.
length
];
for
(
int
i
=
0
;
i
<
charArray
.
length
;
i
++)
byteArray
[
i
]
=
(
byte
)
charArray
[
i
];
byte
[]
md5Bytes
=
md5
.
digest
(
byteArray
);
StringBuffer
hexValue
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
md5Bytes
.
length
;
i
++)
{
int
val
=
((
int
)
md5Bytes
[
i
])
&
0xff
;
if
(
val
<
16
)
{
hexValue
.
append
(
"0"
);
}
hexValue
.
append
(
Integer
.
toHexString
(
val
));
}
return
hexValue
.
toString
();
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
MD5Util
.
encode
(
"abel"
));
}
}
\ No newline at end of file
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