0

Is it possible to implement 2 factor authentication with spring oath password flow? I am thinking to use http filter on the endpoint /oauth/token. My oauth access token grant is done over REST so, the whole authentication process will be restful.

This would be my custom filter but, I am unsure where to wire it up:

 public class TwoFactorAuthenticationFilter extends UsernamePasswordAuthenticationFilter
{
 private String extraParameter = "extra";
 private String delimiter = ":";


/**
 * Given an {@link HttpServletRequest}, this method extracts the username and the extra input
 * values and returns a combined username string of those values separated by the delimiter
 * string.
 *
 * @param request The {@link HttpServletRequest} containing the HTTP request variables from
 *   which the username client domain values can be extracted
 */
@Override
protected String obtainUsername(HttpServletRequest request)
{
    String username = request.getParameter(getUsernameParameter());
    String extraInput = request.getParameter(getExtraParameter());

    String combinedUsername = username + getDelimiter() + extraInput;

    System.out.println("Combined username = " + combinedUsername);
    return combinedUsername;
}

/**
 * @return The parameter name which will be used to obtain the extra input from the login request
 */
public String getExtraParameter()
{
    return this.extraParameter;
}

/**
 * @param extraParameter The parameter name which will be used to obtain the extra input from the login request
 */
public void setExtraParameter(String extraParameter)
{
    this.extraParameter = extraParameter;
}

/**
 * @return The delimiter string used to separate the username and extra input values in the
 * string returned by <code>obtainUsername()</code>
 */
public String getDelimiter()
{
    return this.delimiter;
}

/**
 * @param delimiter The delimiter string used to separate the username and extra input values in the
 * string returned by <code>obtainUsername()</code>
 */
public void setDelimiter(String delimiter)
{
    this.delimiter = delimiter;
}

}

Ashot Karakhanyan
  • 2,804
  • 3
  • 23
  • 28
Dean
  • 887
  • 4
  • 16
  • 42
  • So I found that the ResourceOwnerPasswordTokenGranter ->getOAuth2Authentication is the method that extrapolate the username and password and then calls the authentication manager. Is there a way to provide my own custom ResourceOwnerPasswordTokenGranter? – Dean Apr 22 '14 at 12:15
  • This article basically solves the issue [link](http://stackoverflow.com/questions/22637863/does-oauth2-allow-for-authorization-using-non-password-or-custom-credentials) – Dean Apr 22 '14 at 22:34

0 Answers0