我创建了一个Java应用程序,该程序执行MS Active Directory与Google网上论坛的同步。它是非交互式应用程序,假定由cronjob在夜间执行。它确实可以在我的笔记本电脑(DEV环境)上正常工作。我的问题是,在首次运行时,它会弹出浏览器窗口,并显示要求授权访问Google API的对话框。单击“允许”按钮后,它会愉快地进行到最后。现在,我需要将其移至运行CentOS且没有浏览器的生产服务器。当我在此环境中运行应用程序时,它会显示以下消息:
Please open the following address in your browser:
https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=520105804541-c7d7bfki88qr8dbkv6oahp22i3oq1jq0.apps.googleusercontent.com&redirect_uri=http://localhost:50089/Callback&response_type=code&scope=https://www.googleapis.com/auth/admin.directory.group.member%20https://www.googleapis.com/auth/admin.directory.orgunit%20https://www.googleapis.com/auth/admin.directory.device.mobile.action%20https://www.googleapis.com/auth/admin.directory.orgunit.readonly%20https://www.googleapis.com/auth/admin.directory.userschema%20https://www.googleapis.com/auth/admin.directory.device.chromeos%20https://www.googleapis.com/auth/admin.directory.notifications%20https://www.googleapis.com/auth/admin.directory.device.chromeos.readonly%20https://www.googleapis.com/auth/admin.directory.device.mobile%20https://www.googleapis.com/auth/admin.directory.group.readonly%20https://www.googleapis.com/auth/admin.directory.group.member.readonly%20https://www.googleapis.com/auth/admin.directory.userschema.readonly%20https://www.googleapis.com/auth/admin.directory.user.alias%20https://www.googleapis.com/auth/admin.directory.user.security%20https://www.googleapis.com/auth/admin.directory.device.mobile.readonly%20https://www.googleapis.com/auth/admin.directory.user%20https://www.googleapis.com/auth/admin.directory.user.readonly%20https://www.googleapis.com/auth/admin.directory.user.alias.readonly%20https://www.googleapis.com/auth/admin.directory.group%20https://www.googleapis.com/auth/apps.groups.settings
Run Code Online (Sandbox Code Playgroud)
这台机器上没有浏览器,但是如果尝试在另一个机器上运行它,则会收到错误400-无效请求。原因很明显,因为它重定向到localhost:50089,并且没有人在另一台计算机上的该端口上侦听。通过在developers.google.com上浏览了多个文档和示例,我找到了一种绕过对话框的方法,方法是创建服务帐户并为其生成主键。
try {
GoogleCredential cr = GoogleCredential
.fromStream(new FileInputStream(keyFile))
.createScoped(SCOPES);
Directory directory = new Directory.Builder(httpTransport, jsonFactory, cr)
.setApplicationName(config.getProperty("google.application.name")).build();
} catch (IOException ex) {
LOG.error("Failed to establish access credentials : ", ex.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
它确实读取了密钥并创建了Directory实例,但是对它的任何请求都将导致403响应代码
{“ code”:403,“ errors”:[{“ domain”:“ global”,“ message”:“未授权访问此资源/ api”,“ reason”:“禁止”
}],“ message”: “未授权访问此资源/ api”}”
但是我已经将该帐户的所有特权委派给了服务帐户。不知道我还能做什么。如果有人可以帮助我摆脱困境,我将不胜感激。
我需要在我的页面上放置一个使用 Vaadin 23 创建的 Article 对象。该文章将包含多个段落,每个段落需要 3-4 行文本。我有:
Paragraph p1 = new Paragraph(p11);
p1.add(p12);
p1.add(p13);
Paragraph p2 = new Paragraph(p21);
p2.add(p22)
...
Article article = new Article(p1, p2, ...);
Run Code Online (Sandbox Code Playgroud)
其中 pNN 是 Java String 实例。我希望将每个字符串放在单独的行上,但不想将它们作为单独的段落。不幸的是,Vaadin HTML 元素中没有 <br>。我尝试在字符串或 <br> 末尾添加 '\n',但它不起作用。没有换行。有谁知道该怎么做?
我需要在页面底部放置三个按钮,我希望它们分别位于左角、中心和右上角。我确实创建了 HorizontalLayout,并在其中添加了按钮。我与各种对齐方式斗争了三天多,但无论我做什么,按钮仍然位于左上角。这是我的代码:
HorizontalLayout bottomLayout = new HorizontalLayout();
bottomLayout.setWidthFull();
bottomLayout.setHeight("82px");
bottomLayout.add(buttonA, buttonB, buttonC);
// bottomLayout.setAlignItems(Alignment.STRETCH);
bottomLayout.setAlignSelf(Alignment.END, buttonC);
bottomLayout.setAlignSelf(Alignment.START, buttonA);
bottomLayout.setAlignSelf(Alignment.CENTER, buttonB);
Run Code Online (Sandbox Code Playgroud)
请告诉我我做错了什么以及如何纠正。另外,我所有的按钮都是 80 像素高,前两个按钮看起来彼此垂直对齐,而第三个按钮看起来要高几个像素。我如何垂直对齐它们?