通过 OAuth2 实现(内部开发或第三方,如 Google、Facebook、Login With Amazon 等),是否可以代表登录到移动应用程序或 Web 应用程序的用户生成身份验证代码,而无需需要用户执行任何操作?
获取身份验证码的典型流程需要用户对所请求的范围进行身份验证和授权。但在这种情况下,用户已经通过应用程序的身份验证,因此我想避免要求用户再次登录。
调用外部第三方 API 需要身份验证代码,该 API 最终将用身份验证代码交换刷新/访问令牌。后端系统(与 API 关联)需要根据与其共享的身份验证代码获取自己的刷新/访问令牌。这不是一次性使用令牌;系统需要为登录用户拥有自己的令牌,独立于移动客户端。
我不知道何时在 Electron 内容页面(例如 index.html)中使用require('jslib')vs。<script src=""></script>使用jQuery,我发现它需要按如下方式加载:
<script>window.$ = window.jQuery = require('./js/jquery-2.2.4.min.js');</script>
Run Code Online (Sandbox Code Playgroud)
我需要开始使用其他一些库(例如 Handlebars、ds3.js、Bootstrap 等),但我不确定是否应该使用<script>标签加载这些库,或者是否应该加载require它们。
Docker 容器(基于microsoft/dotnet-framework映像)中的 .NET 应用程序无法连接到安装在 Docker 主机系统上的 SQL Server 2016。Docker 主机为 Windows Server 2016。Docker 版本为 17.03.2-ee-5。
我使用以下命令序列运行容器和 .NET 应用程序:
docker run -it microsoft/dotnet-framework cmd
docker cp App <container-id>:/
docker exec -it <container-id> cmd
cd App
TestConn.exe
Run Code Online (Sandbox Code Playgroud)
TestConn.exe 在大约 10 秒后抛出异常,抱怨它无法连接到 SQL Server。连接字符串是:
Data Source=localhost;Initial Catalog=SomeDB;Persist Security Info=False;User ID=appuser;Password=apppwd;MultipleActiveResultSets=False;Connection Timeout=30;
Run Code Online (Sandbox Code Playgroud)
如果我在 Docker 主机系统中运行 TestConn.exe,则应用程序成功连接到 SQL Server。
我添加--expose=1433到docker run命令 - 没有用。我希望它起作用的方式是 TestConn.exe 尝试连接到 localhost(默认 SQL 端口 1433),然后连接到 Docker 主机中的端口 1433,该端口对应于 SQL Server。
我正在使用一个简单的基于 Spring Boot 的 RestController。我正在返回 JSON,但我无法控制响应中生成的密钥的名称。POJO 看起来像这样:
public class SomePojo {
@JsonProperty("name")
private String fullName;
@JsonProperty("name")
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我创建一个新实例如下:
SomePojo sm = new SomePojo();
sm.setFullName("John Doe");
Run Code Online (Sandbox Code Playgroud)
并返回@ResponseBody 中的实例。我期待看到
{ "name" : "John Doe" }
Run Code Online (Sandbox Code Playgroud)
但我看到
{ "fullName" : "John Doe" }
Run Code Online (Sandbox Code Playgroud)
我尝试@JsonProperty("name")在属性及其 getter 上使用注释,但它不起作用。Spring Boot 版本是 1.4.2。关于我缺少什么的任何建议?
我需要将[Windows] Docker容器作为可执行文件运行,运行相当复杂的PowerShell脚本(调用Java和.NET应用程序)并退出。Docker文档建议ENTRYPOINT用于此目的。因此,我继续创建了一个包含以下内容的Dockerfile:
FROM microsoft/dotnet-framework
COPY run.ps1 /
ENTRYPOINT [ "powershell.exe", "C:\\run.ps1" ]
Run Code Online (Sandbox Code Playgroud)
的内容run.ps1(此问题的超级简化):
gci
write-host "looks like everything is good!"
Run Code Online (Sandbox Code Playgroud)
然后,我运行了以下命令:
# Build the Docker image
docker build --rm -t testdockerps .
# Create/run container using above image
docker run -it testdockerps
Run Code Online (Sandbox Code Playgroud)
容器成功运行,显示的内容,C:\后跟消息- looks like everything is good!。
根据我的观察,我有几个问题:
ENTRYPOINTJSON数组的第一个元素?我应该SHELL在Dockerfile中使用命令吗?我有一个Map<String,Object>包含值的条目List<String>.我需要把内容List<String>变成一个Set<String>.我使用以下代码:
Map<String, Object> map = SomeObj.getMap();
if (map.get("someKey") instance of List<?>) {
Set<String> set = new HashSet<String>((List<String>) map.get("someKey"));
}
Run Code Online (Sandbox Code Playgroud)
我的基于Eclipse的IDE在这一行上有几个警告:
代码编译并按预期运行.有没有更好的方法来做到这一点?注释该行@SuppressWarnings("unchecked")是我的最后和最不喜欢的选项.
我正在尝试<select>使用jQuery和JSON响应中返回的字符串数组中的选项值动态填充元素。选项值之一是Joe's Cafe解码时的值Joe's Cafe。但是,当我使用以下代码时:
$.each(optionVals, function(idx, elem) {
$('#restaurant').append('<option value="' + elem + '">' + elem + '</option>');
});
Run Code Online (Sandbox Code Playgroud)
相应的选项不是我期望的。我看到了:
<option value="Joe's Cafe">Joe's Cafe</option>
Run Code Online (Sandbox Code Playgroud)
代替这个:
<option value="Joe's Cafe">Joe's Cafe</option>
Run Code Online (Sandbox Code Playgroud)
如何防止jQuery '在.append()操作中解码HTML实体?我检查了JSON响应,并且HTML实体是完整的。加载选项并将HTML实体解码为单引号后,我检查了源代码'。
我curl用来测试用户帐户创建 API 如下:
curl -s -X POST "https://$APISERVER/users" \
-H 'Content-Type: application/json' \
-d '{ \
"username": "'$NEWUSERNAME'", \
"firstName": "'$NEWUSERFIRSTNAME'", \
"lastName": "'$NEWUSERLASTNAME'", \
"displayName": "'$NEWUSERDISPLAYNAME'", \
"password": "'$NEWUSERPASSWORD'" \
}'
Run Code Online (Sandbox Code Playgroud)
并且变量是通过命令行参数提供的:
APISERVER=http://localhost:8080
NEWUSERNAME=$1
NEWUSERPASSWORD=$2
NEWUSERFIRSTNAME=$3
NEWUSERLASTNAME=$4
# Calculated variable
NEWUSERDISPLAYNAME="${NEWUSERFIRSTNAME} ${NEWUSERLASTNAME}"
Run Code Online (Sandbox Code Playgroud)
脚本调用示例如下:./test-new-user.sh jdoe Hello123 John Doe,产生以下变量值:
NEWUSERNAME=jdoe
NEWUSERPASSWORD=Hello123
NEWUSERFIRSTNAME=John
NEWUSERLASTNAME=Doe
Run Code Online (Sandbox Code Playgroud)
(我打算NEWUSERDISPLAYNAME设置为“John Doe”)
但是我从服务器返回一个异常,因为curl命令中的有效负载似乎被切断、不完整或格式错误。
JSON parse error: Unexpected end-of-input in VALUE_STRING\n at [Source:
java.io.PushbackInputStream@2eda6052; line: 1, column: 293]; nested
exception is …Run Code Online (Sandbox Code Playgroud) 我无法运行附加的Spring Boot采样器应用程序.它有一个AMQP启动器,需要RabbitMQ.从根本上说,它是一个简单的应用程序,只是向RabbitMQ Exchange发送一个消息,并绑定一个队列.我收到以下错误:
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.company.messaging.MessageDeliveryManager com.company.exec.Application.messageDeliveryManager; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.company.messaging.MessageDeliveryManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
Run Code Online (Sandbox Code Playgroud)
Application.java
package com.company.exec;
@SpringBootApplication
public class Application implements CommandLineRunner {
@Autowired
MessageDeliveryManager messageDeliveryManager;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
public void run(String... args) throws Exception {
messageDeliveryManager.sendMessage(String message);
}
}
Run Code Online (Sandbox Code Playgroud)
MessageDeliveryManager.java
package com.company.messaging;
public …Run Code Online (Sandbox Code Playgroud) 我已经编写了一个基本的 Java 应用程序来使用从 Node.js 服务器流式传输的 SSE(服务器发送的事件),使用 Jersey SSE 客户端。但是,我无法接收事件。为了验证服务器组件是否按预期工作,我使用了curl以下内容:
curl -v -H "Accept: text/event-stream" http://localhost:8080/events/
Run Code Online (Sandbox Code Playgroud)
我收到以下回复:
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /events/ HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: text/event-stream
>
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Content-Type: text/event-stream
< Cache-Control: no-cache
< Connection: keep-alive
< Date: Wed, 26 Apr 2017 17:12:00 GMT
< Transfer-Encoding: chunked
<
event: ping
data: 0.6637400726922664
event: ping
data: 0.8538157046725585
Run Code Online (Sandbox Code Playgroud)
我的 …
我正在开发一个 Spring Boot [web] REST 风格的应用程序ServletInitializer(因为它需要部署到现有的 Tomcat 服务器)。它有一个@RestControllerwith 方法,调用该方法时需要写入 Redis pub-sub channel。我的 Redis 服务器在本地主机上运行(默认端口,无密码)。POM 文件的相关部分具有所需的启动依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当我部署 WAR 并到达端点时http://localhost:8080/springBootApp/health,我得到以下响应:
{
"status": "DOWN",
"diskSpace": {
"status": "UP",
"total": 999324516352,
"free": 691261681664,
"threshold": 10485760
},
"redis": {
"status": "DOWN",
"error": "org.springframework.data.redis.RedisConnectionFailureException: java.net.SocketTimeoutException: Read timed out; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out"
}
}
Run Code Online (Sandbox Code Playgroud)
我将以下内容添加到我的 Spring Boot 应用程序类中:
@Bean
JedisConnectionFactory jedisConnectionFactory() {
return new JedisConnectionFactory();
}
@Bean
public RedisTemplate<String, Object> redisTemplate() …Run Code Online (Sandbox Code Playgroud) 我试图找到使用Java最简洁(和有意义)的方法,Optional从a读取第一个值Optional<String>并返回String(如果存在),或返回"NOT_FOUND".这是我正在使用的代码:
public static String getValue(Optional<String> input) {
return input.ifPresent(val -> val.get()).orElse("NOT_FOUND")
}
Run Code Online (Sandbox Code Playgroud)
Optional的方法显然有非常特殊的用途,但API让我感到困惑.
更新(4/13/2018):
我的问题中的代码不正确,因为如果我认为val是Optional中的值,那么val.get()没有任何意义.谢谢你指出这一点,@ okttman.
另外,我在接受的答案的注释中添加了我的问题的另一部分,即我需要一种方法来操作String值,如果存在,在返回之前.将orElse("NOT_FOUND")仍然适用,如果选不包含值.那么OptionalAPI 的可接受用途是什么来实现以下目标呢?
public static String getValue(Optional<String> input) {
return input.isPresent() ? input.get().substring(0,7).toUpperCase() : "NOT_FOUND";
}
Run Code Online (Sandbox Code Playgroud)
@Aominè的回答和后续评论都涉及这个问题的两个部分.
我需要将UTC日期和时间字符串(例如20180531_132001Z)解析为Java 8日期和时间对象.如何使用Java 8的新日期和时间库进行此操作?我看到的大多数示例都是针对LocalDateTime的,如下所示:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss'Z'");
LocalDateTime localDateTime = LocalDateTime.parse("20180531_132001Z", formatter);
System.out.println(localDateTime);
System.out.println(localDateTime.atOffset(ZoneOffset.UTC));
Run Code Online (Sandbox Code Playgroud)
代码输出:
2018-05-31T13:20:01
2018-05-31T13:20:01Z
Run Code Online (Sandbox Code Playgroud)
我最终需要将它持久化到SQL Server数据库表(列类型是[datetime2](7),使用[Spring] JDBC.
更新:根据评论和答案,我认为我的问题没有经过深思熟虑.换句话说,如果我得到一个输入字符串并且我解析它而不考虑任何区域或偏移量,我将得到一个LocalDateTime对象.如何获取该对象并将封装的值转换为UTC日期和时间?