io.swagger.models.auth.In Java Examples

The following examples show how to use io.swagger.models.auth.In. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FilterRuleServiceImpl.java    From we-cmdb with Apache License 2.0 5 votes vote down vote up
private boolean containEmptyResultFilter(List<Filter> filtersWithRightValues) {
    boolean emptyResultFilter = false;
    if(filtersWithRightValues.size()>0){
        for (Filter filtersWithRightValue : filtersWithRightValues) {
            Object value = filtersWithRightValue.getValue();
            if(FilterOperator.In.getCode().equalsIgnoreCase(filtersWithRightValue.getOperator())){
                if( value == null || ((List)value).size()==0){
                    emptyResultFilter = true;
                }
            }
        }
    }
    return emptyResultFilter;
}
 
Example #2
Source File: AuthBuilder.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the defined apiKey is valid or not. Only apiKey definition with name as 'key' and
 * 'in' as 'query' are allowed"
 */
private boolean isValidApiKeyDefinition(ApiKeyAuthDefinition apiKeydef) {
  if (apiKeydef.getName().equalsIgnoreCase("key") || apiKeydef.getIn() == In.QUERY) {
    return true;
  } else {
    diagCollector.addDiag(
        Diag.warning(
            SimpleLocation.UNKNOWN,
            "apiKey '%s' is ignored. Only apiKey with 'name' as 'key' and 'in' as 'query' are "
                + "supported",
            apiKeydef.getName()));
    return false;
  }
}
 
Example #3
Source File: SwaggerConfiguration.java    From halo with GNU General Public License v3.0 4 votes vote down vote up
private List<ApiKey> adminApiKeys() {
    return Arrays.asList(
        new ApiKey("Token from header", ADMIN_TOKEN_HEADER_NAME, In.HEADER.name()),
        new ApiKey("Token from query", ADMIN_TOKEN_QUERY_NAME, In.QUERY.name())
    );
}
 
Example #4
Source File: SwaggerConfiguration.java    From halo with GNU General Public License v3.0 4 votes vote down vote up
private List<ApiKey> contentApiKeys() {
    return Arrays.asList(
        new ApiKey("Access key from header", API_ACCESS_KEY_HEADER_NAME, In.HEADER.name()),
        new ApiKey("Access key from query", API_ACCESS_KEY_QUERY_NAME, In.QUERY.name())
    );
}
 
Example #5
Source File: SwaggerFactory.java    From dorado with Apache License 2.0 4 votes vote down vote up
public static Swagger getSwagger() {
	if (!swaggerEnable)
		return new Swagger();

	if (swagger != null)
		return swagger;

	Reader reader = new Reader(new Swagger());

	String[] packages = null;
	Class<?> mainClass = Dorado.mainClass;
	EnableSwagger enableSwagger = mainClass.getAnnotation(EnableSwagger.class);

	if (enableSwagger != null) {
		packages = enableSwagger.value();
	}

	if (packages == null || packages.length == 0) {
		packages = Dorado.serverConfig.scanPackages();
	}

	if (packages == null || packages.length == 0) {
		packages = new String[] { mainClass.getPackage().getName() };
	}

	if (packages == null || packages.length == 0) {
		throw new IllegalArgumentException("缺少scanPackages设置");
	}

	Set<Class<?>> classes = new HashSet<>();
	for (String pkg : packages) {
		try {
			classes.addAll(PackageScanner.scan(pkg));
		} catch (Exception ex) {
			// ignore this ex
		}
	}

	Swagger _swagger = reader.read(classes);
	_swagger.setSchemes(Arrays.asList(Scheme.HTTP, Scheme.HTTPS));

	ApiKey apiKey = apiContext.getApiKey();
	if (apiKey != null) {
		ApiKeyAuthDefinition apiKeyAuth = new ApiKeyAuthDefinition(apiKey.getName(),
				In.forValue(apiKey.getIn() == null ? "header" : apiKey.getIn()));
		_swagger.securityDefinition("auth", apiKeyAuth);

		List<SecurityRequirement> securityRequirements = new ArrayList<>();
		SecurityRequirement sr = new SecurityRequirement();
		sr.requirement("auth");
		securityRequirements.add(sr);
		_swagger.setSecurity(securityRequirements);
	}
	if (apiContext.getInfo() != null)
		_swagger.setInfo(apiContext.getInfo());

	swagger = _swagger;
	return _swagger;
}
 
Example #6
Source File: SwaggerContext.java    From binder-swagger-java with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static ApiKeyAuthDefinition apiKeyAuth(String name, In in) {
    return new ApiKeyAuthDefinition(name, in);
}