Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
korteke committed Dec 23, 2015
1 parent 6a7574f commit efb25e5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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));
Expand Down
16 changes: 9 additions & 7 deletions totpauth-impl/src/main/resources/conf/authn/totp-authn-beans.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
p:httpServletRequest-ref="shibboleth.HttpServletRequest" p:seedFetcher-ref="shibboleth.totp.seedfetcher" p:gAuth-ref="shibboleth.totp.gAuth" />

<bean id="RegisterNewToken" class="net.kvak.shibboleth.totpauth.authn.impl.RegisterNewToken" scope="prototype"
p:httpServletRequest-ref="shibboleth.HttpServletRequest" p:gAuth-ref="shibboleth.totp.gAuth" />

<bean id="GenerateNewToken" class="net.kvak.shibboleth.totpauth.authn.impl.GenerateNewToken" scope="prototype"
p:httpServletRequest-ref="shibboleth.HttpServletRequest"
p:gAuth-ref="shibboleth.totp.gAuth"
p:ldapTemplate-ref="ldapTemplate"
p:httpServletRequest-ref="shibboleth.HttpServletRequest"
p:gAuth-ref="shibboleth.totp.gAuth"
p:ldapTemplate-ref="ldapTemplate"
p:tokenCodeField-ref="shibboleth.authn.tokenCodeField">
<constructor-arg ref="shibboleth.authn.seedAttribute" />
<constructor-arg ref="shibboleth.authn.userAttribute" />
<constructor-arg ref="shibboleth.authn.userAttribute" />
</bean>

<bean id="GenerateNewToken" class="net.kvak.shibboleth.totpauth.authn.impl.GenerateNewToken" scope="prototype"
p:httpServletRequest-ref="shibboleth.HttpServletRequest"
p:gAuth-ref="shibboleth.totp.gAuth">
</bean>

<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
Expand Down
2 changes: 1 addition & 1 deletion totpauth-impl/src/main/resources/views/totp-register.vm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ p.error {

<div class="form-element-wrapper">
<label for="tokenNumber">Token code</label>
<input class="form-element form-field" id="j_tokenNumber" name="j_tokenNumber" type="text">
<input class="form-element form-field" id="j_tokenNumber" name="j_tokenNumber" type="text" autofocus>
</div>


Expand Down
2 changes: 1 addition & 1 deletion totpauth-impl/src/main/resources/views/totp.vm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ p.error {

<div class="form-element-wrapper">
<label for="tokenNumber">Token code</label>
<input class="form-element form-field" id="j_tokenNumber" name="j_tokenNumber" type="text">
<input class="form-element form-field" id="j_tokenNumber" name="j_tokenNumber" type="text" autofocus>
</div>

<div class="form-element-wrapper">
Expand Down

0 comments on commit efb25e5

Please sign in to comment.