Search in sources :

Example 66 with EntityTag

use of javax.ws.rs.core.EntityTag in project athenz by yahoo.

the class ZTSImplTest method testPostSignedPolicyRequestNoChanges.

@Test
public void testPostSignedPolicyRequestNoChanges() {
    ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
    DataStore store = new DataStore(structStore, null, ztsMetric);
    ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
    ZTSImpl.serverHostName = "localhost";
    SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
    store.processSignedDomain(signedDomain, false);
    Principal principal = SimplePrincipal.create("user_domain", "user", "v=U1;d=user_domain;n=user;s=signature", 0, null);
    ResourceContext context = createResourceContext(principal);
    Timestamp modified = signedDomain.getDomain().getModified();
    EntityTag eTag = new EntityTag(modified.toString());
    SignedPolicyRequest signedPolicyRequest = new SignedPolicyRequest();
    signedPolicyRequest.setPolicyVersions(Collections.emptyMap());
    Response response = ztsImpl.postSignedPolicyRequest(context, "coretech", signedPolicyRequest, eTag.toString());
    assertEquals(response.getStatus(), 304);
}
Also used : Response(javax.ws.rs.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) DataStore(com.yahoo.athenz.zts.store.DataStore) EntityTag(javax.ws.rs.core.EntityTag) Timestamp(com.yahoo.rdl.Timestamp) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 67 with EntityTag

use of javax.ws.rs.core.EntityTag in project athenz by yahoo.

the class ETagFilterTest method testFilterContainerETagSet.

@Test
public void testFilterContainerETagSet() {
    ContainerResponseContext containerResponse = getContext("etag");
    ETagFilter eTagFilter = new ETagFilter();
    eTagFilter.filter(null, containerResponse);
    EntityTag eTag = (EntityTag) containerResponse.getHeaders().getFirst(HttpHeaders.ETAG);
    assertNotNull(eTag);
    assertEquals(eTag.getValue(), "etag");
}
Also used : ContainerResponseContext(javax.ws.rs.container.ContainerResponseContext) EntityTag(javax.ws.rs.core.EntityTag) ETagFilter(com.yahoo.athenz.container.filter.ETagFilter) Test(org.testng.annotations.Test)

Example 68 with EntityTag

use of javax.ws.rs.core.EntityTag in project athenz by yahoo.

the class ETagFilterTest method testFilterContainerETagNotSet.

@Test
public void testFilterContainerETagNotSet() {
    ContainerResponseContext containerResponse = getContext(null);
    ETagFilter eTagFilter = new ETagFilter();
    eTagFilter.filter(null, containerResponse);
    EntityTag eTag = (EntityTag) containerResponse.getHeaders().getFirst(HttpHeaders.ETAG);
    assertNull(eTag);
}
Also used : ContainerResponseContext(javax.ws.rs.container.ContainerResponseContext) EntityTag(javax.ws.rs.core.EntityTag) ETagFilter(com.yahoo.athenz.container.filter.ETagFilter) Test(org.testng.annotations.Test)

Example 69 with EntityTag

use of javax.ws.rs.core.EntityTag in project athenz by yahoo.

the class ZMSImpl method getSignedDomains.

@Override
public Response getSignedDomains(ResourceContext ctx, String domainName, String metaOnly, String metaAttr, Boolean master, Boolean conditions, String matchingTag) {
    final String caller = ctx.getApiName();
    logPrincipal(ctx);
    validateRequest(ctx.request(), caller);
    if (domainName != null) {
        domainName = domainName.toLowerCase();
        validate(domainName, TYPE_DOMAIN_NAME, caller);
        setRequestDomain(ctx, domainName);
    }
    if (metaAttr != null) {
        metaAttr = metaAttr.toLowerCase();
        validate(metaAttr, TYPE_SIMPLE_NAME, caller);
    }
    boolean setMetaDataOnly = ZMSUtils.parseBoolean(metaOnly, false);
    boolean includeConditions = Boolean.TRUE == conditions;
    long timestamp = getModTimestamp(matchingTag);
    // if this is one of our system principals then we're going
    // to use the master copy instead of read-only replicas
    // unless we're configured to always use read-only replicas
    // for all signed domain operations
    Principal principal = ((RsrcCtxWrapper) ctx).principal();
    boolean masterCopy = (useMasterCopyForSignedDomains || master == Boolean.TRUE) && principal.getFullName().startsWith("sys.");
    // if we're given a specific domain then we don't need to
    // retrieve the list of modified domains
    List<SignedDomain> sdList = new ArrayList<>();
    Long youngestDomMod = -1L;
    if (domainName != null && !domainName.isEmpty()) {
        Domain domain = null;
        try {
            domain = dbService.getDomain(domainName, masterCopy);
        } catch (ResourceException ex) {
            if (ex.getCode() != ResourceException.NOT_FOUND) {
                throw ex;
            }
        }
        if (domain != null) {
            youngestDomMod = domain.getModified().millis();
            if (timestamp != 0 && youngestDomMod <= timestamp) {
                EntityTag eTag = new EntityTag(domain.getModified().toString());
                return Response.status(ResourceException.NOT_MODIFIED).header("ETag", eTag.toString()).build();
            }
            // generate our signed domain object
            SignedDomain signedDomain = retrieveSignedDomain(domain, metaAttr, setMetaDataOnly, masterCopy, includeConditions);
            if (signedDomain != null) {
                sdList.add(signedDomain);
            }
        } else {
            youngestDomMod = System.currentTimeMillis();
        }
    } else {
        if (!setMetaDataOnly && !masterCopy) {
            return Response.status(ResourceException.BAD_REQUEST).build();
        }
        if (matchingTag == null) {
            EntityTag eTag = new EntityTag(Timestamp.fromMillis(0).toString());
            matchingTag = eTag.toString();
        }
        DomainMetaList dmlist = dbService.listModifiedDomains(timestamp);
        List<Domain> modlist = dmlist.getDomains();
        if (modlist == null || modlist.size() == 0) {
            return Response.status(ResourceException.NOT_MODIFIED).header("ETag", matchingTag).build();
        }
        for (Domain dmod : modlist) {
            Long domModMillis = dmod.getModified().millis();
            if (domModMillis.compareTo(youngestDomMod) > 0) {
                youngestDomMod = domModMillis;
            }
            // generate our signed domain object
            SignedDomain signedDomain = retrieveSignedDomain(dmod, metaAttr, setMetaDataOnly, masterCopy, includeConditions);
            if (signedDomain == null) {
                continue;
            }
            // we have a valid domain so we'll add it to our return list
            sdList.add(signedDomain);
        }
    }
    SignedDomains sdoms = new SignedDomains();
    sdoms.setDomains(sdList);
    Timestamp youngest = Timestamp.fromMillis(youngestDomMod);
    EntityTag eTag = new EntityTag(youngest.toString());
    return Response.status(ResourceException.OK).entity(sdoms).header("ETag", eTag.toString()).build();
}
Also used : EntityTag(javax.ws.rs.core.EntityTag) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain)

Example 70 with EntityTag

use of javax.ws.rs.core.EntityTag in project athenz by yahoo.

the class ZMSImplTest method testGetSignedDomainsNotModified.

@Test
public void testGetSignedDomainsNotModified() {
    TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject("SignedDom1", "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
    zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
    // set the meta attributes for domain
    DomainMeta meta = zmsTestInitializer.createDomainMetaObject("Tenant Domain1", null, true, false, "12345", 0);
    zmsTestInitializer.getZms().putDomainMeta(zmsTestInitializer.getMockDomRsrcCtx(), "signeddom1", zmsTestInitializer.getAuditRef(), meta);
    zmsTestInitializer.getZms().privateKey = new ServerPrivateKey(Crypto.loadPrivateKey(Crypto.ybase64DecodeString(zmsTestInitializer.getPrivKey())), "0");
    Authority principalAuthority = new com.yahoo.athenz.common.server.debug.DebugPrincipalAuthority();
    Principal sysPrincipal = principalAuthority.authenticate("v=U1;d=sys;n=zts;s=signature", "10.11.12.13", "GET", null);
    ResourceContext rsrcCtx = zmsTestInitializer.createResourceContext(sysPrincipal);
    EntityTag eTag = new EntityTag(Timestamp.fromCurrentTime().toString());
    Response response = zmsTestInitializer.getZms().getSignedDomains(rsrcCtx, "signeddom1", null, null, Boolean.TRUE, false, eTag.toString());
    assertEquals(response.getStatus(), 304);
    zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), "SignedDom1", zmsTestInitializer.getAuditRef());
}
Also used : Response(javax.ws.rs.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) Authority(com.yahoo.athenz.auth.Authority) EntityTag(javax.ws.rs.core.EntityTag) ServerPrivateKey(com.yahoo.athenz.auth.ServerPrivateKey) Principal(com.yahoo.athenz.auth.Principal)

Aggregations

EntityTag (javax.ws.rs.core.EntityTag)73 GET (javax.ws.rs.GET)24 Response (javax.ws.rs.core.Response)24 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)23 Path (javax.ws.rs.Path)21 CacheControl (javax.ws.rs.core.CacheControl)20 Test (org.junit.Test)18 Produces (javax.ws.rs.Produces)13 Date (java.util.Date)10 Test (org.testng.annotations.Test)9 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)8 Timestamp (com.yahoo.rdl.Timestamp)5 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)5 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)5 List (java.util.List)5 ContainerResponse (org.everrest.core.impl.ContainerResponse)5 Principal (com.yahoo.athenz.auth.Principal)4 EnvironmentUser (fi.otavanopisto.muikku.model.users.EnvironmentUser)4 ArrayList (java.util.ArrayList)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4