From efb25e592762b6c671354007e01a5990b5b6c3ea Mon Sep 17 00:00:00 2001 From: Keijo Korte Date: Wed, 23 Dec 2015 11:21:08 +0200 Subject: [PATCH] Refactoring --- .../totpauth/authn/impl/RegisterNewToken.java | 21 ++++++++++--------- .../resources/conf/authn/totp-authn-beans.xml | 16 +++++++------- .../src/main/resources/views/totp-register.vm | 2 +- .../src/main/resources/views/totp.vm | 2 +- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/totpauth-impl/src/main/java/net/kvak/shibboleth/totpauth/authn/impl/RegisterNewToken.java b/totpauth-impl/src/main/java/net/kvak/shibboleth/totpauth/authn/impl/RegisterNewToken.java index d51ab54..f414c09 100644 --- a/totpauth-impl/src/main/java/net/kvak/shibboleth/totpauth/authn/impl/RegisterNewToken.java +++ b/totpauth-impl/src/main/java/net/kvak/shibboleth/totpauth/authn/impl/RegisterNewToken.java @@ -99,9 +99,9 @@ public void setgAuth(@Nonnull @NotEmpty final GoogleAuthenticator gAuth) { this.gAuth = gAuth; } - /** Constructor - * Initialize user and seed attributes - * */ + /** + * Constructor Initialize user and seed attributes + */ public RegisterNewToken(String seedAttribute, String userAttribute) { log.debug("Construct RegisterNewToken with {} - {}", seedAttribute, userAttribute); this.userAttribute = userAttribute; @@ -149,7 +149,7 @@ protected void doExecute(@Nonnull final ProfileRequestContext profileRequestCont if (!StringUtils.isNumeric(token) || Strings.isNullOrEmpty(token)) { log.debug("{} Empty or invalid tokenCode", getLogPrefix()); tokenCtx.setState(AuthState.CANT_VALIDATE); - + ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.INVALID_CREDENTIALS); return; @@ -162,23 +162,24 @@ protected void doExecute(@Nonnull final ProfileRequestContext profileRequestCont if (!Strings.isNullOrEmpty(dn)) { log.debug("{} User {} DN is {}", getLogPrefix(), upCtx.getUsername(), dn); boolean result = registerToken(dn, tokenCtx.getSharedSecret()); - + if (!result) { ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.ACCOUNT_ERROR); } + } else { + log.debug("Invalid token. Returning."); + tokenCtx.setState(AuthState.CANT_VALIDATE); + ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.INVALID_CREDENTIALS); } - } - log.debug("Invalid token. Returning."); - tokenCtx.setState(AuthState.CANT_VALIDATE); - ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.INVALID_CREDENTIALS); + } } private boolean registerToken(String dn, String sharedSecret) { log.debug("Entering registerToken"); - + try { Attribute attr = new BasicAttribute(seedAttribute, sharedSecret); log.debug("Created new BasicAttribute [{} - {}]", attr.getID(), attr.get(0)); diff --git a/totpauth-impl/src/main/resources/conf/authn/totp-authn-beans.xml b/totpauth-impl/src/main/resources/conf/authn/totp-authn-beans.xml index e4b7aff..5f628ef 100644 --- a/totpauth-impl/src/main/resources/conf/authn/totp-authn-beans.xml +++ b/totpauth-impl/src/main/resources/conf/authn/totp-authn-beans.xml @@ -23,15 +23,17 @@ p:httpServletRequest-ref="shibboleth.HttpServletRequest" p:seedFetcher-ref="shibboleth.totp.seedfetcher" p:gAuth-ref="shibboleth.totp.gAuth" /> - - - + + + + diff --git a/totpauth-impl/src/main/resources/views/totp-register.vm b/totpauth-impl/src/main/resources/views/totp-register.vm index 842df39..ae89a8b 100644 --- a/totpauth-impl/src/main/resources/views/totp-register.vm +++ b/totpauth-impl/src/main/resources/views/totp-register.vm @@ -46,7 +46,7 @@ p.error {
- +
diff --git a/totpauth-impl/src/main/resources/views/totp.vm b/totpauth-impl/src/main/resources/views/totp.vm index 747603a..233277e 100644 --- a/totpauth-impl/src/main/resources/views/totp.vm +++ b/totpauth-impl/src/main/resources/views/totp.vm @@ -35,7 +35,7 @@ p.error {
- +