List of usage examples for org.apache.commons.lang3.tuple Pair getKey
@Override public final L getKey()
Gets the key from this pair.
This method implements the Map.Entry interface returning the left element as the key.
From source file:org.apache.syncope.core.workflow.java.AbstractUserWorkflowAdapter.java
@Override public Pair<WorkflowResult<String>, Boolean> internalSuspend(final String key) { User user = userDAO.authFind(key);//from ww w. jav a2 s .c o m Pair<WorkflowResult<String>, Boolean> result = null; Pair<Boolean, Boolean> enforce = userDAO.enforcePolicies(user); if (enforce.getKey()) { LOG.debug("User {} {} is over the max failed logins", user.getKey(), user.getUsername()); // reduce failed logins number to avoid multiple request user.setFailedLogins(user.getFailedLogins() - 1); // set suspended flag user.setSuspended(Boolean.TRUE); result = ImmutablePair.of(doSuspend(user), enforce.getValue()); } return result; }
From source file:org.apache.syncope.fit.AbstractITCase.java
protected void updateLdapRemoteObject(final String bindDn, final String bindPwd, final String objectDn, final Pair<String, String> attribute) { InitialDirContext ctx = null; try {//w w w .j a v a 2 s .co m ctx = getLdapResourceDirContext(bindDn, bindPwd); Attribute ldapAttribute = new BasicAttribute(attribute.getKey(), attribute.getValue()); ModificationItem[] item = new ModificationItem[1]; item[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, ldapAttribute); ctx.modifyAttributes(objectDn, item); } catch (Exception e) { // ignore } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException e) { // ignore } } } }
From source file:org.apache.syncope.fit.core.AuthenticationITCase.java
@Test public void readEntitlements() { // 1. as not authenticated (not allowed) try {//w w w . ja va 2 s . c o m clientFactory.create().self(); fail("This should not happen"); } catch (AccessControlException e) { assertNotNull(e); } // 2. as anonymous Pair<Map<String, Set<String>>, UserTO> self = clientFactory .create(new AnonymousAuthenticationHandler(ANONYMOUS_UNAME, ANONYMOUS_KEY)).self(); assertEquals(1, self.getKey().size()); assertTrue(self.getKey().keySet().contains(StandardEntitlement.ANONYMOUS)); assertEquals(ANONYMOUS_UNAME, self.getValue().getUsername()); // 3. as admin self = adminClient.self(); assertEquals(syncopeService.platform().getEntitlements().size(), self.getKey().size()); assertFalse(self.getKey().keySet().contains(StandardEntitlement.ANONYMOUS)); assertEquals(ADMIN_UNAME, self.getValue().getUsername()); // 4. as user self = clientFactory.create("bellini", ADMIN_PWD).self(); assertFalse(self.getKey().isEmpty()); assertFalse(self.getKey().keySet().contains(StandardEntitlement.ANONYMOUS)); assertEquals("bellini", self.getValue().getUsername()); }
From source file:org.apache.syncope.fit.core.AuthenticationITCase.java
@Test public void issueSYNCOPE434() { assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService)); // 1. create user with group 'groupForWorkflowApproval' // (users with group groupForWorkflowApproval are defined in workflow as subject to approval) UserTO userTO = UserITCase.getUniqueSampleTO("createWithReject@syncope.apache.org"); userTO.getMemberships()//from ww w . j a va2 s . c o m .add(new MembershipTO.Builder().group("0cbcabd2-4410-4b6b-8f05-a052b451d18f").build()); userTO = createUser(userTO).getEntity(); assertNotNull(userTO); assertEquals("createApproval", userTO.getStatus()); // 2. try to authenticate: fail try { clientFactory.create(userTO.getUsername(), "password123").self(); fail("This should not happen"); } catch (AccessControlException e) { assertNotNull(e); } // 3. approve user WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getKey()); form = userWorkflowService.claimForm(form.getTaskId()); form.getProperty("approveCreate").get().setValue(Boolean.TRUE.toString()); userTO = userWorkflowService.submitForm(form); assertNotNull(userTO); assertEquals("active", userTO.getStatus()); // 4. try to authenticate again: success Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(userTO.getUsername(), "password123") .self(); assertNotNull(self); assertNotNull(self.getKey()); assertNotNull(self.getValue()); }
From source file:org.apache.syncope.fit.core.reference.AuthenticationITCase.java
@Test public void testReadEntitlements() { // 1. as anonymous (not allowed) try {/*from w w w . j a v a 2s .co m*/ clientFactory.createAnonymous().self(); fail(); } catch (AccessControlException e) { assertNotNull(e); } // 2. as authenticated anonymous (used by admin console) Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(ANONYMOUS_UNAME, ANONYMOUS_KEY).self(); assertEquals(1, self.getKey().size()); assertTrue(self.getKey().keySet().contains(Entitlement.ANONYMOUS)); assertEquals(ANONYMOUS_UNAME, self.getValue().getUsername()); // 3. as admin self = adminClient.self(); assertEquals(Entitlement.values().size() - 1, self.getKey().size()); assertFalse(self.getKey().keySet().contains(Entitlement.ANONYMOUS)); assertEquals(ADMIN_UNAME, self.getValue().getUsername()); // 4. as user self = clientFactory.create("bellini", ADMIN_PWD).self(); assertFalse(self.getKey().isEmpty()); assertFalse(self.getKey().keySet().contains(Entitlement.ANONYMOUS)); assertEquals("bellini", self.getValue().getUsername()); }
From source file:org.apache.syncope.fit.core.reference.AuthenticationITCase.java
@Test public void issueSYNCOPE434() { Assume.assumeTrue(ActivitiDetector.isActivitiEnabledForUsers(syncopeService)); // 1. create user with group 9 (users with group 9 are defined in workflow as subject to approval) UserTO userTO = UserITCase.getUniqueSampleTO("createWithReject@syncope.apache.org"); MembershipTO membershipTO = new MembershipTO(); membershipTO.setRightKey(9L);/* www. j a v a2 s. c o m*/ userTO.getMemberships().add(membershipTO); userTO = createUser(userTO); assertNotNull(userTO); assertEquals("createApproval", userTO.getStatus()); // 2. try to authenticate: fail try { clientFactory.create(userTO.getUsername(), "password123").self(); fail(); } catch (AccessControlException e) { assertNotNull(e); } // 3. approve user WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getKey()); form = userWorkflowService.claimForm(form.getTaskId()); Map<String, WorkflowFormPropertyTO> props = form.getPropertyMap(); props.get("approve").setValue(Boolean.TRUE.toString()); form.getProperties().clear(); form.getProperties().addAll(props.values()); userTO = userWorkflowService.submitForm(form); assertNotNull(userTO); assertEquals("active", userTO.getStatus()); // 4. try to authenticate again: success Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(userTO.getUsername(), "password123") .self(); assertNotNull(self); assertNotNull(self.getKey()); assertNotNull(self.getValue()); }
From source file:org.asqatasun.rules.elementchecker.ElementCheckerImpl.java
/** * //from ww w . j a va 2 s . c om * @param successSolutionPair * @param failureSolutionPair * @param eeAttributeNameList */ public ElementCheckerImpl(Pair<TestSolution, String> successSolutionPair, Pair<TestSolution, String> failureSolutionPair, String... eeAttributeNameList) { this.successSolutionPair.left = successSolutionPair.getKey(); this.successSolutionPair.right = successSolutionPair.getValue(); this.failureSolutionPair.left = failureSolutionPair.getKey(); this.failureSolutionPair.right = failureSolutionPair.getValue(); this.eeAttributeNames = Arrays.copyOf(eeAttributeNameList, eeAttributeNameList.length); }
From source file:org.codice.alliance.core.email.impl.EmailSenderImpl.java
/** sendEmail method sends email after receiving input parameters */ @Override/*from w w w.ja va 2 s . c o m*/ public void sendEmail(String fromEmail, String toEmail, String subject, String body, List<Pair<String, InputStream>> attachments) throws IOException { notNull(fromEmail, "fromEmail must be non-null"); notNull(toEmail, "toEmail must be non-null"); notNull(subject, "subject must be non-null"); notNull(body, "body must be non-null"); notNull(attachments, "attachments must be non-null"); if (StringUtils.isBlank(mailHost)) { throw new IOException("the mail server hostname has not been configured"); } List<File> tempFiles = new LinkedList<>(); try { InternetAddress emailAddr = new InternetAddress(toEmail); emailAddr.validate(); Properties properties = createSessionProperties(); Session session = Session.getDefaultInstance(properties); MimeMessage mimeMessage = new MimeMessage(session); mimeMessage.setFrom(new InternetAddress(fromEmail)); mimeMessage.addRecipient(Message.RecipientType.TO, emailAddr); mimeMessage.setSubject(subject); BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(body); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); Holder<Long> bytesWritten = new Holder<>(0L); for (Pair<String, InputStream> attachment : attachments) { messageBodyPart = new MimeBodyPart(); File file = File.createTempFile("email-sender-", ".dat"); tempFiles.add(file); copyDataToTempFile(file, attachment.getValue(), bytesWritten); messageBodyPart.setDataHandler(new DataHandler(new FileDataSource(file))); messageBodyPart.setFileName(attachment.getKey()); multipart.addBodyPart(messageBodyPart); } mimeMessage.setContent(multipart); send(mimeMessage); LOGGER.debug("Email sent to " + toEmail); } catch (AddressException e) { throw new IOException("invalid email address: email=" + toEmail, e); } catch (MessagingException e) { throw new IOException("message error occurred on send", e); } finally { tempFiles.forEach(file -> { if (!file.delete()) { LOGGER.debug("unable to delete tmp file: path={}", file); } }); } }
From source file:org.codice.ddf.catalog.sourcepoller.Poller.java
/** * @throws IllegalStateException if unable to wait for polls * @throws InterruptedException if the current thread was interrupted * @throws CancellationException if the task to wait for the loader {@link Callable<V>} to be * complete was cancelled//from w ww . j av a 2 s. com * @throws ExecutionException if the the task to wait for the loader {@link Callable<V>} threw an * exception * @throws PollerException if unable to commit the value for any of the {@code itemsToPoll} */ private void doPollItems(long timeout, TimeUnit timeoutTimeUnit, ImmutableMap<K, Callable<V>> itemsToPoll) throws InterruptedException, ExecutionException, PollerException { removeNoncurrentKeysFromTheCache(itemsToPoll.keySet()); if (itemsToPoll.isEmpty()) { LOGGER.debug("itemsToPoll is empty. Nothing to poll"); return; } // Gather any exceptions while loading or committing new values final Map<K, Throwable> exceptions = new HashMap<>(); final CompletionService<Pair<K, Commitable>> completionService = new ExecutorCompletionService<>( pollTimeoutWatcherThreadPool); final int startedLoadsCount = startLoads(timeout, timeoutTimeUnit, itemsToPoll, completionService, exceptions); boolean interrupted = false; try { for (int i = 0; i < startedLoadsCount; i++) { // Use CompletionService#poll(long, TimeUnit) instead of CompletionService#take() even // though the timeout has already been accounted for in #load(K, Callable<V>, long, // TimeUnit) to prevent blocking forever // @throws InterruptedException if interrupted while waiting final Future<Pair<K, Commitable>> nextCompletedLoadFuture = completionService.poll(timeout, timeoutTimeUnit); if (nextCompletedLoadFuture == null) { final String message = String.format("Unable to wait for polls to finish within %d %s", timeout, timeoutTimeUnit); LOGGER.debug(message); throw new IllegalStateException(message); } // @throws CancellationException if the computation was cancelled // @throws ExecutionException if the computation threw an exception // @throws InterruptedException if the current thread was interrupted final Pair<K, Commitable> nextCompletedLoad = nextCompletedLoadFuture.get(); try { attemptToCommitLoadedValue(nextCompletedLoad.getKey(), nextCompletedLoad.getValue(), exceptions); } catch (InterruptedException e) { interrupted = true; } } } finally { if (interrupted) { Thread.currentThread().interrupt(); } } if (!exceptions.isEmpty()) { throw new PollerException(exceptions); } }
From source file:org.corpus_tools.graphannis.SaltExport.java
private static void mapLabels(SAnnotationContainer n, API.StringMap labels) { for (API.StringMap.Iterator it = labels.begin(); !it.equals(labels.end()); it = it.increment()) { Pair<String, String> qname = SaltUtil.splitQName(it.first().getString()); String value = it.second() == null ? null : it.second().getString(); if ("annis".equals(qname.getKey())) { n.createFeature(qname.getKey(), qname.getValue(), value); } else {/* w ww . ja v a2 s .c o m*/ n.createAnnotation(qname.getKey(), qname.getValue(), value); } } }