当前位置: 首页 > wzjs >正文

html购物网站做网站哪家公司比较好而且不贵

html购物网站,做网站哪家公司比较好而且不贵,中国自适应网站建设,手机seo排名Vault 是由 HashiCorp 开发的一款用于管理和保护敏感数据的工具。它可以帮助组织安全地存储、分发和使用各种类型的敏感信息,如 API 密钥、密码、证书等。 应用场景 1、API 密钥管理: 将 API 密钥存储在 Vault 中,并根据需要分配给不同的服…

Vault 是由 HashiCorp 开发的一款用于管理和保护敏感数据的工具。它可以帮助组织安全地存储、分发和使用各种类型的敏感信息,如 API 密钥、密码、证书等。

应用场景

1、API 密钥管理:
将 API 密钥存储在 Vault 中,并根据需要分配给不同的服务或团队成员。这样可以确保密钥的安全性和可追溯性。
2、数据库凭证管理:
Vault 可以生成动态数据库凭证,每个凭证都有特定的权限和有效期。当凭证不再需要时,可以自动撤销。
3、SSH 密钥管理:
Vault 可以作为 SSH 密钥管理系统,为用户提供一次性或长期有效的 SSH 密钥。
4、TLS/SSL 证书管理:
Vault 可以签发和管理 TLS/SSL 证书,简化证书生命周期管理过程。
5、云平台凭证管理:
Vault 可以管理和轮换 AWS、Azure、Google Cloud Platform 等云平台的凭证。
6、CI/CD 环境中的秘密管理:
在持续集成/持续交付管道中使用 Vault 来传递敏感信息,如 Docker 镜像仓库凭证、配置文件等。
7、微服务架构中的秘密管理:
在微服务架构中,不同服务之间可能需要共享某些敏感信息。Vault 可以集中管理这些信息,并根据服务的需求提供相应的访问权限。
8、合规性和审计:
Vault 提供强大的审计功能,帮助组织满足合规要求,如 GDPR、HIPAA 等。

启动Vault并配置Token

首先,确保你已经安装并启动了Vault服务器。你可以使用以下命令来初始化和启动Vault:

# 启动Vault开发服务器
vault server -dev# 记录下生成的root token和unseal key

我的Vault根Token是 s.9ZvP3oJHqQcXzKw6FyGmEhLr,并且Vault运行在默认的 http://localhost:8200 上。

将敏感信息存储到Vault

使用Vault CLI或API将敏感信息存储到Vault中。这里我们使用Vault CLI来创建一个密钥路径 secret/app-secrets 并添加一个键值对 {“password”: “mySuperSecretPassword”}。

# 设置Vault地址
export VAULT_ADDR=http://localhost:8200# 设置Vault Token
export VAULT_TOKEN=s.9ZvP3oJHqQcXzKw6FyGmEhLr# 写入敏感信息到Vault
vault kv put secret/app-secrets password=mySuperSecretPassword

代码实操

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-vault-config</artifactId></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-core</artifactId></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
</dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies>
</dependencyManagement><properties><java.version>17</java.version><spring-cloud.version>2022.0.1</spring-cloud.version>
</properties>

配置Vault (application.yml)

server:port:8080spring:
cloud:vault:host:localhostport:8200scheme:httptoken:s.9ZvP3oJHqQcXzKw6FyGmEhLrgeneric:enabled:truebackend:secretdefault-context:app-secrets

创建Vault认证类 (VaultConfig.java)

package com.example.vaultdemo.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.vault.authentication.ClientAuthentication;
import org.springframework.vault.authentication.TokenAuthentication;
import org.springframework.vault.client.VaultEndpoint;
import org.springframework.vault.core.VaultTemplate;@Configuration
publicclass VaultConfig {@Beanpublic ClientAuthentication clientAuthentication() {returnnew TokenAuthentication("s.9ZvP3oJHqQcXzKw6FyGmEhLr");}@Beanpublic VaultTemplate vaultTemplate(ClientAuthentication clientAuthentication) {VaultTemplate vaultTemplate = new VaultTemplate(VaultEndpoint.create("localhost", 8200), clientAuthentication);return vaultTemplate;}
}

编写服务类 (SecretService.java)

package com.example.vaultdemo.service;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.vault.core.VaultOperations;@Service
publicclass SecretService {privatefinal VaultOperations vaultOperations;@Autowiredpublic SecretService(VaultOperations vaultOperations) {this.vaultOperations = vaultOperations;}public String getSecretPassword() {return vaultOperations.read("secret/app-secrets").getData().get("data").toString();}
}

配置Spring Security (WebSecurityConfig.java)

package com.example.vaultdemo.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;@Configuration
@EnableWebSecurity
publicclass WebSecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers("/secrets/**").hasRole("ADMIN").anyRequest().authenticated().and().httpBasic();}@Bean@Overridepublic UserDetailsService userDetailsService() {UserDetails admin = User.withDefaultPasswordEncoder().username("admin").password("password").roles("ADMIN").build();UserDetails user = User.withDefaultPasswordEncoder().username("user").password("password").roles("USER").build();returnnew InMemoryUserDetailsManager(admin, user);}
}

编写控制器 (SecretController.java)

package com.example.vaultdemo.controller;import com.example.vaultdemo.service.SecretService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/secrets")
publicclass SecretController {privatefinal SecretService secretService;@Autowiredpublic SecretController(SecretService secretService) {this.secretService = secretService;}@GetMapping("/password")public ResponseEntity<String> getPassword() {String password = secretService.getSecretPassword();return ResponseEntity.ok(password);}
}

主应用程序类 (VaultDemoApplication.java)

package com.example.vaultdemo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class VaultDemoApplication {public static void main(String[] args) {SpringApplication.run(VaultDemoApplication.class, args);}
}

测试用例 (SecretServiceTest.java)

package com.example.vaultdemo;import com.example.vaultdemo.service.SecretService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;importstatic org.assertj.core.api.Assertions.assertThat;@SpringBootTest
class SecretServiceTest {@Autowiredprivate SecretService secretService;@Testvoid shouldReturnCorrectPassword() {// 在Vault中的路径为secret/data/app-secrets,键值对为{"password": "mySuperSecretPassword"}assertThat(secretService.getSecretPassword()).contains("mySuperSecretPassword");}
}

启动Spring Boot应用程序
确保所有文件都已正确放置在相应的目录中,然后运行Spring Boot应用程序。

测试API
使用Postman发送HTTP GET请求到 http://localhost:8080/secrets/password,

使用HTTP Basic Authentication,用户名为 admin,密码为 password。

请求

URL: http://localhost:8080/secrets/password
Method: GET
Authorization:
Type: Basic Auth
Username: admin
Password: password

响应

{"password": "mySuperSecretPassword"
}
http://www.dtcms.com/wzjs/515550.html

相关文章:

  • 博客网站设计及说明百度一下官方下载安装
  • dw可以做网站吗怎么推广网站
  • 代码级优化wordpress怎么理解搜索引擎优化
  • 北京 网站建设大全青岛seo网站推广
  • 政务网站模版广告软文范例大全100字
  • 哪个网站做二手叉车回收好有没有购买链接
  • 凡科登录网站手机版百度电脑端网页版入口
  • 前台网站开发技术迅雷磁力链bt磁力种子
  • 做网站一定需要自己买主机吗百度首页推广广告怎么做
  • 邢台市最新征婚seo站点是什么意思
  • 网站建设工程网络营销策划的概念
  • 网站关键词排名软件教育培训机构
  • 永嘉做网站网站收录怎么弄
  • wordpress访问过的页码不变色网络推广优化服务
  • 东莞网站关键词优化哪家好苏州网站seo服务
  • 技术支持 哈尔滨网站建设长尾关键词挖掘词
  • 网站推广的基本方法对于大部分网站来说都是适用的每日一则新闻摘抄
  • 看英语做游戏的网站东莞网站制作外包
  • 烟台优化网站建设外贸网站有哪些平台
  • 做电脑游戏破解的网站郑州优化网站关键词
  • 做宝宝衣服的网站东莞网站建设制作
  • 为什么php做不了大网站广州最新消息
  • 做网站linux主机网站seo排名优化软件
  • 房产中介网站排名山东16市最新疫情
  • 专业的网站建设设计价格推广方案万能模板
  • 公司做网站最低需用多少钱西安百度关键词优化排名
  • 微信h5免费制作网站模板下载在线建站平台免费建网站
  • 邢台市网站制作 网站建设网络营销外包公司
  • 网站系统功能流程图百度企业推广
  • 绍兴网站制作公司优化大师官方免费下载