Example usage for org.apache.shiro.authc Account getRoles

List of usage examples for org.apache.shiro.authc Account getRoles

Introduction

In this page you can find the example usage for org.apache.shiro.authc Account getRoles.

Prototype

Collection<String> getRoles();

Source Link

Document

Returns the names of all roles assigned to a corresponding Subject.

Usage

From source file:net.swigg.security.example.ExampleRealm.java

License:Open Source License

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    UsernamePasswordToken upToken = UsernamePasswordToken.class.cast(token);
    String principal = upToken.getUsername();
    Account account = this.accountRepository.get(principal);

    // no account matches that principal
    if (null == account) {
        throw new UnknownAccountException();
    }//from   w  ww .  j ava  2s . com

    Set<Object> principals = Sets.newHashSet(account.getName(), account);
    principals.addAll(account.getRoles());
    PrincipalCollection principalCollection = new SimplePrincipalCollection(principals, getName());

    return new SimpleAuthenticationInfo(principalCollection, account.getPassword());
}