Skip to content

Commit 44d5aed

Browse files
committed
Allow using a custom LoginCredentials object
1 parent 6b45130 commit 44d5aed

1 file changed

Lines changed: 62 additions & 47 deletions

File tree

lib/src/main/java/xyz/gianlu/librespot/core/Session.java

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,16 @@ public Authentication.LoginCredentials getCredentials() {
962962
return loginCredentials;
963963
}
964964

965+
/**
966+
* Authenticates with a custom {@link com.spotify.Authentication.LoginCredentials} object.
967+
*
968+
* @param credentials The credentials
969+
*/
970+
public Builder credentials(@NotNull Authentication.LoginCredentials credentials) {
971+
loginCredentials = credentials;
972+
return this;
973+
}
974+
965975
/**
966976
* Authenticates with stored credentials. Tries to read the file specified in the configuration.
967977
*/
@@ -1283,7 +1293,7 @@ static ConnectionHolder create(@NotNull String addr, @NotNull Configuration conf
12831293
Socket sock;
12841294
if (conf.proxySSL) {
12851295
sock = SSLSocketFactory.getDefault().createSocket(conf.proxyAddress, conf.proxyPort);
1286-
} else{
1296+
} else {
12871297
sock = new Socket(conf.proxyAddress, conf.proxyPort);
12881298
}
12891299
OutputStream out = sock.getOutputStream();
@@ -1333,6 +1343,57 @@ protected PasswordAuthentication getPasswordAuthentication() {
13331343
}
13341344
}
13351345

1346+
/**
1347+
* A {@link SocketFactory} that delegates calls. Sockets can be configured after creation by
1348+
* overriding {@link #configureSocket(java.net.Socket)}.
1349+
* <p>
1350+
* Copy/pasted from okhttp3 tests sources for HTTPS proxy support
1351+
*/
1352+
public static class DelegatingSocketFactory extends SocketFactory {
1353+
private final SocketFactory delegate;
1354+
1355+
public DelegatingSocketFactory(SocketFactory delegate) {
1356+
this.delegate = delegate;
1357+
}
1358+
1359+
@Override
1360+
public Socket createSocket() throws IOException {
1361+
Socket socket = delegate.createSocket();
1362+
return configureSocket(socket);
1363+
}
1364+
1365+
@Override
1366+
public Socket createSocket(String host, int port) throws IOException {
1367+
Socket socket = delegate.createSocket(host, port);
1368+
return configureSocket(socket);
1369+
}
1370+
1371+
@Override
1372+
public Socket createSocket(String host, int port, InetAddress localAddress,
1373+
int localPort) throws IOException {
1374+
Socket socket = delegate.createSocket(host, port, localAddress, localPort);
1375+
return configureSocket(socket);
1376+
}
1377+
1378+
@Override
1379+
public Socket createSocket(InetAddress host, int port) throws IOException {
1380+
Socket socket = delegate.createSocket(host, port);
1381+
return configureSocket(socket);
1382+
}
1383+
1384+
@Override
1385+
public Socket createSocket(InetAddress host, int port, InetAddress localAddress,
1386+
int localPort) throws IOException {
1387+
Socket socket = delegate.createSocket(host, port, localAddress, localPort);
1388+
return configureSocket(socket);
1389+
}
1390+
1391+
protected Socket configureSocket(Socket socket) throws IOException {
1392+
// No-op by default.
1393+
return socket;
1394+
}
1395+
}
1396+
13361397
private class Receiver implements Runnable {
13371398
private final Thread thread;
13381399
private volatile boolean running = true;
@@ -1439,50 +1500,4 @@ public void run() {
14391500
LOGGER.trace("Session.Receiver stopped");
14401501
}
14411502
}
1442-
1443-
/**
1444-
* A {@link SocketFactory} that delegates calls. Sockets can be configured after creation by
1445-
* overriding {@link #configureSocket(java.net.Socket)}.
1446-
*
1447-
* Copy/pasted from okhttp3 tests sources for HTTPS proxy support
1448-
*/
1449-
public static class DelegatingSocketFactory extends SocketFactory {
1450-
private final SocketFactory delegate;
1451-
1452-
public DelegatingSocketFactory(SocketFactory delegate) {
1453-
this.delegate = delegate;
1454-
}
1455-
1456-
@Override public Socket createSocket() throws IOException {
1457-
Socket socket = delegate.createSocket();
1458-
return configureSocket(socket);
1459-
}
1460-
1461-
@Override public Socket createSocket(String host, int port) throws IOException {
1462-
Socket socket = delegate.createSocket(host, port);
1463-
return configureSocket(socket);
1464-
}
1465-
1466-
@Override public Socket createSocket(String host, int port, InetAddress localAddress,
1467-
int localPort) throws IOException {
1468-
Socket socket = delegate.createSocket(host, port, localAddress, localPort);
1469-
return configureSocket(socket);
1470-
}
1471-
1472-
@Override public Socket createSocket(InetAddress host, int port) throws IOException {
1473-
Socket socket = delegate.createSocket(host, port);
1474-
return configureSocket(socket);
1475-
}
1476-
1477-
@Override public Socket createSocket(InetAddress host, int port, InetAddress localAddress,
1478-
int localPort) throws IOException {
1479-
Socket socket = delegate.createSocket(host, port, localAddress, localPort);
1480-
return configureSocket(socket);
1481-
}
1482-
1483-
protected Socket configureSocket(Socket socket) throws IOException {
1484-
// No-op by default.
1485-
return socket;
1486-
}
1487-
}
14881503
}

0 commit comments

Comments
 (0)