我正在使用 21 版本的 Vaadin。我有以下代码,取自 Vaadin 网站的一个示例,并由我稍微(纯粹是美丽)修改。其余文件不变。
代码如下。为什么我会得到这样的日志?
2022-01-20 10:08:32.589 DEBUG 12556 --- [nio-8888-exec-6] cephotoarchive.components.DropView:放置 1. 用户在这里 2022-01-20 10:08:38.197 TRACE 12556 --- [nio-8888-exec-1] c.example.photoarchive.SecurityService:身份验证为空 2022-01-20 10:08:38.197 DEBUG 12556 --- [nio-8888-exec-1] cephotoarchive.components.DropView :将 2. 用户放在这里 <>
@Log4j2
@Route(value = "drop", layout = MainAppLayout.class)
public class DropView extends VerticalLayout implements HasComponents {
private final SecurityService securityService;
public DropView(SecurityService securityService) {
this.securityService = securityService;
MultiFileMemoryBuffer buffer = new MultiFileMemoryBuffer();
Upload upload = new Upload(buffer);
upload.setUploadButton(new Button(getTranslation("Upload_files")));
upload.setDropLabel(new Label(getTranslation("Drop_files")));
upload.setMaxFileSize(-1);
log.debug("Place 1. User here <{}>", getUsername());
upload.addFinishedListener(e -> {
log.debug("Place 2. User here <{}>", getUsername());
// my code ... too much :-)
});
add(upload);
}
private String getUsername() {
var user = securityService.getAuthenticatedUser();
if (user != null) return user.getUsername();
return "";
}
}
@Log4j2
@Service
public class SecurityService {
private static final String LOGOUT_SUCCESS_URL = "/";
public UserDetails getAuthenticatedUser() {
SecurityContext context = SecurityContextHolder.getContext();
if (Objects.isNull(context)) {log.trace("context is null");return null;}
Authentication authentication = context.getAuthentication();
if (Objects.isNull(authentication)) {log.trace("authentication is null");return null;}
Object principal = authentication.getPrincipal();
if (Objects.isNull(principal)) {log.trace("principal is null");return null;}
if (principal instanceof UserDetails) {
return (UserDetails) principal;
}
// Anonymous or no authentication.
return null;
}
}