Search in sources :

Example 1 with BasicAuthSlice

use of com.artipie.http.auth.BasicAuthSlice in project artipie by artipie.

the class AuthAndPermissionsTest method johnCanDelete.

@Test
void johnCanDelete() throws IOException {
    final RsStatus status = RsStatus.NO_CONTENT;
    MatcherAssert.assertThat(new BasicAuthSlice(new SliceSimple(new RsWithStatus(status)), new AuthFromYaml(this.credentials()), new Permission.ByName("delete", this.permissions())).response(new RequestLine("PUT", "/foo", "HTTP/1.2").toString(), new ListOf<Map.Entry<String, String>>(new Authorization(String.format("Basic %s", new Base64Encoded("john:123").asString()))), Flowable.empty()), new RsHasStatus(status));
}
Also used : RsHasStatus(com.artipie.http.hm.RsHasStatus) RsStatus(com.artipie.http.rs.RsStatus) Authorization(com.artipie.http.headers.Authorization) BasicAuthSlice(com.artipie.http.auth.BasicAuthSlice) RequestLine(com.artipie.http.rq.RequestLine) RsWithStatus(com.artipie.http.rs.RsWithStatus) Permission(com.artipie.http.auth.Permission) ListOf(org.cactoos.list.ListOf) Base64Encoded(org.cactoos.text.Base64Encoded) Map(java.util.Map) SliceSimple(com.artipie.http.slice.SliceSimple) Test(org.junit.jupiter.api.Test)

Example 2 with BasicAuthSlice

use of com.artipie.http.auth.BasicAuthSlice in project artipie by artipie.

the class AuthAndPermissionsTest method publicRepoWorksWithAuth.

@Test
void publicRepoWorksWithAuth() throws IOException {
    final RsStatus status = RsStatus.OK;
    MatcherAssert.assertThat(new BasicAuthSlice(new SliceSimple(new RsWithStatus(status)), new AuthFromYaml(this.credentials()), new Permission.ByName("delete", this.allAllowedPermissions())).response(new RequestLine("GET", "/foo", "HTTP/1.2").toString(), new ListOf<Map.Entry<String, String>>(new Authorization(String.format("Basic %s", new Base64Encoded("admin:abc").asString()))), Flowable.empty()), new RsHasStatus(status));
}
Also used : RsHasStatus(com.artipie.http.hm.RsHasStatus) RsStatus(com.artipie.http.rs.RsStatus) Authorization(com.artipie.http.headers.Authorization) BasicAuthSlice(com.artipie.http.auth.BasicAuthSlice) RequestLine(com.artipie.http.rq.RequestLine) RsWithStatus(com.artipie.http.rs.RsWithStatus) Permission(com.artipie.http.auth.Permission) ListOf(org.cactoos.list.ListOf) Base64Encoded(org.cactoos.text.Base64Encoded) Map(java.util.Map) SliceSimple(com.artipie.http.slice.SliceSimple) Test(org.junit.jupiter.api.Test)

Example 3 with BasicAuthSlice

use of com.artipie.http.auth.BasicAuthSlice in project artipie by artipie.

the class AuthAndPermissionsTest method authIsNotRequiredForPublicRepo.

@Test
void authIsNotRequiredForPublicRepo() {
    final RsStatus status = RsStatus.ACCEPTED;
    MatcherAssert.assertThat(new BasicAuthSlice(new SliceSimple(new RsWithStatus(status)), new AuthFromYaml(this.credentials()), new Permission.ByName("install", this.allAllowedPermissions())).response(new RequestLine("GET", "/foo", "HTTP/1.2").toString(), Collections.emptyList(), Flowable.empty()), new RsHasStatus(status));
}
Also used : BasicAuthSlice(com.artipie.http.auth.BasicAuthSlice) RequestLine(com.artipie.http.rq.RequestLine) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsHasStatus(com.artipie.http.hm.RsHasStatus) Permission(com.artipie.http.auth.Permission) RsStatus(com.artipie.http.rs.RsStatus) SliceSimple(com.artipie.http.slice.SliceSimple) Test(org.junit.jupiter.api.Test)

Example 4 with BasicAuthSlice

use of com.artipie.http.auth.BasicAuthSlice in project artipie by artipie.

the class AuthAndPermissionsTest method adminCanDeploy.

@Test
void adminCanDeploy() throws IOException {
    final RsStatus status = RsStatus.ACCEPTED;
    MatcherAssert.assertThat(new BasicAuthSlice(new SliceSimple(new RsWithStatus(status)), new AuthFromYaml(this.credentials()), new Permission.ByName("deploy", this.permissions())).response(new RequestLine("PUT", "/foo", "HTTP/1.2").toString(), new ListOf<Map.Entry<String, String>>(new Authorization(String.format("Basic %s", new Base64Encoded("admin:abc").asString()))), Flowable.empty()), new RsHasStatus(status));
}
Also used : RsHasStatus(com.artipie.http.hm.RsHasStatus) RsStatus(com.artipie.http.rs.RsStatus) Authorization(com.artipie.http.headers.Authorization) BasicAuthSlice(com.artipie.http.auth.BasicAuthSlice) RequestLine(com.artipie.http.rq.RequestLine) RsWithStatus(com.artipie.http.rs.RsWithStatus) Permission(com.artipie.http.auth.Permission) ListOf(org.cactoos.list.ListOf) Base64Encoded(org.cactoos.text.Base64Encoded) Map(java.util.Map) SliceSimple(com.artipie.http.slice.SliceSimple) Test(org.junit.jupiter.api.Test)

Example 5 with BasicAuthSlice

use of com.artipie.http.auth.BasicAuthSlice in project artipie by artipie.

the class DockerRoutingSlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final RequestLineFrom req = new RequestLineFrom(line);
    final String path = req.uri().getPath();
    final Matcher matcher = PTN_PATH.matcher(path);
    final Response rsp;
    if (matcher.matches()) {
        final String group = matcher.group(1);
        if (group.isEmpty() || group.equals("/")) {
            rsp = new AsyncResponse(this.settings.auth().thenApply(auth -> new BasicAuthSlice(new BaseEntity(), auth, user -> !user.equals(Permissions.ANY_USER)).response(line, headers, body)));
        } else {
            rsp = this.origin.response(new RequestLine(req.method().toString(), new URIBuilder(req.uri()).setPath(group).toString(), req.version()).toString(), new Headers.From(headers, DockerRoutingSlice.HDR_REAL_PATH, path), body);
        }
    } else {
        rsp = this.origin.response(line, headers, body);
    }
    return rsp;
}
Also used : AsyncResponse(com.artipie.http.async.AsyncResponse) BasicAuthSlice(com.artipie.http.auth.BasicAuthSlice) RequestLine(com.artipie.http.rq.RequestLine) Matcher(java.util.regex.Matcher) BaseEntity(com.artipie.docker.http.BaseEntity) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) AsyncResponse(com.artipie.http.async.AsyncResponse) URIBuilder(org.apache.http.client.utils.URIBuilder)

Aggregations

BasicAuthSlice (com.artipie.http.auth.BasicAuthSlice)5 RequestLine (com.artipie.http.rq.RequestLine)5 Permission (com.artipie.http.auth.Permission)4 RsHasStatus (com.artipie.http.hm.RsHasStatus)4 RsStatus (com.artipie.http.rs.RsStatus)4 RsWithStatus (com.artipie.http.rs.RsWithStatus)4 SliceSimple (com.artipie.http.slice.SliceSimple)4 Test (org.junit.jupiter.api.Test)4 Authorization (com.artipie.http.headers.Authorization)3 Map (java.util.Map)3 ListOf (org.cactoos.list.ListOf)3 Base64Encoded (org.cactoos.text.Base64Encoded)3 BaseEntity (com.artipie.docker.http.BaseEntity)1 AsyncResponse (com.artipie.http.async.AsyncResponse)1 RequestLineFrom (com.artipie.http.rq.RequestLineFrom)1 Matcher (java.util.regex.Matcher)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1