且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java Web 服务客户端基本身份验证

更新时间:2023-11-30 23:51:04

事实证明,有一种简单、标准的方法可以实现我想要的:

It turned out that there's a simple, standard way to achieve what I wanted:

import java.net.Authenticator;
import java.net.PasswordAuthentication;

Authenticator myAuth = new Authenticator() 
{
    @Override
    protected PasswordAuthentication getPasswordAuthentication()
    {
        return new PasswordAuthentication("german", "german".toCharArray());
    }
};

Authenticator.setDefault(myAuth);

没有自定义的sun"类或外部依赖项,也没有手动编码任何东西.

No custom "sun" classes or external dependencies, and no manually encode anything.

我知道 BASIC 安全性并不安全,但我们也在使用 HTTPS.

I'm aware that BASIC security is not, well, secure, but we are also using HTTPS.