我的 Spring 应用程序中有以下方法
public static String getCurrentUserStudentId() {
return ((LdapPerson) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getID();
}
这适用于应用程序运行,但是当我运行调用此方法的测试时,它给出
org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken cannot be cast to fi.utu.security.ldap.userdetails.LdapPerson
我不太熟悉 Spring Security 来提供所有可能相关的文件,但问我。我希望有人能告诉我该怎么做。