gpt4 book ai didi

java - ReSTLet如何解码HTTP基本认证中的secret

转载 作者:行者123 更新时间:2023-11-29 05:05:44 25 4
gpt4 key购买 nike

我有以下类(class)处理我的路线之一:

public class HotelsSrv extends ServerResource implements 
HotelsListResource {
private String hotelId;

@Override
protected void doInit() throws ResourceException {
super.doInit();
String str;
String secret = getRequest().getChallengeResponse().getSecret().toString();
byte[] bytes = new BASE64Decoder().decodeBuffer(secret)
str = new String(bytes);

System.out.println("user: "+getRequest().getChallengeResponse().getIdentifier());

System.out.println("password: "+str);
}

我正在尝试解码 secret ,以便我可以使用自定义过程对其进行验证,但此行会引发未知异常:

    byte[] bytes = new BASE64Decoder().decodeBuffer(secret)

最佳答案

试试这段代码

public void authenticate(HttpServletRequest req) {
String authhead = req.getHeader("Authorization");

if (authhead != null) {
// *****Decode the authorisation String*****
byte[] e = Base64.decode(authhead.substring(6));
String usernpass = new String(e);
// *****Split the username from the password*****
String user = usernpass.substring(0, usernpass.indexOf(":"));
String password = usernpass.substring(usernpass.indexOf(":") + 1);
// check username and password
}
}

关于java - ReSTLet如何解码HTTP基本认证中的secret,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30422247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com