Nexus设置guest只访问指定artifact

Guids: http://books.sonatype.com/nexus-book/reference/running.html
0. 下载nexus
http://www.sonatype.org/nexus/go/
下载后直接解压

1. 启动nexus
windows下:进入bin目录,然后运行
> nexus.bat console

2. 启动完成后,进入http://127.0.0.1:8081/nexus/
默认用户名密码
admin
admin123

在设置权限前,建议为自己的项目单独建立个repository group.方便对该group分配权限。

3. 设置guest只能获取指定的artifact,设置完成后,匿名用户可根据开放的artifact的groupid, artifactid进行查询
思路:为anonymous自定义privileges,role; privileges可根据repository targets来设置。
3.1. 设置repository targets
作用:通过它来配置哪些目录下的artifact可以被访问。
a. 新增一个repository targets
name:最好取个有意义的名字
repository type: 自定义的一般选“Any Content”
Pattern Expression: 根据通配符来设置可以匹配的articfact的路径
.*/com/some/company/.* --可以匹配"com.some.company"作为groupid, artifactid包含
^/com/some/company/* --以com/some/company开头的路径的artifact
例如:我想要匹配company所有的SNAPSHOT下的artifact.可以配置成:
.*/com/xxx/companyname/xxx/.*SNAPSHOT/.*
b.点“Add”按钮, 将pattern expression添加到patterns里
c. 可以添加多个Pattern Expression来设置多个artifacts

3.2.设置routing
作用:通过routing来配置哪些目录是可以通过repository path来访问,哪些是不可以通过repository path访问。
例如:不允许通过repossitory path来访问com/mycompany目录
a. 配置URL pattern: ^/com/mycompany/.*
b. 选择rule type:
Exclusive, 不包含设置的目录
Inclusive, 包含设置的目录
c. 选择repository group,根据需要选择你的repository group.
d. 选择需要使用引用该配置的repositories.
配置好后,通过repository path来访问com/mycomany目录时会得到404错误。

3.3. 设置Privileges
name: 特权名字
description: 特权描述
repository: 选择你的repository
repository target: 选择你在3.1.里新增的target.
新增后,nexus会为它创建四个个权限(create, read, update,delete)

3.4. 设置roles
a. 填写roleid, name, description.
b. 选择在privilesges里新增的privilege, Nexus Anonymous Role

3.5. 配置users
a. 将原来的role全部移除掉,并将在3.4新增的role设置给anonymous user
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用 Maven 的 Java API 来获取 Nexus指定组件的全部版本信息。以下是一个示例代码: ```java import org.apache.maven.artifact.repository.metadata.DefaultMetadataResolver; import org.apache.maven.artifact.repository.metadata.Metadata; import org.apache.maven.artifact.repository.metadata.MetadataResolutionRequest; import org.apache.maven.artifact.repository.metadata.MetadataResolutionResult; import java.util.List; public class NexusMetadataResolver { private final String nexusUrl; private final String repositoryId; public NexusMetadataResolver(String nexusUrl, String repositoryId) { this.nexusUrl = nexusUrl; this.repositoryId = repositoryId; } public List<String> getComponentVersions(String groupId, String artifactId) throws Exception { DefaultMetadataResolver resolver = new DefaultMetadataResolver(); MetadataResolutionRequest request = new MetadataResolutionRequest(); request.setRemoteRepository(nexusUrl, repositoryId, true); request.setMetadata(new Metadata(groupId, artifactId, "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT)); MetadataResolutionResult result = resolver.resolve(request); Metadata metadata = result.getMetadata(); return metadata.getVersioning().getVersions(); } } ``` 使用时,您需要传入 Nexus 服务器的地址和仓库 ID,以及要获取版本信息的组件的 `groupId` 和 `artifactId`。例如: ```java NexusMetadataResolver resolver = new NexusMetadataResolver("https://<nexus-url>/repository/maven-public/", "nexus"); List<String> versions = resolver.getComponentVersions("com.example", "example-component"); for (String version : versions) { System.out.println(version); } ``` 其中,`<nexus-url>` 是 Nexus 服务器的地址,"nexus" 是仓库 ID,"com.example" 和 "example-component" 分别是组件的 `groupId` 和 `artifactId`。这段代码会输出指定组件的所有版本信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值