Skip to content

Commit

Permalink
Merge pull request #649 from WeBankPartners/dev
Browse files Browse the repository at this point in the history
Dev merge to Master
  • Loading branch information
xuxuzhesi authored Jan 16, 2020
2 parents ac0f114 + cceae84 commit 19878f1
Show file tree
Hide file tree
Showing 167 changed files with 14,251 additions and 13,019 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,36 @@ name: Java CI
on: [push, pull_request]

jobs:
build:
build_wecube:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
with:
repository: WeBankPartners/wecube-platform.git
ref: refs/heads/master
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: maven-cmdb
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn --file /home/runner/work/we-cmdb/wecube-platform.git/pom.xml clean install -Dmaven.test.skip=true


build:
needs: build_wecube
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: maven-cmdb
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
/target/
*.yml
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ build:
mkdir -p repository
docker run --rm --name $(build_name) -v /data/repository:/usr/src/mymaven/repository -v $(current_dir)/build/maven_settings.xml:/usr/share/maven/ref/settings-docker.xml -v $(current_dir):/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn -U clean install -Dmaven.test.skip=true -s /usr/share/maven/ref/settings-docker.xml dependency:resolve

build-plugin-ui:
mkdir -p repository
docker run --rm --name plugin-ui-build -v /data/repository:/usr/src/mymaven/repository -v $(current_dir)/build/maven_settings.xml:/usr/share/maven/ref/settings-docker.xml -v $(current_dir):/usr/src/mymaven -w /usr/src/mymaven maven:3.3-jdk-8 mvn -U clean install -Dmaven.test.skip=true -DbuildType=plugin -s /usr/share/maven/ref/settings-docker.xml dependency:resolve

image:
docker build -t $(project_name):$(version) .

Expand Down
24 changes: 9 additions & 15 deletions cmdb-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>cmdb</artifactId>
<groupId>com.webank.cmdb</groupId>
<version>1.4.0-SNAPSHOT</version>
<artifactId>cmdb</artifactId>
<version>${cmdb.version}</version>
</parent>
<groupId>com.webank</groupId>
<artifactId>cmdb-core</artifactId>
<name>cmdb-core</name>
<description>cmdb-core</description>

<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<artifactId>cmdb-core</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.webank.wecube.platform</groupId>
<artifactId>platform-auth-client</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand All @@ -35,7 +34,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -170,10 +168,6 @@
<argLine>-Xmx2048m -XX:MaxPermSize=256m</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ public class UIProperties {
private Integer ciTypeIdOfSystemDesign = 1;
private Integer ciTypeIdOfSubsystemDesign = 2;
private Integer ciTypeIdOfUnitDesign = 3;
private Integer ciTypeIdOfUnit = 8;
private Integer ciTypeIdOfSubsys = 7;
private Integer ciTypeIdOfUnit = 9;
private Integer ciTypeIdOfSubsys = 8;
private Integer ciTypeIdOfSystem = 7;
private String ciTypeCodeOfSubsys = "subsys";
private Integer ciTypeIdOfHost = 12;
private Integer ciTypeIdOfInstance = 15;
private Integer ciTypeIdOfIdc = 16;
private Integer ciTypeIdOfZone = 17;
private Integer ciTypeIdOfZoneLink = 18;
private Integer ciTypeIdOfIdcDesign = 22;
private Integer ciTypeIdOfZoneDesign = 23;
private Integer ciTypeIdOfZoneLinkDesign = 24;
private Integer ciTypeIdOfHost = 15;
private Integer ciTypeIdOfInstance = 14;
private Integer ciTypeIdOfIdc = 18;
private Integer ciTypeIdOfZone = 19;
private Integer ciTypeIdOfZoneLink = 20;
private Integer ciTypeIdOfIdcDesign = 25;
private Integer ciTypeIdOfZoneDesign = 26;
private Integer ciTypeIdOfZoneLinkDesign = 27;
private String enumCategoryCiTypeLayer = "ci_layer";
private String enumCategoryCiTypeCatalog = "ci_catalog";
private String enumCategoryCiTypeZoomLevels = "ci_zoom_level";
Expand All @@ -43,10 +44,12 @@ public class UIProperties {
private String referenceCodeOfRunning = "running";
private String referenceCodeOfRealize = "realize";
private String referenceCodeOfRelate = "relation";
private String referenceCodeOfUse = "use";
private String propertyNameOfState = "state";
private String enumCodeOfStateDelete = "delete";
private Integer enumIdOfStateDelete = 36;
private String propertyNameOfFixedDate = "fixed_date";
private String enumCategoryNameOfEnv = "env";
private String enumCategoryNameOfEnv = "deploy_environment";
private String catNameOfArchitectureDesign = "tab_of_architecture_design";
private String catNameOfDeployDesign = "tab_of_deploy_design";
private String catNameOfQueryDeployDesign = "tab_query_of_deploy_design";
Expand All @@ -64,4 +67,4 @@ public class SecurityProperties {
private String casRedirectAppAddr;
private String whitelistIpAddress;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.Arrays;
import java.util.List;

import javax.servlet.Filter;

import org.apache.commons.lang3.StringUtils;
import org.jasig.cas.client.validation.Cas20ServiceTicketValidator;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -34,9 +36,12 @@

import com.webank.cmdb.cache.CacheHandlerInterceptor;
import com.webank.cmdb.config.ApplicationProperties.SecurityProperties;
import com.webank.cmdb.constant.AuthenticationType;
import com.webank.cmdb.controller.interceptor.HttpAccessUsernameInterceptor;
import com.webank.cmdb.exception.CmdbException;
import com.webank.cmdb.mvc.CustomRolesPrefixPostProcessor;
import com.webank.wecube.platform.auth.client.filter.Http401AuthenticationEntryPoint;
import com.webank.wecube.platform.auth.client.filter.JwtSsoBasedAuthenticationFilter;

import springfox.documentation.swagger2.annotations.EnableSwagger2;

Expand All @@ -48,9 +53,6 @@
@ComponentScan({ "com.webank.cmdb.controller", "com.webank.cmdb.mvc", "com.webank.cmdb.stateTransition" })
public class SpringWebConfig extends WebSecurityConfigurerAdapter implements WebMvcConfigurer {

private static final String AUTH_PROVIDER_LOCAL = "LOCAL";
private static final String AUTH_PROVIDER_CAS = "CAS";

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
Expand Down Expand Up @@ -94,10 +96,12 @@ protected void configure(HttpSecurity http) throws Exception {
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = http.authorizeRequests();
if (securityProperties.isEnabled()) {
registry = configureWhiteListAuthentication(registry, true);
if (AUTH_PROVIDER_LOCAL.equalsIgnoreCase(securityProperties.getAuthenticationProvider())) {
if (AuthenticationType.lOCAL.getCode().equalsIgnoreCase(securityProperties.getAuthenticationProvider())) {
configureLocalAuthentication(registry);
} else if (AUTH_PROVIDER_CAS.equalsIgnoreCase(securityProperties.getAuthenticationProvider())) {
} else if (AuthenticationType.CAS.getCode().equalsIgnoreCase(securityProperties.getAuthenticationProvider())) {
configureCasAuthentication(registry);
} else if (AuthenticationType.PLATFORM_AUTH.getCode().equalsIgnoreCase(securityProperties.getAuthenticationProvider())) {
configurePlatformAuthentication(registry);
} else {
throw new CmdbException("Unsupported authentication-provider: " + securityProperties.getAuthenticationProvider());
}
Expand Down Expand Up @@ -159,16 +163,38 @@ protected ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionIntercept
convertedList.add(String.format("hasIpAddress('%s')", ipAddress));
}

return registry.antMatchers("/api/v2/**")
return registry.antMatchers("/**")
.access(StringUtils.join(convertedList, " or "));
}
} else {
return registry.antMatchers("/api/v2/**")
.permitAll();
return registry.antMatchers("/**").permitAll();
}
return registry;
}

protected ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry configurePlatformAuthentication(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) throws Exception {
registry.antMatchers("/index.html").permitAll()
.antMatchers("/swagger-ui.html/**", "/swagger-resources/**").permitAll()
.antMatchers("/webjars/**").permitAll()
.antMatchers("/v2/api-docs").permitAll()
.antMatchers("/csrf").permitAll()
.antMatchers("/**/*.png").permitAll()
.anyRequest()
.authenticated()
.and()
.addFilter(jwtSsoBasedAuthenticationFilter())
.csrf()
.disable()
.exceptionHandling()
.authenticationEntryPoint(new Http401AuthenticationEntryPoint());
return registry;
}

protected Filter jwtSsoBasedAuthenticationFilter() throws Exception {
JwtSsoBasedAuthenticationFilter filter = new JwtSsoBasedAuthenticationFilter(authenticationManager());
return (Filter) filter;
}

protected void configureCasAuthentication(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) throws Exception {
registry.and()
.exceptionHandling()
Expand All @@ -192,7 +218,7 @@ protected void configureCasAuthentication(ExpressionUrlAuthorizationConfigurer<H
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
if (!securityProperties.isEnabled()) {
auth.userDetailsService(userDetailsService).passwordEncoder(new BypassPasswordEncoder());
} else if (AUTH_PROVIDER_LOCAL.equalsIgnoreCase(securityProperties.getAuthenticationProvider())) {
} else if (AuthenticationType.lOCAL.getCode().equalsIgnoreCase(securityProperties.getAuthenticationProvider())) {
auth.userDetailsService(userDetailsService);
} else {
super.configure(auth);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.webank.cmdb.constant;

public enum AggregationFuction {
None("none"), MAX("max"), MIN("min"), AVG("avg"), SUM("sum"), COUNT("count");

private String code;

private AggregationFuction(String code) {
this.code = code;
}

public String getCode() {
return code;
}

/**
* Get FilterOperator from code
*
* @param code The input FilterOperator code
* @return The matching enum value. None if there is not matching enum value
*/
static public AggregationFuction fromCode(String code) {
for (AggregationFuction operator : values()) {
if (None.equals(operator))
continue;

if (operator.getCode().equals(code)) {
return operator;
}
}
return None;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.webank.cmdb.constant;

public enum AuthenticationType {
NONE("NONE"), lOCAL("LOCAL"), CAS("CAS"), PLATFORM_AUTH("PLATFORM-AUTH");

private String code;

private AuthenticationType(String code) {
this.code = code;
}

public String getCode() {
return code;
}

static public AuthenticationType fromCode(String code) {
for (AuthenticationType value : values()) {
if (NONE.equals(value))
continue;

if (value.getCode().equals(code)) {
return value;
}
}
return NONE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,9 @@ public static class ADM_LOG {

public static final List<String> MYSQL_SCHEMA_KEYWORDS = Arrays.asList("ACCESSIBLE","ADD","ALL","ALTER","ANALYZE","AND","AS","ASC","ASENSITIVE","BEFORE","BETWEEN","BIGINT","BINARY","BLOB","BOTH","BY","CALL","CASCADE","CASE","CHANGE","CHAR","CHARACTER","CHECK","COLLATE","COLUMN","CONDITION","CONSTRAINT","CONTINUE","CONVERT","CREATE","CROSS","CUBE","CUME_DIST","CURRENT_DATE","CURRENT_TIME","CURRENT_TIMESTAMP","CURRENT_USER","CURSOR","DATABASE","DATABASES","DAY_HOUR","DAY_MICROSECOND","DAY_MINUTE","DAY_SECOND","DEC","DECIMAL","DECLARE","DEFAULT","DELAYED","DELETE","DENSE_RANK","DESC","DESCRIBE","DETERMINISTIC","DISTINCT","DISTINCTROW","DIV","DOUBLE","DROP","DUAL","EACH","ELSE","ELSEIF","EMPTY","ENCLOSED","ESCAPED","EXCEPT","EXISTS","EXIT","EXPLAIN","FALSE","FETCH","FIRST_VALUE","FLOAT","FLOAT4","FLOAT8","FOR","FORCE","FOREIGN","FROM","FULLTEXT","FUNCTION","GENERATED","GET","GRANT","GROUP","GROUPING","GROUPS","HAVING","HIGH_PRIORITY","HOUR_MICROSECOND","HOUR_MINUTE","HOUR_SECOND","IF","IGNORE","IN","INDEX","INFILE","INNER","INOUT","INSENSITIVE","INSERT","INT","INT1","INT2","INT3","INT4","INT8","INTEGER","INTERVAL","INTO","IO_AFTER_GTIDS","IO_BEFORE_GTIDS","IS","ITERATE","JOIN","JSON_TABLE","KEY","KEYS","KILL","LAG","LAST_VALUE","LATERAL","LEAD","LEADING","LEAVE","LEFT","LIKE","LIMIT","LINEAR","LINES","LOAD","LOCALTIME","LOCALTIMESTAMP","LOCK","LONG","LONGBLOB","LONGTEXT","LOOP","LOW_PRIORITY","MASTER_BIND","MASTER_SSL_VERIFY_SERVER_CERT","MATCH","MAXVALUE","MEDIUMBLOB","MEDIUMINT","MEDIUMTEXT","MEMBER","MIDDLEINT","MINUTE_MICROSECOND","MINUTE_SECOND","MOD","MODIFIES","NATURAL","NOT","NO_WRITE_TO_BINLOG","NTH_VALUE","NTILE","NULL","NUMERIC","OF","ON","OPTIMIZE","OPTIMIZER_COSTS","OPTION","OPTIONALLY","OR","ORDER","OUT","OUTER","OUTFILE","OVER","PARTITION","PERCENT_RANK","PRECISION","PRIMARY","PROCEDURE","PURGE","RANGE","RANK","READ","READS","READ_WRITE","REAL","RECURSIVE","REFERENCES","REGEXP","RELEASE","RENAME","REPEAT","REPLACE","REQUIRE","RESIGNAL","RESTRICT","RETURN","REVOKE","RIGHT","RLIKE","ROW","ROWS","ROW_NUMBER","SCHEMA","SCHEMAS","SECOND_MICROSECOND","SELECT","SENSITIVE","SEPARATOR","SET","SHOW","SIGNAL","SMALLINT","SPATIAL","SPECIFIC","SQL","SQLEXCEPTION","SQLSTATE","SQLWARNING","SQL_BIG_RESULT","SQL_CALC_FOUND_ROWS","SQL_SMALL_RESULT","SSL","STARTING","STORED","STRAIGHT_JOIN","SYSTEM","TABLE","TERMINATED","THEN","TINYBLOB","TINYINT","TINYTEXT","TO","TRAILING","TRIGGER","TRUE","UNDO","UNION","UNIQUE","UNLOCK","UNSIGNED","UPDATE","USAGE","USE","USING","UTC_DATE","UTC_TIME","UTC_TIMESTAMP","VALUES","VARBINARY","VARCHAR","VARCHARACTER","VARYING","VIRTUAL","WHEN","WHERE","WHILE","WINDOW","WITH","WRITE","XOR","YEAR_MONTH","ZEROFILL");
public static final List<String> DEFAULT_FIELDS = Arrays.asList("created_date","created_by","updated_date","updated_by","guid","r_guid","p_guid","key_name","state","code","description","fixed_date","orchestration","biz_key");

public static final String SYMBOL_COMMA = ",";
public static final String SYMBOL_EQUALSIGN = "=";
public static final String SYMBOL_AND = "&";

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.webank.cmdb.constant;

public enum FilterOperator {
None("none"), In("in"), Contains("contains"), Equal("eq"), Greater("gt"), Less("lt"), NotEqual("ne"), NotNull("notNull"), Null("null");
None("none"), In("in"), Contains("contains"), Equal("eq"), Greater("gt"), Less("lt"), NotEqual("ne"), NotNull("notNull"), Null("null"), GreaterEqual("gteq"), LessEqual("lteq"), NotEmpty("notEmpty"), Empty("empty");

private String code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,9 @@ public List<RoleCiTypeCtrlAttrConditionDto> updateRoleCiTypeCtrlAttrConditions(@
public void deleteRoleCiTypeCtrlAttrConditions(@Valid @RequestBody List<Integer> requestIds) {
staticDtoService.delete(RoleCiTypeCtrlAttrConditionDto.class, requestIds);
}

@GetMapping("/static-data/special-connector")
public Object getSpecialConnector() {
return constantService.getSpecialConnector();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

Expand All @@ -22,9 +24,16 @@ public class HttpAccessUsernameInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String username = request.getHeader(KEY_USERNAME);
String[] authorities = new String[0];
Principal userPrincipal = request.getUserPrincipal();
if (userPrincipal != null) {
username = userPrincipal.getName();
if (userPrincipal instanceof UsernamePasswordAuthenticationToken) {
authorities = ((UsernamePasswordAuthenticationToken) userPrincipal).getAuthorities()
.stream()
.map(GrantedAuthority::toString)
.toArray(String[]::new);
}
}

if (StringUtils.isNotBlank(username)) {
Expand All @@ -35,6 +44,8 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
logger.warn(String.format(("The username [%s] contains invalid character, can not set to response header."), username));
}
}

CmdbThreadLocal.getIntance().withAuthorities(authorities);
return true;
}

Expand Down
Loading

0 comments on commit 19878f1

Please sign in to comment.