Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢捷峰
discovery
Commits
ecb2fa83
Commit
ecb2fa83
authored
Jul 21, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
控制台增加权限拦截判断
parent
1c60cef5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
6 deletions
+85
-6
discovery-console/src/main/java/com/nepxion/discovery/console/constant/ConsoleConstant.java
+16
-0
discovery-console/src/main/java/com/nepxion/discovery/console/rest/AbstractRestInvoker.java
+43
-6
discovery-console/src/main/java/com/nepxion/discovery/console/rest/ConfigClearRestInvoker.java
+7
-0
discovery-console/src/main/java/com/nepxion/discovery/console/rest/ConfigUpdateRestInvoker.java
+7
-0
discovery-console/src/main/java/com/nepxion/discovery/console/rest/VersionClearRestInvoker.java
+6
-0
discovery-console/src/main/java/com/nepxion/discovery/console/rest/VersionUpdateRestInvoker.java
+6
-0
No files found.
discovery-console/src/main/java/com/nepxion/discovery/console/constant/ConsoleConstant.java
0 → 100644
View file @
ecb2fa83
package
com
.
nepxion
.
discovery
.
console
.
constant
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
public
class
ConsoleConstant
{
public
static
final
String
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
=
"spring.application.discovery.control.enabled"
;
public
static
final
String
SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED
=
"spring.application.config.rest.control.enabled"
;
}
\ No newline at end of file
discovery-console/src/main/java/com/nepxion/discovery/console/rest/AbstractRestInvoker.java
View file @
ecb2fa83
...
...
@@ -11,6 +11,7 @@ package com.nepxion.discovery.console.rest;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -21,6 +22,7 @@ import org.springframework.http.HttpStatus;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestTemplate
;
import
com.nepxion.discovery.console.constant.ConsoleConstant
;
import
com.nepxion.discovery.console.entity.ResultEntity
;
import
com.nepxion.discovery.console.handler.ConsoleErrorHandler
;
...
...
@@ -47,13 +49,19 @@ public abstract class AbstractRestInvoker {
String
serviceId
=
serviceInstance
.
getServiceId
().
toLowerCase
();
String
host
=
serviceInstance
.
getHost
();
int
port
=
serviceInstance
.
getPort
();
String
url
=
getUrl
(
host
,
port
);
String
result
=
doRest
(
url
);
if
(!
StringUtils
.
equals
(
result
,
"OK"
))
{
ConsoleErrorHandler
errorHandler
=
(
ConsoleErrorHandler
)
restTemplate
.
getErrorHandler
();
result
=
errorHandler
.
getCause
();
String
result
=
null
;
try
{
checkPermission
(
serviceInstance
);
result
=
doRest
(
url
);
if
(!
StringUtils
.
equals
(
result
,
"OK"
))
{
ConsoleErrorHandler
errorHandler
=
(
ConsoleErrorHandler
)
restTemplate
.
getErrorHandler
();
result
=
errorHandler
.
getCause
();
}
}
catch
(
Exception
e
)
{
result
=
e
.
getMessage
();
}
ResultEntity
resultEntity
=
new
ResultEntity
();
...
...
@@ -70,9 +78,37 @@ public abstract class AbstractRestInvoker {
return
ResponseEntity
.
ok
().
body
(
resultEntityList
);
}
protected
void
checkDiscoveryControlPermission
(
ServiceInstance
serviceInstance
)
{
Map
<
String
,
String
>
metaData
=
serviceInstance
.
getMetadata
();
String
discoveryControlEnabled
=
metaData
.
get
(
ConsoleConstant
.
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
);
if
(
StringUtils
.
isEmpty
(
discoveryControlEnabled
))
{
throw
new
IllegalArgumentException
(
"No metadata for key="
+
ConsoleConstant
.
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
);
}
if
(!
Boolean
.
valueOf
(
discoveryControlEnabled
))
{
throw
new
IllegalArgumentException
(
"Discovery control is disabled"
);
}
}
protected
void
checkConfigRestControlPermission
(
ServiceInstance
serviceInstance
)
{
Map
<
String
,
String
>
metaData
=
serviceInstance
.
getMetadata
();
String
configRestControlEnabled
=
metaData
.
get
(
ConsoleConstant
.
SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED
);
if
(
StringUtils
.
isEmpty
(
configRestControlEnabled
))
{
throw
new
IllegalArgumentException
(
"No metadata for key="
+
ConsoleConstant
.
SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED
);
}
if
(!
Boolean
.
valueOf
(
configRestControlEnabled
))
{
throw
new
IllegalArgumentException
(
"Config rest control is disabled"
);
}
}
protected
abstract
String
getInfo
();
protected
abstract
String
getUrl
(
String
host
,
int
port
);
protected
abstract
String
doRest
(
String
url
);
protected
abstract
void
checkPermission
(
ServiceInstance
serviceInstance
)
throws
Exception
;
}
\ No newline at end of file
discovery-console/src/main/java/com/nepxion/discovery/console/rest/ConfigClearRestInvoker.java
View file @
ecb2fa83
...
...
@@ -33,4 +33,10 @@ public class ConfigClearRestInvoker extends AbstractRestInvoker {
protected
String
doRest
(
String
url
)
{
return
restTemplate
.
postForEntity
(
url
,
null
,
String
.
class
).
getBody
();
}
@Override
protected
void
checkPermission
(
ServiceInstance
serviceInstance
)
throws
Exception
{
checkDiscoveryControlPermission
(
serviceInstance
);
checkConfigRestControlPermission
(
serviceInstance
);
}
}
\ No newline at end of file
discovery-console/src/main/java/com/nepxion/discovery/console/rest/ConfigUpdateRestInvoker.java
View file @
ecb2fa83
...
...
@@ -47,4 +47,10 @@ public class ConfigUpdateRestInvoker extends AbstractRestInvoker {
return
restTemplate
.
postForEntity
(
url
,
entity
,
String
.
class
).
getBody
();
}
@Override
protected
void
checkPermission
(
ServiceInstance
serviceInstance
)
throws
Exception
{
checkDiscoveryControlPermission
(
serviceInstance
);
checkConfigRestControlPermission
(
serviceInstance
);
}
}
\ No newline at end of file
discovery-console/src/main/java/com/nepxion/discovery/console/rest/VersionClearRestInvoker.java
View file @
ecb2fa83
...
...
@@ -37,4 +37,9 @@ public class VersionClearRestInvoker extends AbstractRestInvoker {
protected
String
doRest
(
String
url
)
{
return
restTemplate
.
postForEntity
(
url
,
version
,
String
.
class
).
getBody
();
}
@Override
protected
void
checkPermission
(
ServiceInstance
serviceInstance
)
throws
Exception
{
checkDiscoveryControlPermission
(
serviceInstance
);
}
}
\ No newline at end of file
discovery-console/src/main/java/com/nepxion/discovery/console/rest/VersionUpdateRestInvoker.java
View file @
ecb2fa83
...
...
@@ -37,4 +37,9 @@ public class VersionUpdateRestInvoker extends AbstractRestInvoker {
protected
String
doRest
(
String
url
)
{
return
restTemplate
.
postForEntity
(
url
,
version
,
String
.
class
).
getBody
();
}
@Override
protected
void
checkPermission
(
ServiceInstance
serviceInstance
)
throws
Exception
{
checkDiscoveryControlPermission
(
serviceInstance
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment