Java Network HTTP Authentication :-
This code will help u to authenticate your web application using system credential.
If u want to set the authentication for network http authentication for your application U need to override the method of Authenticator Class and set your password
static class CustomAuthenticator extends Authenticator {
static final String userId="test";
static final String password="password";
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication(userId,password.toCharArray()));
}
}
public static void main(String[] args) throws Exception {
Authenticator.setDefault(new CustomAuthenticator ());//set the custom default network login password
PasswordAuthentication pswAuth=new CustomAuthenticator().getPasswordAuthentication();
System.out.println("Default authentication User :"+pswAuth.getUserName());
System.out.println("Default authentication Password :"+pswAuth.getPassword().toString()); }
}
No comments:
Post a Comment