在使用 Netty 编写的 HTTP 反向代理中,如何确定单个 HTTP 请求(标头 + 任何正文内容)读取的字节数或单个 HTTP 响应写入的字节数?如何使 Netty 的开箱即用HTTPRequestDecoder和HTTPResponseEncoder(或超类)能够使这些信息可供其他ChannelHandler人使用?
我知道很容易ChannelHandler在管道的开头粘贴 a 以记录通道写入和读取的字节总数,但我不希望这样 - 我想知道每个请求和每个响应读取或写入的字节数。由于 Netty 开箱即用的 HTTP 编码器和解码器负责读取和写入,因此我希望可以对某些内容进行子类化并“挂钩”读/写逻辑,以获取每个消息编码或解码的计数。这可能吗?
在表示请求/响应大小直方图以及支持 HTTP 扩展访问日志格式时,此数据非常重要:
http://httpd.apache.org/docs/current/mod/mod_log_config.html
从该页面,访问记录单个请求/响应对时使用的日志格式字符串标记:
%I Bytes received, including request and headers. Cannot be zero. You need to enable mod_logio to use this.
%O Bytes sent, including headers. May be zero in rare cases such as when a request is aborted before a response is sent. You need to enable …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种基于过期令牌的真实性更新jwt令牌的机制。这是我尝试过的
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.exceptions.TokenExpiredException;
import com.auth0.jwt.interfaces.DecodedJWT;
import constants.AppConstants;
import java.io.UnsupportedEncodingException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
public class JwtUtil {
private static JWTVerifier verifier;
private static String secret = AppConstants.JWT_KEY;
static {
Algorithm algorithm = null;
try {
algorithm = Algorithm.HMAC256(secret);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
verifier = JWT.require(algorithm)
.withIssuer("Issuer")
.build();
}
public static String getSignedToken(Long userId) {
Algorithm algorithm = null;
try {
algorithm = Algorithm.HMAC256(secret);
} catch (UnsupportedEncodingException e) …Run Code Online (Sandbox Code Playgroud) 我正在研究用 Kotlin/Native 编写的命令行工具的概念证明,因为它似乎是跨平台二进制文件的理想语言和运行时。
该命令行工具需要定期与 os 用户 $PATH 或 shell 环境中的操作系统可执行文件、命令和/或 shell 函数进行交互。但是,我在kotlin-native 示例或文档中没有看到任何可能指示如何执行以下操作的示例:
在 JVM 领域,我们可以使用java.lang.ProcessBuilder所有这些,但这显然在 Kotlin/Native 中不可用。
我找到了 cinterop/posixplatform.posix.system函数,但这并不能让您访问进程的流。
在我的网络研究中,我发现了一个非常好的 C教程,它表明唯一干净的方法是使用forkanddup2等,但我不清楚这是否或如何转换为 Kotlin/Native 代码。
我正在使用 JJWT 库生成 JWT 令牌。我按如下方式生成令牌。我使用虚拟值作为我的密钥。
我们可以假设jwt.security.key=security-key
@Value("${jwt.security.key}")
private String key;
@Value("${ws.issuer}")
private String issuer;
static final long ONE_MINUTE_IN_MILLIS=60000;
static final long TOKEN_DURATION_IN_MIN=30L;
private SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
@Override
public String issueToken(String userName) {
long nowMillis = System.currentTimeMillis();
long expMillis = nowMillis + (ONE_MINUTE_IN_MILLIS * TOKEN_DURATION_IN_MIN);
return Jwts
.builder()
.setId("01")
.setIssuedAt(new Date(nowMillis))
.setHeaderParam("typ","JWT")
.setSubject(userName)
.setIssuer(issuer)
.setExpiration(new Date(expMillis))
.signWith(signatureAlgorithm, key).compact();
}
Run Code Online (Sandbox Code Playgroud)
虽然token可以成功解码。每次我验证 jwt.io 调试器的签名时,总是会导致签名无效。可以在这里看到。
jenv plugins我相信,该命令将向您显示所有可用的插件。
是否有jenv指示实际启用了哪些插件的命令?
我有一个以下实用程序类,但是每当我通过验证方法检查过期的令牌时,它都不会抛出JWtVerificationException.
public class Token {
private static String SECRET = "c3bff416-993f-4760-9275-132b00256944";
public static String get(String name, String value) throws UnsupportedEncodingException {
return JWT.create()
.withIssuer("auth0")
.withClaim(name, value)
.withClaim("random", String.valueOf(UUID.randomUUID()))
.withExpiresAt(new Date(System.currentTimeMillis() + (4 * 60 * 60 * 1000)))
.sign(Algorithm.HMAC256(Token.SECRET));
}
public static DecodedJWT verify(String token) throws JWTVerificationException, UnsupportedEncodingException {
JWTVerifier verifier = JWT.require(Algorithm.HMAC256(Token.SECRET))
.withIssuer("auth0")
.acceptExpiresAt(4)
.build();
return verifier.verify(token);
}
}
Run Code Online (Sandbox Code Playgroud)
根据网站https://github.com/auth0/java-jwt
验证令牌时,时间验证会自动发生,从而导致
JWTVerificationException在值无效时抛出异常。
编辑:
当客户端每 5 分钟更新一次令牌时,接下来的工作是否有效,或者我应该添加几秒钟来适应任何网络延迟?
创造
.withExpiresAt(new Date(System.currentTimeMillis() + (5 * 60 * 1000))) …Run Code Online (Sandbox Code Playgroud) 我创建了一个包含文件的Servlet 3.0 Web片段jar:
/META-INF/resources/WEB-INF/classes/com/foo/whatever/i18n.properties
应用程序启动时由Web片段启用的其中一个Servlet上下文侦听器执行以下代码:
public static final String BUNDLE_BASE_NAME = "com.foo.whatever.i18n";
//... later:
ResourceBundle.getBundle(BUNDLE_BASE_NAME, locale);
Run Code Online (Sandbox Code Playgroud)
这意味着i18n.properties如果最终用户未在其Web应用程序中的相同路径中指定自己的文件,则应使用Web片段的上述文件.
这适用于Tomcat 7,但不适用于Jetty 8.这是在Jetty 8中部署时产生的异常:
java.util.MissingResourceException:找不到基本名称com.foo.whatever.i18n的bundle,locale en_US
有没有办法让Jetty 8兑现Web片段的类路径贡献?
目前,我的Web应用程序的所有用户都通过stormpath进行身份验证.从现在开始,该Web应用程序将需要使用Apigee上托管的rest api.在这里开始我的怀疑.Apigee通过oauth2.0授予对API的访问权限.那很棒.但是,我想知道我是否能够在Stormpath服务中保留当前的webapp身份验证.我不是Oauth的专家.因此,我不确定在Stormpath中进行身份验证是否可行,然后在Apigee中请求一个AccessToken.WebApplication将具有客户端凭据以请求访问令牌.直截了当:用户是否可以在第三方服务中进行身份验证,并且仍然可以获得Apigee托管的Rest API的Oauth访问令牌?
非常感谢.