update oidc+partey
This commit is contained in:
@@ -149,27 +149,21 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
if (!StringUtils.hasText(config.getAccessToken()) || config.getExpires() == null
|
||||
|| config.getExpires().isBefore(Instant.now())) {
|
||||
|
||||
String authHeader = "Basic "
|
||||
+ new String(Base64.getEncoder()
|
||||
.encode(String
|
||||
.format("%s:%s", config.getClientId(), config.getClientSecret())
|
||||
.getBytes()));
|
||||
WebClient.RequestBodySpec request = WebClient.builder().baseUrl(config.getAccountUrl())
|
||||
.build().method(HttpMethod.POST)
|
||||
.uri(uriBuilder -> uriBuilder.path("/api/token").build())
|
||||
String authHeader = "Basic " + new String(Base64.getEncoder()
|
||||
.encode(String.format("%s:%s", config.getClientId(), config.getClientSecret()).getBytes()));
|
||||
WebClient.RequestBodySpec request = WebClient.builder().baseUrl(config.getAccountUrl()).build()
|
||||
.method(HttpMethod.POST).uri(uriBuilder -> uriBuilder.path("/api/token").build())
|
||||
.header(HttpHeaders.AUTHORIZATION, authHeader)
|
||||
.header(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
|
||||
|
||||
request.bodyValue("grant_type=refresh_token&refresh_token="
|
||||
+ config.getRefreshToken());
|
||||
request.bodyValue("grant_type=refresh_token&refresh_token=" + config.getRefreshToken());
|
||||
|
||||
String jsonString = request.retrieve().bodyToMono(String.class).block();
|
||||
|
||||
if (StringUtils.hasText(jsonString)) {
|
||||
JsonObject response = JsonParser.parseString(jsonString).getAsJsonObject();
|
||||
config.setAccessToken(response.get("access_token").getAsString());
|
||||
config.setExpires(Instant.now().plus(response.get("expires_in").getAsLong(),
|
||||
ChronoUnit.SECONDS));
|
||||
config.setExpires(Instant.now().plus(response.get("expires_in").getAsLong(), ChronoUnit.SECONDS));
|
||||
|
||||
if (response.has("refresh_token")) {
|
||||
config.setRefreshToken(response.get("refresh_token").getAsString());
|
||||
@@ -197,8 +191,7 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
|
||||
WebClient.RequestBodySpec request = webClient.method(HttpMethod.GET)
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/me/player").build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer "
|
||||
+ config.getAccessToken());
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + config.getAccessToken());
|
||||
|
||||
String jsonString = request.retrieve().bodyToMono(String.class).block();
|
||||
|
||||
@@ -222,11 +215,9 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
device_ids.add(config.getDeviceId());
|
||||
queryParameters.add("device_ids", device_ids.toString());
|
||||
queryParameters.add("play", "true");
|
||||
request = webClient.method(HttpMethod.PUT)
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/me/player")
|
||||
.queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer "
|
||||
+ config.getAccessToken());
|
||||
request = webClient.method(HttpMethod.PUT).uri(
|
||||
uriBuilder -> uriBuilder.path("/v1/me/player").queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + config.getAccessToken());
|
||||
|
||||
request.retrieve().bodyToMono(String.class).block();
|
||||
return getStatus();
|
||||
@@ -280,19 +271,15 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
queryParameters.add("context_uri", context_uri);
|
||||
}
|
||||
WebClient.RequestBodySpec request = webClient.method(HttpMethod.PUT)
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/me/player/play")
|
||||
.queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer "
|
||||
+ config.getAccessToken());
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/me/player/play").queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + config.getAccessToken());
|
||||
|
||||
try {
|
||||
request.retrieve().bodyToMono(String.class).block();
|
||||
logger.debug("started playback");
|
||||
} catch (Exception e) {
|
||||
if (!StringUtils.hasText(context_uri)
|
||||
&& StringUtils.hasText(config.getFallbackContextId())) {
|
||||
logger.debug("retry to start playback with: "
|
||||
+ config.getFallbackContextId());
|
||||
if (!StringUtils.hasText(context_uri) && StringUtils.hasText(config.getFallbackContextId())) {
|
||||
logger.debug("retry to start playback with: " + config.getFallbackContextId());
|
||||
tryStartPlayback(config.getFallbackContextId());
|
||||
} else {
|
||||
config.setActive(false);
|
||||
@@ -321,13 +308,12 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
if (offset != null) {
|
||||
queryParameters.add("offset", String.valueOf(offset));
|
||||
}
|
||||
WebClient.RequestBodySpec request = webClient.method(HttpMethod.GET).uri(
|
||||
uriBuilder -> uriBuilder.path("/v1/search").queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer "
|
||||
+ config.getAccessToken());
|
||||
WebClient.RequestBodySpec request = webClient.method(HttpMethod.GET)
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/search").queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + config.getAccessToken());
|
||||
|
||||
String jsonString = request.retrieve().bodyToMono(String.class)
|
||||
.onErrorResume(e -> Mono.just(e.getMessage())).block();
|
||||
String jsonString = request.retrieve().bodyToMono(String.class).onErrorResume(e -> Mono.just(e.getMessage()))
|
||||
.block();
|
||||
|
||||
if (StringUtils.hasText(jsonString)) {
|
||||
return JsonParser.parseString(jsonString);
|
||||
@@ -352,14 +338,12 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
if (limit != null) {
|
||||
queryParameters.add("limit", String.valueOf(limit));
|
||||
}
|
||||
WebClient.RequestBodySpec request = webClient.method(HttpMethod.GET)
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/me/player/recently-played")
|
||||
.queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer "
|
||||
+ config.getAccessToken());
|
||||
WebClient.RequestBodySpec request = webClient.method(HttpMethod.GET).uri(
|
||||
uriBuilder -> uriBuilder.path("/v1/me/player/recently-played").queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + config.getAccessToken());
|
||||
|
||||
String jsonString = request.retrieve().bodyToMono(String.class)
|
||||
.onErrorResume(e -> Mono.just(e.getMessage())).block();
|
||||
String jsonString = request.retrieve().bodyToMono(String.class).onErrorResume(e -> Mono.just(e.getMessage()))
|
||||
.block();
|
||||
|
||||
if (StringUtils.hasText(jsonString)) {
|
||||
return JsonParser.parseString(jsonString);
|
||||
@@ -396,10 +380,8 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
|
||||
queryParameters.add("device_id", config.getDeviceId());
|
||||
WebClient.RequestBodySpec request = webClient.method(HttpMethod.PUT)
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/me/player/play")
|
||||
.queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer "
|
||||
+ config.getAccessToken());
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/me/player/play").queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + config.getAccessToken());
|
||||
|
||||
JsonObject body = new JsonObject();
|
||||
if (StringUtils.hasText(config.getFallbackContextId())) {
|
||||
@@ -419,10 +401,8 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
queryParameters.add("uri", uri);
|
||||
queryParameters.add("device_id", config.getDeviceId());
|
||||
WebClient.RequestBodySpec request = webClient.method(HttpMethod.POST)
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/me/player/queue")
|
||||
.queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer "
|
||||
+ config.getAccessToken());
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/me/player/queue").queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + config.getAccessToken());
|
||||
|
||||
request.retrieve().bodyToMono(String.class).block();
|
||||
}
|
||||
@@ -468,8 +448,7 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
|
||||
WebClient.RequestBodySpec request = webClient.method(HttpMethod.GET)
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/me/player/devices").build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer "
|
||||
+ config.getAccessToken());
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + config.getAccessToken());
|
||||
|
||||
boolean deviceFound = false;
|
||||
|
||||
@@ -482,8 +461,7 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
JsonArray devices = response.getAsJsonObject().getAsJsonArray("devices");
|
||||
for (JsonElement deviceElement : devices) {
|
||||
JsonObject device = deviceElement.getAsJsonObject();
|
||||
if (device.has("id")
|
||||
&& device.get("id").getAsString().equals(config.getDeviceId())) {
|
||||
if (device.has("id") && device.get("id").getAsString().equals(config.getDeviceId())) {
|
||||
deviceFound = true;
|
||||
return;
|
||||
}
|
||||
@@ -496,8 +474,7 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
try {
|
||||
Runtime.getRuntime().exec(command);
|
||||
} catch (IOException e) {
|
||||
logger.warn("Could execute command: "
|
||||
+ command, e);
|
||||
logger.warn("Could execute command: " + command, e);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,8 @@ public class JukeboxController extends BaseController {
|
||||
throw new EntityResponseStatusException(HttpStatus.GONE);
|
||||
}
|
||||
|
||||
if (queueList.containsKey(getCurrentUserId()) && queueList.get(getCurrentUserId())
|
||||
.isAfter(Instant.now().minus(1, ChronoUnit.MINUTES))) {
|
||||
if (queueList.containsKey(getCurrentUserId())
|
||||
&& queueList.get(getCurrentUserId()).isAfter(Instant.now().minus(1, ChronoUnit.MINUTES))) {
|
||||
throw new EntityResponseStatusException(
|
||||
Duration.between(queueList.get(getCurrentUserId()), Instant.now()).getSeconds(),
|
||||
HttpStatus.PAYMENT_REQUIRED);
|
||||
@@ -92,10 +92,10 @@ public class JukeboxController extends BaseController {
|
||||
throw new EntityResponseStatusException(HttpStatus.GONE);
|
||||
}
|
||||
|
||||
if (searchList.containsKey(getCurrentUserId()) && searchList.get(getCurrentUserId())
|
||||
.isAfter(Instant.now().minus(3, ChronoUnit.SECONDS))) {
|
||||
throw new EntityResponseStatusException(Duration
|
||||
.between(searchList.get(getCurrentUserId()), Instant.now()).getSeconds(),
|
||||
if (searchList.containsKey(getCurrentUserId())
|
||||
&& searchList.get(getCurrentUserId()).isAfter(Instant.now().minus(3, ChronoUnit.SECONDS))) {
|
||||
throw new EntityResponseStatusException(
|
||||
Duration.between(searchList.get(getCurrentUserId()), Instant.now()).getSeconds(),
|
||||
HttpStatus.PAYMENT_REQUIRED);
|
||||
}
|
||||
}
|
||||
@@ -137,9 +137,8 @@ public class JukeboxController extends BaseController {
|
||||
*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@GetMapping("/search")
|
||||
public void search(@RequestParam("q") String query,
|
||||
@RequestParam("offset") Optional<Long> offset, HttpServletResponse response)
|
||||
throws JsonIOException, IOException {
|
||||
public void search(@RequestParam("q") String query, @RequestParam("offset") Optional<Long> offset,
|
||||
HttpServletResponse response) throws JsonIOException, IOException {
|
||||
checkSearchPermission();
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
|
||||
+2
-3
@@ -110,9 +110,8 @@ public class JukeboxManagementController extends BaseController {
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@GetMapping("/search")
|
||||
public void search(@RequestParam("q") String query,
|
||||
@RequestParam("offset") Optional<Long> offset, HttpServletResponse response)
|
||||
throws JsonIOException, IOException {
|
||||
public void search(@RequestParam("q") String query, @RequestParam("offset") Optional<Long> offset,
|
||||
HttpServletResponse response) throws JsonIOException, IOException {
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
gson.toJson(jukeboxManager.searchTrack(query, offset.orElse(null)), response.getWriter());
|
||||
|
||||
Reference in New Issue
Block a user