Announcement Announcement Module
Collapse
No announcement yet.
Spring Equivalent to java.net.Authenticator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Equivalent to java.net.Authenticator

    I have a method that looks like this, and is used by the client in the manner shown in the 2nd code snippet. I am using Spring beans in my app, so I am wondering if Spring has their own way of doing this? I can inject the username/password easily enough, but I am wondering if there is a Spring-centric approach.

    The client is accessing a password protected URL that is hosting a web service on a private network

    Code:
    import java.net.Authenticator;
    
    public class MyAuthenticator extends Authenticator {
        protected PasswordAuthentication getPasswordAuthentication() {
            String promptString = getRequestingPrompt();
            String hostname = getRequestingHost();
            InetAddress ipaddr = getRequestingSite();
            int port = getRequestingPort();
    
            String username = "myusername";
            String password = "mypassword";
            return new PasswordAuthentication(username, password.toCharArray());
        }
    }

    Client code:


    Code:
    Authenticator.setDefault(new MyAuthenticator());

  • #2
    Hi,
    Did it worked for you?
    I am also having the same issue. I wanted to access the spring secured URL from my application. When i try from browser after login it is working perfectly. But when i am accessing the url with application with imageio.read(url), the authentication object is not passed. How can i pass the Spring authentication with javaio.read(url)??

    Otherwise Is there any equalant for java.net.Authenticator?

    some one please help me.

    Comment

    Working...
    X