Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Max Mecklin
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a49d4b80
authored
Mar 05, 2014
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rest changes
1 parent
78dcf6db
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
9 deletions
code/MoyaUtilities/src/main/java/fi/codecrew/moya/utilities/PasswordFunctions.java
code/MoyaWeb/src/fi/codecrew/moya/rest/RestApplicationEntrypoint.java
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/MapPojo.java
code/MoyaUtilities/src/main/java/fi/codecrew/moya/utilities/PasswordFunctions.java
View file @
a49d4b8
package
fi
.
codecrew
.
moya
.
utilities
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.Charset
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Random
;
...
...
@@ -19,6 +20,44 @@ public class PasswordFunctions {
private
static
final
boolean
UGLY_FIX
=
true
;
private
static
final
Charset
LATIN1
=
Charset
.
forName
(
"ISO-8859-15"
);
public
static
final
String
calculateSha1
(
String
source
)
{
String
ret
=
null
;
try
{
final
MessageDigest
algo
=
MessageDigest
.
getInstance
(
"SHA"
);
final
byte
[]
resultByte
=
algo
.
digest
(
source
.
getBytes
(
LATIN1
));
ret
=
new
String
(
Hex
.
encodeHex
(
resultByte
)).
toUpperCase
();
}
catch
(
NoSuchAlgorithmException
e
)
{
logger
.
warn
(
"THIS SHOULD NEVER HAPPEN! (SHA1 hashfunction should always exist)"
,
e
);
}
return
ret
;
}
/**
* Returns the SHA1 sum of the @param fields separated by @param separator e
* eg separator = "+" fields {"ONE", "TWO", "THREE"} return value
* ONE+TWO+THREE
*
* @param separator
* @param fields
* @return
*/
public
static
final
String
calculateSha1
(
String
separator
,
String
...
fields
)
{
String
str
=
mkSeparatedString
(
separator
,
fields
);
String
ret
=
null
;
try
{
final
MessageDigest
algo
=
MessageDigest
.
getInstance
(
"SHA"
);
final
byte
[]
resultByte
=
algo
.
digest
(
str
.
getBytes
(
LATIN1
));
ret
=
new
String
(
Hex
.
encodeHex
(
resultByte
)).
toUpperCase
();
}
catch
(
NoSuchAlgorithmException
e
)
{
logger
.
warn
(
"THIS SHOULD NEVER HAPPEN! (SHA1 hashfunction should always exist)"
,
e
);
}
return
ret
;
}
/**
* Returns the MD5 sum of the @param fields separated by @param separator e
* eg separator = "+" fields {"ONE", "TWO", "THREE"} return value
...
...
@@ -28,9 +67,13 @@ public class PasswordFunctions {
* @param fields
* @return
*/
public
static
String
calculateMd5
(
String
separator
,
String
...
fields
)
public
static
final
String
calculateMd5
(
String
separator
,
String
...
fields
)
{
return
calculateMd5
(
mkSeparatedString
(
separator
,
fields
));
}
public
static
final
String
mkSeparatedString
(
String
separator
,
String
...
fields
)
{
StringBuilder
sb
=
new
StringBuilder
();
boolean
first
=
true
;
for
(
String
field
:
fields
)
...
...
@@ -42,17 +85,15 @@ public class PasswordFunctions {
}
sb
.
append
(
field
);
}
logger
.
info
(
"Calculating md5 from {}"
,
sb
.
toString
());
return
calculateMd5
(
sb
.
toString
());
return
sb
.
toString
();
}
public
static
String
calculateMd5
(
String
str
)
public
static
final
String
calculateMd5
(
String
str
)
{
String
ret
=
null
;
try
{
final
MessageDigest
algo
=
MessageDigest
.
getInstance
(
"MD5"
);
final
byte
[]
resultByte
=
algo
.
digest
(
str
.
getBytes
());
final
byte
[]
resultByte
=
algo
.
digest
(
str
.
getBytes
(
LATIN1
));
ret
=
new
String
(
Hex
.
encodeHex
(
resultByte
)).
toUpperCase
();
}
catch
(
NoSuchAlgorithmException
e
)
{
logger
.
warn
(
"THIS SHOULD NEVER HAPPEN! (md5 hashfunction should always exist)"
,
e
);
...
...
code/MoyaWeb/src/fi/codecrew/moya/rest/RestApplicationEntrypoint.java
View file @
a49d4b8
...
...
@@ -3,7 +3,9 @@ package fi.codecrew.moya.rest;
import
javax.ws.rs.ApplicationPath
;
import
javax.ws.rs.core.Application
;
@ApplicationPath
(
"/rest"
)
@ApplicationPath
(
RestApplicationEntrypoint
.
REST_PATH
)
public
class
RestApplicationEntrypoint
extends
Application
{
public
static
final
String
REST_PATH
=
"/rest"
;
}
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/MapPojo.java
deleted
100644 → 0
View file @
78dcf6d
package
fi
.
codecrew
.
moya
.
rest
.
pojo
;
Write
Preview
Markdown
is supported
Attach a file
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 post a comment