You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package controller ;
import javax.servlet.http.HttpServletRequest ;
import org.springframework.beans.factory.annotation.Autowired ;
import dto.UserLoginDto ;
import util.JwtUtil ;
public class BaseController {
@Autowired
private JwtUtil jwtUtil ;
protected UserLoginDto getUserLoginDto ( String token ) {
return jwtUtil . getUserLoginDto ( token ) ;
}
protected String getIpAddr ( HttpServletRequest request ) {
String ip = request . getHeader ( "x-forwarded-for" ) ;
if ( ip ! = null & & ip . length ( ) ! = 0 & & ! "unknown" . equalsIgnoreCase ( ip ) ) {
// 多次反向代理后会有多个ip值, 第一个ip才是真实ip
if ( ip . indexOf ( "," ) ! = - 1 ) {
ip = ip . split ( "," ) [ 0 ] ;
}
}
if ( ip = = null | | ip . length ( ) = = 0 | | "unknown" . equalsIgnoreCase ( ip ) ) {
ip = request . getHeader ( "Proxy-Client-IP" ) ;
}
if ( ip = = null | | ip . length ( ) = = 0 | | "unknown" . equalsIgnoreCase ( ip ) ) {
ip = request . getHeader ( "WL-Proxy-Client-IP" ) ;
}
if ( ip = = null | | ip . length ( ) = = 0 | | "unknown" . equalsIgnoreCase ( ip ) ) {
ip = request . getHeader ( "HTTP_CLIENT_IP" ) ;
}
if ( ip = = null | | ip . length ( ) = = 0 | | "unknown" . equalsIgnoreCase ( ip ) ) {
ip = request . getHeader ( "HTTP_X_FORWARDED_FOR" ) ;
}
if ( ip = = null | | ip . length ( ) = = 0 | | "unknown" . equalsIgnoreCase ( ip ) ) {
ip = request . getHeader ( "X-Real-IP" ) ;
}
if ( ip = = null | | ip . length ( ) = = 0 | | "unknown" . equalsIgnoreCase ( ip ) ) {
ip = request . getRemoteAddr ( ) ;
}
return ip ;
}
}