Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
reg-app
Regapp
Commits
8f7a8b73
Commit
8f7a8b73
authored
Jun 26, 2020
by
ls1947
Browse files
add om classes for totp authenticator token init
parent
9f51b775
Changes
12
Hide whitespace changes
Inline
Side-by-side
bwreg-service/src/main/java/edu/kit/scc/webreg/service/twofa/LinotpConnection.java
View file @
8f7a8b73
...
...
@@ -33,7 +33,8 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
edu.kit.scc.webreg.entity.UserEntity
;
import
edu.kit.scc.webreg.service.twofa.linotp.LinotpResponse
;
import
edu.kit.scc.webreg.service.twofa.linotp.LinotpInitAuthenticatorTokenResponse
;
import
edu.kit.scc.webreg.service.twofa.linotp.LinotpShowUserResponse
;
public
class
LinotpConnection
{
...
...
@@ -92,7 +93,45 @@ public class LinotpConnection {
httpClient
=
HttpClients
.
custom
().
setDefaultRequestConfig
(
config
).
build
();
}
public
LinotpResponse
getTokenList
(
UserEntity
user
)
throws
TwoFaException
{
public
LinotpInitAuthenticatorTokenResponse
createAuthenticatorToken
(
UserEntity
user
)
throws
TwoFaException
{
try
{
HttpPost
httpPost
=
new
HttpPost
(
configMap
.
get
(
"url"
)
+
"/admin/init"
);
List
<
NameValuePair
>
nvps
=
new
ArrayList
<
NameValuePair
>();
nvps
.
add
(
new
BasicNameValuePair
(
"session"
,
adminSession
));
nvps
.
add
(
new
BasicNameValuePair
(
"type"
,
"totp"
));
nvps
.
add
(
new
BasicNameValuePair
(
"otplen"
,
"6"
));
nvps
.
add
(
new
BasicNameValuePair
(
"genkey"
,
"1"
));
nvps
.
add
(
new
BasicNameValuePair
(
"hashlib"
,
"sha256"
));
nvps
.
add
(
new
BasicNameValuePair
(
"timeStep"
,
"30"
));
nvps
.
add
(
new
BasicNameValuePair
(
"description"
,
"This is a description"
));
if
(
configMap
.
containsKey
(
"userId"
))
nvps
.
add
(
new
BasicNameValuePair
(
"user"
,
configMap
.
get
(
"userId"
)));
else
nvps
.
add
(
new
BasicNameValuePair
(
"user"
,
user
.
getEppn
()));
if
(
configMap
.
containsKey
(
"realm"
))
nvps
.
add
(
new
BasicNameValuePair
(
"realm"
,
configMap
.
get
(
"realm"
)));
httpPost
.
setEntity
(
new
UrlEncodedFormEntity
(
nvps
));
CloseableHttpResponse
response
=
httpClient
.
execute
(
targetHost
,
httpPost
,
context
);
try
{
HttpEntity
entity
=
response
.
getEntity
();
String
responseString
=
EntityUtils
.
toString
(
entity
);
logger
.
debug
(
responseString
);
return
resultParser
.
parseInitAuthenticatorTokenResponse
(
responseString
);
}
finally
{
response
.
close
();
}
}
catch
(
ParseException
|
IOException
e
)
{
throw
new
TwoFaException
(
e
);
}
}
public
LinotpShowUserResponse
getTokenList
(
UserEntity
user
)
throws
TwoFaException
{
try
{
HttpPost
httpPost
=
new
HttpPost
(
configMap
.
get
(
"url"
)
+
"/admin/show"
);
...
...
@@ -112,8 +151,7 @@ public class LinotpConnection {
String
responseString
=
EntityUtils
.
toString
(
entity
);
logger
.
debug
(
responseString
);
resultParser
.
parseResult
(
responseString
);
return
resultParser
.
getResponse
();
return
resultParser
.
parseShowUserResponse
(
responseString
);
}
finally
{
response
.
close
();
...
...
bwreg-service/src/main/java/edu/kit/scc/webreg/service/twofa/LinotpResultParser.java
View file @
8f7a8b73
...
...
@@ -5,27 +5,35 @@ import java.io.IOException;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
edu.kit.scc.webreg.service.twofa.linotp.LinotpResponse
;
import
edu.kit.scc.webreg.service.twofa.linotp.LinotpInitAuthenticatorTokenResponse
;
import
edu.kit.scc.webreg.service.twofa.linotp.LinotpShowUserResponse
;
public
class
LinotpResultParser
{
private
ObjectMapper
om
;
private
LinotpResponse
response
;
public
LinotpResultParser
()
{
om
=
new
ObjectMapper
();
om
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
);
}
public
void
parseResult
(
String
responseString
)
throws
TwoFaException
{
public
LinotpShowUserResponse
parseShowUserResponse
(
String
responseString
)
throws
TwoFaException
{
try
{
response
=
om
.
readValue
(
responseString
,
LinotpResponse
.
class
);
LinotpShowUserResponse
response
=
om
.
readValue
(
responseString
,
LinotpShowUserResponse
.
class
);
return
response
;
}
catch
(
IOException
e
)
{
throw
new
TwoFaException
(
e
);
}
}
public
LinotpResponse
getResponse
()
{
return
response
;
public
LinotpInitAuthenticatorTokenResponse
parseInitAuthenticatorTokenResponse
(
String
responseString
)
throws
TwoFaException
{
try
{
LinotpInitAuthenticatorTokenResponse
response
=
om
.
readValue
(
responseString
,
LinotpInitAuthenticatorTokenResponse
.
class
);
return
response
;
}
catch
(
IOException
e
)
{
throw
new
TwoFaException
(
e
);
}
}
}
bwreg-service/src/main/java/edu/kit/scc/webreg/service/twofa/TwoFaService.java
View file @
8f7a8b73
package
edu.kit.scc.webreg.service.twofa
;
import
edu.kit.scc.webreg.service.twofa.linotp.LinotpInitAuthenticatorTokenResponse
;
public
interface
TwoFaService
{
LinotpTokenResultList
findByUserId
(
Long
userId
)
throws
TwoFaException
;
LinotpInitAuthenticatorTokenResponse
createAuthenticatorToken
(
Long
userId
)
throws
TwoFaException
;
}
bwreg-service/src/main/java/edu/kit/scc/webreg/service/twofa/TwoFaServiceImpl.java
View file @
8f7a8b73
...
...
@@ -9,7 +9,8 @@ import org.slf4j.Logger;
import
edu.kit.scc.webreg.dao.UserDao
;
import
edu.kit.scc.webreg.entity.UserEntity
;
import
edu.kit.scc.webreg.service.twofa.linotp.LinotpResponse
;
import
edu.kit.scc.webreg.service.twofa.linotp.LinotpInitAuthenticatorTokenResponse
;
import
edu.kit.scc.webreg.service.twofa.linotp.LinotpShowUserResponse
;
@Stateless
public
class
TwoFaServiceImpl
implements
TwoFaService
{
...
...
@@ -32,7 +33,7 @@ public class TwoFaServiceImpl implements TwoFaService {
LinotpConnection
linotpConnection
=
new
LinotpConnection
(
configMap
);
linotpConnection
.
requestAdminSession
();
LinotpResponse
response
=
linotpConnection
.
getTokenList
(
user
);
Linotp
ShowUser
Response
response
=
linotpConnection
.
getTokenList
(
user
);
LinotpTokenResultList
resultList
=
new
LinotpTokenResultList
();
if
(
response
.
getResult
()
!=
null
&&
response
.
getResult
().
getValue
()
!=
null
&&
response
.
getResult
().
getValue
().
getData
()
!=
null
)
{
...
...
@@ -53,6 +54,18 @@ public class TwoFaServiceImpl implements TwoFaService {
return
resultList
;
}
@Override
public
LinotpInitAuthenticatorTokenResponse
createAuthenticatorToken
(
Long
userId
)
throws
TwoFaException
{
UserEntity
user
=
userDao
.
findById
(
userId
);
Map
<
String
,
String
>
configMap
=
configResolver
.
resolveConfig
(
user
);
LinotpConnection
linotpConnection
=
new
LinotpConnection
(
configMap
);
linotpConnection
.
requestAdminSession
();
LinotpInitAuthenticatorTokenResponse
response
=
linotpConnection
.
createAuthenticatorToken
(
user
);
return
response
;
}
}
bwreg-service/src/main/java/edu/kit/scc/webreg/service/twofa/linotp/LinotpInitAuthenticatorTokenDetail.java
0 → 100644
View file @
8f7a8b73
package
edu.kit.scc.webreg.service.twofa.linotp
;
import
java.io.Serializable
;
public
class
LinotpInitAuthenticatorTokenDetail
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
LinotpInitAuthenticatorTokenOtpKey
googleurl
;
private
String
serial
;
private
LinotpInitAuthenticatorTokenOtpKey
otpkey
;
public
LinotpInitAuthenticatorTokenOtpKey
getGoogleurl
()
{
return
googleurl
;
}
public
void
setGoogleurl
(
LinotpInitAuthenticatorTokenOtpKey
googleurl
)
{
this
.
googleurl
=
googleurl
;
}
public
String
getSerial
()
{
return
serial
;
}
public
void
setSerial
(
String
serial
)
{
this
.
serial
=
serial
;
}
public
LinotpInitAuthenticatorTokenOtpKey
getOtpkey
()
{
return
otpkey
;
}
public
void
setOtpkey
(
LinotpInitAuthenticatorTokenOtpKey
otpkey
)
{
this
.
otpkey
=
otpkey
;
}
}
bwreg-service/src/main/java/edu/kit/scc/webreg/service/twofa/linotp/LinotpInitAuthenticatorTokenOtpKey.java
0 → 100644
View file @
8f7a8b73
package
edu.kit.scc.webreg.service.twofa.linotp
;
import
java.io.Serializable
;
public
class
LinotpInitAuthenticatorTokenOtpKey
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
img
;
private
String
order
;
private
String
value
;
private
String
description
;
public
String
getImg
()
{
return
img
;
}
public
void
setImg
(
String
img
)
{
this
.
img
=
img
;
}
public
String
getOrder
()
{
return
order
;
}
public
void
setOrder
(
String
order
)
{
this
.
order
=
order
;
}
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
}
bwreg-service/src/main/java/edu/kit/scc/webreg/service/twofa/linotp/LinotpInitAuthenticatorTokenResponse.java
0 → 100644
View file @
8f7a8b73
package
edu.kit.scc.webreg.service.twofa.linotp
;
import
java.io.Serializable
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
public
class
LinotpInitAuthenticatorTokenResponse
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
version
;
@JsonProperty
(
"jsonrpc"
)
private
String
jsonRpc
;
private
LinotpResult
result
;
private
LinotpInitAuthenticatorTokenDetail
detail
;
private
Integer
id
;
public
String
getVersion
()
{
return
version
;
}
public
void
setVersion
(
String
version
)
{
this
.
version
=
version
;
}
public
String
getJsonRpc
()
{
return
jsonRpc
;
}
public
void
setJsonRpc
(
String
jsonRpc
)
{
this
.
jsonRpc
=
jsonRpc
;
}
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
LinotpResult
getResult
()
{
return
result
;
}
public
void
setResult
(
LinotpResult
result
)
{
this
.
result
=
result
;
}
public
LinotpInitAuthenticatorTokenDetail
getDetail
()
{
return
detail
;
}
public
void
setDetail
(
LinotpInitAuthenticatorTokenDetail
detail
)
{
this
.
detail
=
detail
;
}
}
bwreg-service/src/main/java/edu/kit/scc/webreg/service/twofa/linotp/LinotpResult.java
View file @
8f7a8b73
...
...
@@ -3,9 +3,8 @@ package edu.kit.scc.webreg.service.twofa.linotp;
public
class
LinotpResult
{
private
boolean
status
;
private
boolean
value
;
private
LinotpValue
value
;
public
boolean
isStatus
()
{
return
status
;
}
...
...
@@ -14,13 +13,12 @@ public class LinotpResult {
this
.
status
=
status
;
}
public
LinotpValue
get
Value
()
{
public
boolean
is
Value
()
{
return
value
;
}
public
void
setValue
(
LinotpValue
value
)
{
public
void
setValue
(
boolean
value
)
{
this
.
value
=
value
;
}
}
bwreg-service/src/main/java/edu/kit/scc/webreg/service/twofa/linotp/LinotpResponse.java
→
bwreg-service/src/main/java/edu/kit/scc/webreg/service/twofa/linotp/Linotp
ShowUser
Response.java
View file @
8f7a8b73
...
...
@@ -4,7 +4,7 @@ import java.io.Serializable;
import
com.fasterxml.jackson.annotation.JsonProperty
;
public
class
LinotpResponse
implements
Serializable
{
public
class
Linotp
ShowUser
Response
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -13,7 +13,7 @@ public class LinotpResponse implements Serializable {
@JsonProperty
(
"jsonrpc"
)
private
String
jsonRpc
;
private
LinotpResult
result
;
private
Linotp
Value
Result
result
;
private
Integer
id
;
...
...
@@ -33,11 +33,11 @@ public class LinotpResponse implements Serializable {
this
.
jsonRpc
=
jsonRpc
;
}
public
LinotpResult
getResult
()
{
public
Linotp
Value
Result
getResult
()
{
return
result
;
}
public
void
setResult
(
LinotpResult
result
)
{
public
void
setResult
(
Linotp
Value
Result
result
)
{
this
.
result
=
result
;
}
...
...
bwreg-service/src/main/java/edu/kit/scc/webreg/service/twofa/linotp/LinotpValueResult.java
0 → 100644
View file @
8f7a8b73
package
edu.kit.scc.webreg.service.twofa.linotp
;
public
class
LinotpValueResult
{
private
boolean
status
;
private
LinotpValue
value
;
public
boolean
isStatus
()
{
return
status
;
}
public
void
setStatus
(
boolean
status
)
{
this
.
status
=
status
;
}
public
LinotpValue
getValue
()
{
return
value
;
}
public
void
setValue
(
LinotpValue
value
)
{
this
.
value
=
value
;
}
}
bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/TwoFaUserBean.java
View file @
8f7a8b73
...
...
@@ -24,6 +24,7 @@ import edu.kit.scc.webreg.service.UserService;
import
edu.kit.scc.webreg.service.twofa.LinotpTokenResultList
;
import
edu.kit.scc.webreg.service.twofa.TwoFaException
;
import
edu.kit.scc.webreg.service.twofa.TwoFaService
;
import
edu.kit.scc.webreg.service.twofa.linotp.LinotpInitAuthenticatorTokenResponse
;
import
edu.kit.scc.webreg.session.SessionManager
;
import
edu.kit.scc.webreg.util.FacesMessageGenerator
;
...
...
@@ -33,7 +34,6 @@ public class TwoFaUserBean implements Serializable {
private
static
final
long
serialVersionUID
=
1L
;
@Inject
private
Logger
logger
;
...
...
@@ -51,6 +51,7 @@ public class TwoFaUserBean implements Serializable {
private
UserEntity
user
;
private
LinotpTokenResultList
tokenList
;
private
LinotpInitAuthenticatorTokenResponse
createTokenResponse
;
public
void
preRenderView
(
ComponentSystemEvent
ev
)
{
if
(
user
==
null
)
{
...
...
@@ -64,6 +65,14 @@ public class TwoFaUserBean implements Serializable {
}
}
public
void
createAuthenticatorToken
()
{
try
{
createTokenResponse
=
twoFaService
.
createAuthenticatorToken
(
user
.
getId
());
}
catch
(
TwoFaException
e
)
{
logger
.
warn
(
"TwoFaException"
,
e
);
}
}
public
Boolean
getReadOnly
()
{
return
tokenList
.
getReadOnly
();
}
...
...
@@ -80,4 +89,8 @@ public class TwoFaUserBean implements Serializable {
return
user
;
}
public
LinotpInitAuthenticatorTokenResponse
getCreateTokenResponse
()
{
return
createTokenResponse
;
}
}
bwreg-webapp/src/main/webapp/user/twofa.xhtml
View file @
8f7a8b73
...
...
@@ -37,9 +37,17 @@
</p:panel>
<p:panel
header=
"#{messages.twofa_list}"
rendered=
"#{! twoFaUserBean.readOnly}"
>
<p:repeat
var=
"token"
value=
"#{twoFaUserBean.tokenList}"
>
<div><h:outputText
value=
"#{token.serial}"
/></div>
</p:repeat>
<p:panelGrid
columns=
"2"
>
<p:repeat
var=
"token"
value=
"#{twoFaUserBean.tokenList}"
>
<p:panel>
<div><h:outputText
value=
"#{token.serial}"
/></div>
<div><h:outputText
value=
"#{token.tokenType}"
/></div>
<div><h:outputText
value=
"#{token.isactive}"
/></div>
</p:panel>
</p:repeat>
</p:panelGrid>
<p:commandButton
action=
"#{twoFaUserBean.createAuthenticatorToken()}"
value=
"Create"
></p:commandButton>
</p:panel>
</h:form>
</ui:define>
...
...
Write
Preview
Supports
Markdown
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