Example usage for java.util EnumSet of

List of usage examples for java.util EnumSet of

Introduction

In this page you can find the example usage for java.util EnumSet of.

Prototype

@SafeVarargs
public static <E extends Enum<E>> EnumSet<E> of(E first, E... rest) 

Source Link

Document

Creates an enum set initially containing the specified elements.

Usage

From source file:org.eclipse.hono.authorization.impl.InMemoryAuthorizationService.java

@Override
public void removePermission(final String subject, final ResourceIdentifier resource, final Permission first,
        final Permission... rest) {
    requireNonNull(subject, "subject is required");
    requireNonNull(resource, "resource is required");
    requireNonNull(first, "permission is required");

    final EnumSet<Permission> permissions = EnumSet.of(first, rest);
    LOGGER.trace("removing permission {} for subject {} on resource {}.", first, subject, resource);
    resources.computeIfPresent(resource, (key, value) -> {
        ofNullable(value.getAclEntry(subject)).map(AclEntry::getPermissions)
                .ifPresent(p -> p.removeAll(permissions));
        return value;
    });//from w w w  .  j  a v  a  2 s. co  m
}

From source file:ch.cyberduck.core.s3.S3AccessControlListFeatureTest.java

@Test
public void testWrite() throws Exception {
    final S3Session session = new S3Session(new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
            new Credentials(System.getProperties().getProperty("s3.key"),
                    System.getProperties().getProperty("s3.secret"))));
    session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path container = new Path("test-us-east-1-cyberduck",
            EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    new S3TouchFeature(session).touch(test);
    final S3AccessControlListFeature f = new S3AccessControlListFeature(session);
    {//  ww w.  j a v a 2 s .  c om
        final Acl acl = new Acl();
        acl.addAll(new Acl.GroupUser(Acl.GroupUser.EVERYONE), new Acl.Role(Acl.Role.READ));
        acl.addAll(new Acl.GroupUser(Acl.GroupUser.AUTHENTICATED), new Acl.Role(Acl.Role.READ));
        f.setPermission(test, acl);
    }
    {
        final Acl acl = new Acl();
        acl.addAll(new Acl.GroupUser("http://acs.amazonaws.com/groups/global/AllUsers"),
                new Acl.Role(Acl.Role.READ));
        acl.addAll(new Acl.GroupUser("http://acs.amazonaws.com/groups/global/AuthenticatedUsers"),
                new Acl.Role(Acl.Role.READ));
        // Check for owner added with full control
        acl.addAll(new Acl.CanonicalUser("80b9982b7b08045ee86680cc47f43c84bf439494a89ece22b5330f8a49477cf6"),
                new Acl.Role(Acl.Role.FULL));
        assertEquals(acl, f.getPermission(test));
    }
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:ch.cyberduck.core.sds.SDSNodeIdProviderTest.java

@Test
public void getFileIdFileVersions() throws Exception {
    final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials(
            System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key")));
    final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(),
            new DefaultX509KeyManager());
    final LoginConnectionService service = new LoginConnectionService(new DisabledLoginCallback(),
            new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    service.connect(session, PathCache.empty(), new DisabledCancelCallback());
    final Path room = new SDSDirectoryFeature(session)
            .mkdir(new Path(new AlphanumericRandomStringService().random(),
                    EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus());
    final String name = new AlphanumericRandomStringService().random();
    final Path file = new SDSTouchFeature(session).touch(new Path(room, name, EnumSet.of(Path.Type.file)),
            new TransferStatus());
    final String versionIdTouch = file.attributes().getVersionId();
    assertEquals(versionIdTouch, new SDSNodeIdProvider(session)
            .getFileid(new Path(room, name, EnumSet.of(Path.Type.file)), new DisabledListProgressListener()));
    final byte[] content = RandomUtils.nextBytes(32769);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);//  w  w  w .j  a  v a 2  s.  c  om
    status.setExists(true);
    final SDSWriteFeature writer = new SDSWriteFeature(session);
    final HttpResponseOutputStream<VersionId> out = writer.write(file, status,
            new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    final VersionId versionIdWrite = out.getStatus();
    assertNotNull(versionIdWrite);
    assertNotEquals(versionIdTouch, versionIdWrite);
    assertEquals(versionIdWrite.toString(), new SDSNodeIdProvider(session)
            .getFileid(new Path(room, name, EnumSet.of(Path.Type.file)), new DisabledListProgressListener()));
    new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:ch.cyberduck.core.b2.B2LargeUploadServiceTest.java

@Test
public void testAppendNoPartCompleted() throws Exception {
    final B2Session session = new B2Session(new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(),
            new Credentials(System.getProperties().getProperty("b2.user"),
                    System.getProperties().getProperty("b2.key"))));
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path test = new Path(bucket, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    final int length = 102 * 1024 * 1024;
    final byte[] content = RandomUtils.nextBytes(length);
    IOUtils.write(content, local.getOutputStream(false));
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);//w  w  w  . j av a  2s.  com
    final AtomicBoolean interrupt = new AtomicBoolean();
    final B2LargeUploadService service = new B2LargeUploadService(session, new B2WriteFeature(session),
            100 * 1024L * 1024L, 1);
    try {
        service.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED),
                new DisabledStreamListener() {
                    long count;

                    @Override
                    public void sent(final long bytes) {
                        count += bytes;
                        if (count >= 5 * 1024L * 1024L) {
                            throw new RuntimeException();
                        }
                    }
                }, status, new DisabledLoginCallback());
    } catch (BackgroundException e) {
        // Expected
        interrupt.set(true);
    }
    assertTrue(interrupt.get());
    assertEquals(0L, status.getOffset(), 0L);
    assertFalse(status.isComplete());

    final TransferStatus append = new TransferStatus().append(true).length(content.length);
    service.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED),
            new DisabledStreamListener(), append, new DisabledLoginCallback());
    assertTrue(new B2FindFeature(session).find(test));
    assertEquals(content.length, new B2AttributesFinderFeature(session).find(test).getSize());
    assertEquals(content.length, append.getOffset(), 0L);
    assertTrue(append.isComplete());
    final byte[] buffer = new byte[content.length];
    final InputStream in = new B2ReadFeature(session).read(test, new TransferStatus(),
            new DisabledConnectionCallback());
    IOUtils.readFully(in, buffer);
    in.close();
    assertArrayEquals(content, buffer);
    new B2DeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    local.delete();
    session.close();
}

From source file:alfio.manager.user.UserManager.java

public boolean isOwner(User user) {
    return checkRole(user, EnumSet.of(Role.ADMIN, Role.OWNER));
}

From source file:ch.cyberduck.core.s3.S3SingleUploadServiceTest.java

@Test
public void testUploadSSE() throws Exception {
    final S3Session session = new S3Session(new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
            new Credentials(System.getProperties().getProperty("s3.key"),
                    System.getProperties().getProperty("s3.secret"))));
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final S3SingleUploadService service = new S3SingleUploadService(session,
            new S3WriteFeature(session, new S3DisabledMultipartService()));
    final Path container = new Path("test-us-east-1-cyberduck",
            EnumSet.of(Path.Type.directory, Path.Type.volume));
    final String name = UUID.randomUUID().toString() + ".txt";
    final Path test = new Path(container, name, EnumSet.of(Path.Type.file));
    final Local local = new Local(System.getProperty("java.io.tmpdir"), name);
    final String random = new RandomStringGenerator.Builder().build().generate(1000);
    final OutputStream out = local.getOutputStream(false);
    IOUtils.write(random, out, Charset.defaultCharset());
    out.close();// w  ww  .ja  va  2 s  .  c o  m
    final TransferStatus status = new TransferStatus();
    status.setLength(random.getBytes().length);
    status.setMime("text/plain");
    status.setEncryption(KMSEncryptionFeature.SSE_KMS_DEFAULT);
    service.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED),
            new DisabledStreamListener(), status, new DisabledLoginCallback());
    assertTrue(new S3FindFeature(session).find(test));
    final PathAttributes attributes = new S3AttributesFinderFeature(session).find(test);
    assertEquals(random.getBytes().length, attributes.getSize());
    final Map<String, String> metadata = new S3MetadataFeature(session, new S3AccessControlListFeature(session))
            .getMetadata(test);
    assertFalse(metadata.isEmpty());
    assertEquals("text/plain", metadata.get("Content-Type"));
    assertEquals("aws:kms", metadata.get("server-side-encryption"));
    assertNotNull(metadata.get("server-side-encryption-aws-kms-key-id"));
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    local.delete();
    session.close();
}

From source file:ch.cyberduck.core.b2.B2ReadFeatureTest.java

@Test
public void testReadInterrupt() throws Exception {
    final B2Session session = new B2Session(new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(),
            new Credentials(System.getProperties().getProperty("b2.user"),
                    System.getProperties().getProperty("b2.key"))));
    final LoginConnectionService service = new LoginConnectionService(new DisabledLoginCallback(),
            new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    service.connect(session, PathCache.empty(), new DisabledCancelCallback());
    final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new Path(bucket, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final byte[] content = RandomUtils.nextBytes(923);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);/*from w w w  . ja v  a 2  s  .co  m*/
    status.setChecksum(new SHA1ChecksumCompute().compute(new ByteArrayInputStream(content), status));
    final HttpResponseOutputStream<BaseB2Response> out = new B2WriteFeature(session).write(file, status,
            new DisabledConnectionCallback());
    IOUtils.write(content, out);
    out.close();
    {
        // Unknown length in status
        // Read a single byte
        final InputStream in = new B2ReadFeature(session).read(file, new TransferStatus(),
                new DisabledConnectionCallback());
        assertNotNull(in.read());
        in.close();
    }
    {
        final InputStream in = new B2ReadFeature(session).read(file, new TransferStatus(),
                new DisabledConnectionCallback());
        assertNotNull(in);
        in.close();
    }
    new B2DeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:ch.cyberduck.core.spectra.SpectraWriteFeatureTest.java

@Test
public void testOverwriteZeroSized() throws Exception {
    final Host host = new Host(new SpectraProtocol() {
        @Override//  ww  w  .  j av  a  2 s .co m
        public Scheme getScheme() {
            return Scheme.http;
        }
    }, System.getProperties().getProperty("spectra.hostname"),
            Integer.valueOf(System.getProperties().getProperty("spectra.port")),
            new Credentials(System.getProperties().getProperty("spectra.user"),
                    System.getProperties().getProperty("spectra.key")));
    final SpectraSession session = new SpectraSession(host, new DisabledX509TrustManager(),
            new DefaultX509KeyManager());
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    // Make 0-byte file
    new SpectraTouchFeature(session).touch(test, new TransferStatus());
    // Replace content
    final byte[] content = new RandomStringGenerator.Builder().build().generate(1000).getBytes();
    final TransferStatus status = new TransferStatus().length(content.length);
    status.setChecksum(new CRC32ChecksumCompute().compute(new ByteArrayInputStream(content), status));
    final SpectraBulkService bulk = new SpectraBulkService(session);
    bulk.pre(Transfer.Type.upload, Collections.singletonMap(test, status.exists(true)),
            new DisabledConnectionCallback());
    final OutputStream out = new SpectraWriteFeature(session).write(test, status,
            new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content),
            out);
    out.close();
    new SpectraDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:org.apigw.authserver.admin.LocalDataAdministration.java

/**
 * Populates the database with some base data for local testing purposes.
 * This method runs upon spring context initialization when running locally,
 * i.e. when using loginform-authserver-context.xml as context
 *///from   ww  w  .j  a v a 2  s  .  c  o  m
public void populateWithDataForLocalTesting() {
    log.info("Populating local usage data...");
    registerRole("CRM_SCHEDULING_READ", "Lsa tidbokningar");
    registerRole("CRM_SCHEDULING_WRITE", "Skriva tidbokningar");
    registerRole("CRM_REQUESTSTATUS_READ", "Lsa remiss-status");
    registerRole("CRM_CARELISTING_READ", "Lsa listningar");
    registerRole("CLINICALPROCESS_HEALTHCOND_DESCRIPTION_READ", "Lsa vrddokumentation");
    registerRole("CLINICALPROCESS_LOGISTICS_LOGISTICS_READ", "Lsa vrdkontakter");
    registerRole("CLINICALPROCESS_ACTIVITYPRESCRIPTION_ACTOUTCOME_READ", "Lsa vaccinationer");
    registerRole("CLINICALPROCESS_HEALTHCOND_ACTOUTCOME_READ", "Lsa mdravrd");
    registerRole("CLINICALPROCESS_HEALTHCOND_RHEUMA_READ", "Lsa reumatismdata");
    registerRole("INFRASTRUCTURE_SUPPORTSERVICES_FORMINTERACTION_WRITE", "Skriva formulrdata");
    registerRole("INFRASTRUCTURE_SUPPORTSERVICES_FORMINTERACTION_READ", "Lsa formulrdata");
    registerRole("CLINICALPROCESS_HEALTHCOND_BASIC_READ", "");

    registerApplication("vardpumpen", "Vrdpumpen", "Application description", 0L, 0L, "CA_2",
            "VARDPUMPEN_DUMMY_SUBJ_DN", "Callista Enterprise",
            Arrays.asList("CRM_SCHEDULING_READ", "CLINICALPROCESS_HEALTHCOND_DESCRIPTION_READ",
                    "CLINICALPROCESS_LOGISTICS_LOGISTICS_READ",
                    "CLINICALPROCESS_ACTIVITYPRESCRIPTION_ACTOUTCOME_READ",
                    "CLINICALPROCESS_HEALTHCOND_ACTOUTCOME_READ", "CLINICALPROCESS_HEALTHCOND_RHEUMA_READ",
                    "CRM_CARELISTING_READ"),
            "secret", EnumSet.of(ROLE_CLIENT, ROLE_TRUSTED_CLIENT), "http://localhost:8080/anotherClient");

    registerApplication("clientA", "API Test", "Description of the API Test application", 0L, 0L,
            "CN=clientA, OU=Callista Software, O=Callista Enterprise AB, L=Gothenburg, ST=, C=SE",
            "CN=clientA, OU=Callista Software, O=Callista Enterprise AB, L=Gothenburg, ST=, C=SE",
            "Callista Enterprise",
            Arrays.asList("CRM_SCHEDULING_READ", "CRM_SCHEDULING_WRITE", "CRM_REQUESTSTATUS_READ",
                    "CRM_CARELISTING_READ", "CLINICALPROCESS_HEALTHCOND_DESCRIPTION_READ",
                    "CLINICALPROCESS_LOGISTICS_LOGISTICS_READ",
                    "CLINICALPROCESS_ACTIVITYPRESCRIPTION_ACTOUTCOME_READ",
                    "CLINICALPROCESS_HEALTHCOND_ACTOUTCOME_READ", "CLINICALPROCESS_HEALTHCOND_RHEUMA_READ",
                    "INFRASTRUCTURE_SUPPORTSERVICES_FORMINTERACTION_READ",
                    "INFRASTRUCTURE_SUPPORTSERVICES_FORMINTERACTION_WRITE",
                    "CLINICALPROCESS_HEALTHCOND_BASIC_READ"),
            "secret", EnumSet.of(ROLE_CLIENT, ROLE_TRUSTED_CLIENT, ROLE_ADMIN), "http://localhost:9090");
}

From source file:eu.ggnet.dwoss.redtape.position.PositionUpdateCask.java

@Override
public void accept(Position position) {
    if (position == null)
        return;/*from  w  ww  .ja v a2 s  .  com*/

    PostLedger postLedger = lookup(MandatorSupporter.class).loadPostLedger();
    List bookingAccounts = new ArrayList();
    bookingAccounts.add(postLedger.get(position.getType()).orElse(-1));
    bookingAccounts.addAll(postLedger.getPossible(position.getType()).orElse(Collections.EMPTY_LIST));
    bookingAccountBox.setModel(new DefaultComboBoxModel(bookingAccounts.toArray()));

    this.position = position;
    this.setPositionName(position.getName());
    this.setPrice(position.getPrice());
    this.setDescription(position.getDescription());
    this.setAmount(position.getAmount());
    this.setPreDecimal((int) (position.getAmount() - (position.getAmount() % 1)));
    this.setPostDecimal((int) ((position.getAmount() % 1) * 100));
    this.setBookingAccount(position.getBookingAccount());

    System.out.println("Pre: " + this.getPreDecimal());
    System.out.println("Post: " + this.getPostDecimal());

    this.accessCos = lookup(Guardian.class);

    if (position.getDocument() != null && EnumSet.of(DocumentType.ANNULATION_INVOICE, DocumentType.CREDIT_MEMO)
            .contains(position.getDocument().getType())) {
        disableComponents(preDecimalSpinner, postDecimalSpinner, nameArea, bookingAccountBox, priceField,
                afterTaxPriceField, descriptionArea);
        accessCos.add(priceSumField, UPDATE_POSITION_WITH_EXISTING_DOCUMENT);
        accessCos.add(afterTaxSumField, UPDATE_POSITION_WITH_EXISTING_DOCUMENT);
        accessCos.add(priceField, UPDATE_POSITION_WITH_EXISTING_DOCUMENT);
        accessCos.add(afterTaxPriceField, UPDATE_POSITION_WITH_EXISTING_DOCUMENT);
    } else {
        if (position.getType() == PRODUCT_BATCH || position.getType() == UNIT) {
            disableComponents(postDecimalSpinner);
            accessCos.add(priceField, UPDATE_PRICE_OF_UNITS_AND_PRODUCT_BATCH);
            accessCos.add(afterTaxPriceField, UPDATE_PRICE_OF_UNITS_AND_PRODUCT_BATCH);
        }
        if (position.getType() == UNIT) {
            disableComponents(preDecimalSpinner);
            bookingAccountBox.setEnabled(true);
        }
        if (position.getType() == COMMENT) {
            disableComponents(priceField, priceSumField, afterTaxPriceField, afterTaxSumField,
                    preDecimalSpinner, postDecimalSpinner);
        }
        if (position.getType() == SHIPPING_COST) {
            disableComponents(nameArea, afterTaxPriceField, afterTaxSumField, preDecimalSpinner,
                    postDecimalSpinner);
        }

        if (EnumSet.of(COMMENT, SERVICE, PRODUCT_BATCH).contains(position.getType())) {
            nameArea.setEditable(true);
            if (position.getType() == SERVICE)
                bookingAccountBox.setEnabled(true);
        }
    }
}