-
-
Notifications
You must be signed in to change notification settings - Fork 680
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev'
# Conflicts: # CHANGELOG.md
- Loading branch information
Showing
16 changed files
with
226 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
LavalinkServer/src/main/java/lavalink/server/config/RequestAuthorizationFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package lavalink.server.config; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@Configuration | ||
public class RequestAuthorizationFilter implements HandlerInterceptor, WebMvcConfigurer { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(RequestAuthorizationFilter.class); | ||
private ServerConfig serverConfig; | ||
private MetricsPrometheusConfigProperties metricsConfig; | ||
|
||
public RequestAuthorizationFilter(ServerConfig serverConfig, MetricsPrometheusConfigProperties metricsConfig) { | ||
this.serverConfig = serverConfig; | ||
this.metricsConfig = metricsConfig; | ||
} | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { | ||
// Collecting metrics is anonymous | ||
if (!metricsConfig.getEndpoint().isEmpty() | ||
&& request.getServletPath().equals(metricsConfig.getEndpoint())) return true; | ||
|
||
if (request.getServletPath().equals("/error")) return true; | ||
|
||
String authorization = request.getHeader("Authorization"); | ||
|
||
if (authorization == null || !authorization.equals(serverConfig.getPassword())) { | ||
String method = request.getMethod(); | ||
String path = request.getRequestURI().substring(request.getContextPath().length()); | ||
String ip = request.getRemoteAddr(); | ||
|
||
if (authorization == null) { | ||
log.warn("Authorization missing for {} on {} {}", ip, method, path); | ||
response.setStatus(HttpStatus.UNAUTHORIZED.value()); | ||
return false; | ||
} | ||
log.warn("Authorization failed for {} on {} {}", ip, method, path); | ||
response.setStatus(HttpStatus.FORBIDDEN.value()); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry.addInterceptor(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
LavalinkServer/src/main/java/lavalink/server/info/InfoRestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package lavalink.server.info; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* Created by napster on 08.03.19. | ||
*/ | ||
@RestController | ||
public class InfoRestHandler { | ||
|
||
private final AppInfo appInfo; | ||
|
||
public InfoRestHandler(AppInfo appInfo) { | ||
this.appInfo = appInfo; | ||
} | ||
|
||
@GetMapping("/version") | ||
public String version() { | ||
return appInfo.getVersionBuild(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 15 additions & 4 deletions
19
LavalinkServer/src/main/java/lavalink/server/player/LoadResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
package lavalink.server.player; | ||
|
||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; | ||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
class LoadResult { | ||
public ResultStatus loadResultType; | ||
public List<AudioTrack> tracks; | ||
public String playlistName; | ||
public ResultStatus loadResultType; | ||
public Integer selectedTrack; | ||
public FriendlyException exception; | ||
|
||
public LoadResult(List<AudioTrack> tracks, @Nullable String playlistName, ResultStatus loadResultType, | ||
@Nullable Integer selectedTrack) { | ||
public LoadResult(ResultStatus loadResultType, List<AudioTrack> tracks, | ||
@Nullable String playlistName, @Nullable Integer selectedTrack) { | ||
|
||
this.loadResultType = loadResultType; | ||
this.tracks = Collections.unmodifiableList(tracks); | ||
this.playlistName = playlistName; | ||
this.loadResultType = loadResultType; | ||
this.selectedTrack = selectedTrack; | ||
this.exception = null; | ||
} | ||
|
||
public LoadResult(FriendlyException exception) { | ||
this.loadResultType = ResultStatus.LOAD_FAILED; | ||
this.tracks = Collections.emptyList(); | ||
this.playlistName = null; | ||
this.selectedTrack = null; | ||
this.exception = exception; | ||
} | ||
} |
Oops, something went wrong.