chb0kotlin
02/14/2018, 6:59 AMinterface AclClassRepository : PagingAndSortingRepository<AclClass, Long>
@Component
class SecurityConfiguration(private val classRepo: AclClassRepository) : WebSecurityConfigurerAdapter() {
@PostConstruct
private fun init() {
val context = SecurityContextHolder.getContext()
context.authentication = UsernamePasswordAuthenticationToken("system", "system",
createAuthorityList("ROLE_ADMIN"))
val all = classRepo.findAll()
val reflections = Reflections(this.javaClass.`package`.name)
val entities = all - reflections.getTypesAnnotatedWith(Entity::class.java)
// Error:(64, 42) Kotlin: Type parameter bound for S in fun <S : AclClass!> save(p0: S): S
is not satisfied: inferred type Any! is not a subtype of AclClass!
entities.forEach { classRepo.save(it) }
//Error:(65, 23) Kotlin: Type parameter bound for S in fun <S : AclClass!> saveAll(p0: (Mutable)Iterable<S!>): (Mutable)Iterable<S!>
is not satisfied: inferred type Any! is not a subtype of AclClass!
classRepo.saveAll(entities)
SecurityContextHolder.clearContext()
}
}
Max Russek
02/14/2018, 7:40 AMclassRepo.findAll()
but it looks like entities
is a set of Class
instances (I inferred this only because of the reflection). In that case, it seems that there is no way that elements of entities
can be of a subtype of AclClass
like apparently the type bound requiresr4zzz4k
02/14/2018, 12:19 PMclassRepo
contains objects of type AclClass
, and reflections.getTypesAnnotatedWith(...)
returns Set<Class<*>>
. You have to have a way of casting your `Class<*>`es to `AclClass`es.