}
protected SkeletonKeyToken createAccessToken(User user, Realm realm)
{
List<Resource> resources = identityManager.getResources(realm);
SkeletonKeyToken token = new SkeletonKeyToken();
token.id(generateId());
token.principal(user.getUsername());
token.audience(realm.getName());
if (realm.getTokenLifespan() > 0)
{
token.expiration((System.currentTimeMillis() / 1000) + realm.getTokenLifespan());
}
RoleMapping realmMapping = identityManager.getRoleMapping(realm, user);
if (realmMapping != null && realmMapping.getRoles().size() > 0)
{
SkeletonKeyToken.Access access = new SkeletonKeyToken.Access();
for (String role : realmMapping.getRoles())
{
access.addRole(role);
}
token.setRealmAccess(access);
}
for (Resource resource : resources)
{
RoleMapping mapping = identityManager.getRoleMapping(realm, resource, user);
if (mapping == null) continue;
SkeletonKeyToken.Access access = token.addAccess(resource.getName())
.verifyCaller(resource.isSurrogateAuthRequired());
for (String role : mapping.getRoles())
{
access.addRole(role);
}
}
if (token.getResourceAccess() == null || token.getResourceAccess().size() == 0) return null;
return token;
}