Nortel Networks NN46120-104 User Manual

Page 278

Advertising
background image

278

Using the Port Forwarder API

private String getCookieFromURL(String spec) {

try {

URL url = new URL(spec);

URLConnection connection = null;

((HttpURLConnection) connection).setFollowRedirects(false);

connection = url.openConnection();

connection.getInputStream();

/* check if we are authorized */

if (connection != null) {

String headerField =

getHeaderField(connection, SET_COOKIE_HEADER);

return headerField.substring (headerField.indexOf(’=’)

+ 1,

headerField.indexOf(’;’));

} else {

return null;

}

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return null;

}

PortForwarderAuthenticator pfa =

new PortForwarderAuthenticator() {

public PortForwarderCredentials getCredentials() {

cookie = getCookieFromURL(loginUrl);

if (cookie == null) {

return null;

}

cred.setNortelToken(cookie);

return cred;

}

public PasswordAuthentication getProxyCredentials() {

LoginDialog loginDialog = new LoginDialog();

return new PasswordAuthentication(loginDialog.getUserId()

,

loginDialog.getPassword(

)

.toCharArray(

));

}

};

portForwarder.setAuthenticator(pfa);

Nortel VPN Gateway

User Guide

NN46120-104

02.01

Standard

14 April 2008

Copyright © 2007-2008 Nortel Networks

.

Advertising