Yes we are using custom caching.
Our Realm uses data from a Postgres database
Our custom Cache is using data from Redis.
At first when looking at the code we use in the Realm, there is no code
directly referencing our Cache or CacheManager, but looking at our Spring
configuration I am setting the cacheManager property in the Realm, which
comes from extending AuthorizingRealm.
I actually, haven't seen this exception come up anymore, but are you saying
I shouldn't be setting the cacheManager property?
Here is our code
@Transactional
public class BlahRealm extends AuthorizingRealm {
@Autowired
ApplicationContext context;
private AccountService accountService;
private AccountService getAccountService() {
if (this.accountService == null) {
this.accountService = context.getBean(AccountService.class);
}
return this.accountService;
}
private SimpleAccount getAccount(String username) {
AccountSecurity accountSecurity =
getAccountService().findByUserName(username);
if (accountSecurity == null) {
return null;
}
//ByteSource byteSource =
ByteSource.Util.bytes(accountSecurity.getSaltValue());
MutablePrincipalCollection principalCollection = new
SimplePrincipalCollection();
principalCollection.add(accountSecurity.getUsername(), getName());
principalCollection.add(accountSecurity.getId(), getName());
SimpleAccount account = new SimpleAccount(principalCollection,
accountSecurity.getPassword(), getName());
Set<UserRole> roles = accountSecurity.getRoles();
for (UserRole role : roles) {
account.addRole(role.getRole());
}
Set<UserGroup> groups = accountSecurity.getGroups();
for (UserGroup group : groups) {
account.addStringPermission(group.getName());
}
return account;
}
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection
principals) {
String username = (String)principals.getPrimaryPrincipal();
return getAccount(username);
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken
authenticationToken) throws AuthenticationException {
UsernamePasswordToken upToken = (UsernamePasswordToken)
authenticationToken;
return getAccount(upToken.getUsername());
}
@Override
public String getName() {
return "BlahRealm";
}
@Override
public boolean supports(AuthenticationToken authenticationToken) {
return (authenticationToken instanceof UsernamePasswordToken);
}
}
And here is our Spring configuration for that bean
<bean id="blahRealm"
class="com.blah.account.security.shiro.realm.BlahRealm">
<property name="name" value="blah"/>
<property name="credentialsMatcher" ref="credentialsMatcher"/>
<property name="cacheManager" ref="cacheManager"/>
</bean>
Thanks for taking the time to look at this. I might just remove the
cacheManager property setting to see what happens.
Thanks
Mark
--
View this message in context:
http://shiro-user.582556.n2.nabble.com/Getting-a-ClassCast-Exception-with-taglib-SimpleSession-tp7578430p7578492.html
Sent from the Shiro User mailing list archive at Nabble.com.