You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shiro.apache.org by dikybird <m_...@hotmail.com> on 2016/05/10 17:50:08 UTC

Apache Shiro custom AuthenticationToken

I am trying to use Shiro to login with a number rather than standard
usernamePasswordToken. I am getting the error
org.apache.shiro.authc.pam.UnsupportedTokenException: Realm .... does not
support authentication token. Please ensure that the appropriate Realm
implementation is configured correctly or that the realm accepts
AuthenticationTokens of this type.". How can I configure the realm to
support the token?

public class NumberAuthToken implements AuthenticationToken{
String  number;

public NumberAuthToken (String number) {
  this.number = number;
}

public String getPrincipal() {
  return number;
}
public String getCredentials() {
  return number;
}
}

and credentials matcher

public class NumberTokenMatcher implements CredentialsMatcher {
@Override
public boolean doCredentialsMatch(AuthenticationToken authToken,
AuthenticationInfo authenticationInfo) {

    return true;
}
}

in spring configuration

 <beans:bean id="UserDetails" class="com.UserDetailsService">
   <beans:property name="credentialsMatcher" ref="NumberTokenMatcher"/>
  </beans:bean>

  <beans:bean id="NumberTokenMatcher" class="com.NumberTokenMatcher">
login.java

        AuthenticationToken numberToken = (AuthenticationToken) new
NumberAuthToken(number);

        Subject subject = SecurityUtils.getSubject();

        subject.login(numberToken);



--
View this message in context: http://shiro-developer.582600.n2.nabble.com/Apache-Shiro-custom-AuthenticationToken-tp7578964.html
Sent from the Shiro Developer mailing list archive at Nabble.com.