List of usage examples for org.apache.commons.lang3.tuple Triple getMiddle
public abstract M getMiddle();
Gets the middle element from this triple.
From source file:org.apache.syncope.core.logic.SAML2SPLogic.java
@PreAuthorize("isAuthenticated() and not(hasRole('" + StandardEntitlement.ANONYMOUS + "'))") public SAML2RequestTO createLogoutRequest(final String accessToken, final String spEntityID) { check();/*from ww w . j ava 2s .c o m*/ // 1. fetch the current JWT used for Syncope authentication JwsJwtCompactConsumer consumer = new JwsJwtCompactConsumer(accessToken); if (!consumer.verifySignatureWith(jwsSignatureVerifier)) { throw new IllegalArgumentException("Invalid signature found in Access Token"); } // 2. look for IdP String idpEntityID = (String) consumer.getJwtClaims().getClaim(JWT_CLAIM_IDP_ENTITYID); if (idpEntityID == null) { throw new NotFoundException("No SAML 2.0 IdP information found in the access token"); } SAML2IdPEntity idp = cache.get(idpEntityID); if (idp == null) { throw new NotFoundException("SAML 2.0 IdP '" + idpEntityID + "'"); } if (idp.getSLOLocation(idp.getBindingType()) == null) { throw new IllegalArgumentException("No SingleLogoutService available for " + idp.getId()); } // 3. create LogoutRequest LogoutRequest logoutRequest = new LogoutRequestBuilder().buildObject(); logoutRequest.setID("_" + UUID_GENERATOR.generate().toString()); logoutRequest.setDestination(idp.getSLOLocation(idp.getBindingType()).getLocation()); DateTime now = new DateTime(); logoutRequest.setIssueInstant(now); logoutRequest.setNotOnOrAfter(now.plusMinutes(5)); Issuer issuer = new IssuerBuilder().buildObject(); issuer.setValue(spEntityID); logoutRequest.setIssuer(issuer); NameID nameID = new NameIDBuilder().buildObject(); nameID.setFormat((String) consumer.getJwtClaims().getClaim(JWT_CLAIM_NAMEID_FORMAT)); nameID.setValue((String) consumer.getJwtClaims().getClaim(JWT_CLAIM_NAMEID_VALUE)); logoutRequest.setNameID(nameID); SessionIndex sessionIndex = new SessionIndexBuilder().buildObject(); sessionIndex.setSessionIndex((String) consumer.getJwtClaims().getClaim(JWT_CLAIM_SESSIONINDEX)); logoutRequest.getSessionIndexes().add(sessionIndex); SAML2RequestTO requestTO = new SAML2RequestTO(); requestTO.setIdpServiceAddress(logoutRequest.getDestination()); requestTO.setBindingType(idp.getBindingType()); try { // 3. generate relay state as JWT Map<String, Object> claims = new HashMap<>(); claims.put(JWT_CLAIM_IDP_DEFLATE, idp.getBindingType() == SAML2BindingType.REDIRECT ? true : idp.isUseDeflateEncoding()); Triple<String, String, Date> relayState = accessTokenDataBinder.generateJWT(logoutRequest.getID(), JWT_RELAY_STATE_DURATION, claims); requestTO.setRelayState(relayState.getMiddle()); // 4. sign and encode AuthnRequest switch (idp.getBindingType()) { case REDIRECT: requestTO.setContent(saml2rw.encode(logoutRequest, true)); requestTO.setSignAlg(saml2rw.getSigAlgo()); requestTO.setSignature(saml2rw.sign(requestTO.getContent(), requestTO.getRelayState())); break; case POST: default: saml2rw.sign(logoutRequest); requestTO.setContent(saml2rw.encode(logoutRequest, idp.isUseDeflateEncoding())); } } catch (Exception e) { LOG.error("While generating LogoutRequest", e); SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Unknown); sce.getElements().add(e.getMessage()); throw sce; } return requestTO; }
From source file:org.apache.syncope.core.persistence.jpa.dao.ElasticsearchAnySearchDAO.java
private QueryBuilder getQueryBuilder(final AnyCond cond, final AnyTypeKind kind) { Triple<PlainSchema, PlainAttrValue, AnyCond> checked; try {//from w w w .j ava2s . co m checked = check(cond, kind); } catch (IllegalArgumentException e) { return EMPTY_QUERY_BUILDER; } return fillAttrQuery(checked.getLeft(), checked.getMiddle(), checked.getRight()); }
From source file:org.apache.syncope.core.persistence.jpa.dao.JPAAnySearchDAO.java
private String getQuery(final AnyCond cond, final boolean not, final List<Object> parameters, final SearchSupport svs) { Triple<PlainSchema, PlainAttrValue, AnyCond> checked; try {// ww w.j ava2 s .c om checked = check(cond, svs.anyTypeKind); } catch (IllegalArgumentException e) { return EMPTY_QUERY; } StringBuilder query = new StringBuilder("SELECT DISTINCT any_id FROM ").append(svs.field().name) .append(" WHERE "); fillAttrQuery(query, checked.getMiddle(), checked.getLeft(), checked.getRight(), not, parameters, svs); return query.toString(); }
From source file:org.apache.syncope.core.provisioning.java.data.AccessTokenDataBinderImpl.java
@Override public Pair<String, Date> create(final String subject, final Map<String, Object> claims, final byte[] authorities, final boolean replaceExisting) { String body = null;//from ww w . j a v a 2s .c o m Date expiryTime = null; AccessToken existing = accessTokenDAO.findByOwner(subject); if (existing != null) { body = existing.getBody(); expiryTime = existing.getExpiryTime(); } if (replaceExisting || body == null) { Triple<String, String, Date> created = generateJWT(subject, confDAO.find("jwt.lifetime.minutes", 120L), claims); body = created.getMiddle(); expiryTime = created.getRight(); AccessToken accessToken = entityFactory.newEntity(AccessToken.class); accessToken.setKey(created.getLeft()); accessToken.setBody(body); accessToken.setExpiryTime(expiryTime); accessToken.setOwner(subject); if (!adminUser.equals(accessToken.getOwner())) { accessToken.setAuthorities(authorities); } accessTokenDAO.save(accessToken); } if (replaceExisting && existing != null) { accessTokenDAO.delete(existing); } return Pair.of(body, expiryTime); }
From source file:org.apache.zeppelin.notebook.ParagraphTest.java
@Test public void testCursorPosition() { Paragraph paragraph = spy(new Paragraph()); // left = buffer, middle = cursor position into source code, right = cursor position after parse List<Triple<String, Integer, Integer>> dataSet = Arrays.asList(Triple.of("%jdbc schema.", 13, 7), Triple.of(" %jdbc schema.", 16, 7), Triple.of(" \n%jdbc schema.", 15, 7), Triple.of("%jdbc schema.table. ", 19, 13), Triple.of("%jdbc schema.\n\n", 13, 7), Triple.of(" %jdbc schema.tab\n\n", 18, 10), Triple.of(" \n%jdbc schema.\n \n", 16, 7), Triple.of(" \n%jdbc schema.\n \n", 16, 7), Triple.of(" \n%jdbc\n\n schema\n \n", 17, 6), Triple.of("%another\n\n schema.", 18, 7), Triple.of("\n\n schema.", 10, 7), Triple.of("schema.", 7, 7), Triple.of("schema. \n", 7, 7), Triple.of(" \n %jdbc", 11, 0), Triple.of("\n %jdbc", 9, 0), Triple.of("%jdbc \n schema", 16, 6), Triple.of("%jdbc \n \n schema", 20, 6)); for (Triple<String, Integer, Integer> data : dataSet) { paragraph.setText(data.getLeft()); Integer actual = paragraph.calculateCursorPosition(data.getLeft(), data.getMiddle()); assertEquals(data.getRight(), actual); }/* w w w . j a va 2s . c om*/ }
From source file:org.dllearner.algorithms.qtl.operations.lgg.AbstractLGGGenerator.java
protected RDFResourceTree computeLGG(RDFResourceTree tree1, RDFResourceTree tree2, boolean learnFilters) { subCalls++;/*from w w w. j a v a2 s .co m*/ // 1. compare the root nodes // a) if both root nodes have same URI or literal value, just return one of the two trees as LGG if ((tree1.isResourceNode() || tree1.isLiteralValueNode()) && tree1.getData().equals(tree2.getData())) { logger.trace("Early termination. Tree 1 {} and tree 2 {} describe the same resource.", tree1, tree2); return tree1; } // b) handle literal nodes if (tree1.isLiteralNode() && tree2.isLiteralNode()) { return processLiteralNodes(tree1, tree2); } // c) handle class nodes if (tree1.isClassNode()) { return processClassNodes(tree1, tree2); } // d) else create new empty tree RDFResourceTree lgg = new RDFResourceTree(); // 2. compare the edges // we only have to compare edges which are // a) contained in both trees // b) related via subsumption, i.e. p1 p2 // get edges of tree 2 connected via subsumption Set<Triple<Node, Node, Node>> relatedEdges = getRelatedEdges(tree1, tree2); for (Triple<Node, Node, Node> entry : relatedEdges) { if (stop || isTimeout()) { complete = false; break; } Node edge1 = entry.getLeft(); Node edge2 = entry.getMiddle(); Node lcs = entry.getRight(); Set<RDFResourceTree> addedChildren = new HashSet<>(); // loop over children of first tree for (RDFResourceTree child1 : tree1.getChildren(edge1)) {//System.out.println("c1:" + child1); if (stop || isTimeout()) { complete = false; break; } // loop over children of second tree for (RDFResourceTree child2 : tree2.getChildren(edge2)) {//System.out.println("c2:" + child2); if (stop || isTimeout()) { complete = false; break; } RDFResourceTree lggChild = computeLGG(child1, child2, learnFilters); // check if there was already a more specific child computed before // and if so don't add the current one boolean add = true; for (Iterator<RDFResourceTree> it = addedChildren.iterator(); it.hasNext();) { RDFResourceTree addedChild = it.next(); if (isSubTreeOf(addedChild, lggChild)) { // logger.trace("Skipped adding: Previously added child {} is subsumed by {}.", // addedChild.getStringRepresentation(), // lggChild.getStringRepresentation()); add = false; break; } else if (isSubTreeOf(lggChild, addedChild)) { // logger.trace("Removing child node: {} is subsumed by previously added child {}.", // lggChild.getStringRepresentation(), // addedChild.getStringRepresentation()); lgg.removeChild(addedChild, lgg.getEdgeToChild(addedChild)); it.remove(); } } if (add) { lgg.addChild(lggChild, lcs); addedChildren.add(lggChild); // logger.trace("Adding child {}", lggChild.getStringRepresentation()); } } } } return lgg; }
From source file:org.dllearner.algorithms.qtl.operations.lgg.AbstractLGGGenerator.java
protected RDFResourceTree processClassNodes(RDFResourceTree tree1, RDFResourceTree tree2) { RDFResourceTree lgg = new RDFResourceTree(); Set<Triple<Node, Node, Node>> relatedEdges = getRelatedEdges(tree1, tree2); for (Triple<Node, Node, Node> entry : relatedEdges) { if (stop || isTimeout()) { complete = false;/*from www. ja v a 2s.c om*/ break; } Node edge1 = entry.getLeft(); Node edge2 = entry.getMiddle(); Node lcs = entry.getRight(); Set<RDFResourceTree> addedChildren = new HashSet<>(); // loop over children of first tree for (RDFResourceTree child1 : tree1.getChildren(edge1)) {//System.out.println("c1:" + child1); if (stop || isTimeout()) { complete = false; break; } // loop over children of second tree for (RDFResourceTree child2 : tree2.getChildren(edge2)) {//System.out.println("c2:" + child2); if (stop || isTimeout()) { complete = false; break; } RDFResourceTree lggChild = computeLGG(child1, child2, false); // check if there was already a more specific child computed before // and if so don't add the current one boolean add = true; for (Iterator<RDFResourceTree> it = addedChildren.iterator(); it.hasNext();) { RDFResourceTree addedChild = it.next(); if (isSubTreeOf(addedChild, lggChild)) { // logger.trace("Skipped adding: Previously added child {} is subsumed by {}.", // addedChild.getStringRepresentation(), // lggChild.getStringRepresentation()); add = false; break; } else if (isSubTreeOf(lggChild, addedChild)) { // logger.trace("Removing child node: {} is subsumed by previously added child {}.", // lggChild.getStringRepresentation(), // addedChild.getStringRepresentation()); lgg.removeChild(addedChild, lgg.getEdgeToChild(addedChild)); it.remove(); } } if (add) { lgg.addChild(lggChild, lcs); addedChildren.add(lggChild); // logger.trace("Adding child {}", lggChild.getStringRepresentation()); } } } } return lgg; }
From source file:org.dllearner.algorithms.qtl.operations.lgg.LGGGeneratorRDFS.java
@Override protected RDFResourceTree processClassNodes(RDFResourceTree tree1, RDFResourceTree tree2) { if (tree1.isResourceNode() && tree2.isResourceNode()) { System.out.print("LCS(" + tree1 + ", " + tree2 + ")"); Node lcs = NonStandardReasoningServices.getLeastCommonSubsumer(reasoner, tree1.getData(), tree2.getData(), EntityType.CLASS); System.out.println(" = " + lcs); if (lcs != null) { return new RDFResourceTree(lcs); }//from ww w . j a v a 2s. com } RDFResourceTree lgg = new RDFResourceTree(); Set<Triple<Node, Node, Node>> relatedEdges = getRelatedEdges(tree1, tree2); for (Triple<Node, Node, Node> entry : relatedEdges) { Node edge1 = entry.getLeft(); Node edge2 = entry.getMiddle(); Node lcs = entry.getRight(); Set<RDFResourceTree> addedChildren = new HashSet<>(); // loop over children of first tree for (RDFResourceTree child1 : tree1.getChildren(edge1)) {//System.out.println("c1:" + child1); // loop over children of second tree for (RDFResourceTree child2 : tree2.getChildren(edge2)) {//System.out.println("c2:" + child2); RDFResourceTree lggChild = computeLGG(child1, child2, false); // check if there was already a more specific child computed before // and if so don't add the current one boolean add = true; for (Iterator<RDFResourceTree> it = addedChildren.iterator(); it.hasNext();) { RDFResourceTree addedChild = it.next(); if (isSubTreeOf(addedChild, lggChild)) { // logger.trace("Skipped adding: Previously added child {} is subsumed by {}.", // addedChild.getStringRepresentation(), // lggChild.getStringRepresentation()); add = false; break; } else if (isSubTreeOf(lggChild, addedChild)) { // logger.trace("Removing child node: {} is subsumed by previously added child {}.", // lggChild.getStringRepresentation(), // addedChild.getStringRepresentation()); lgg.removeChild(addedChild, lgg.getEdgeToChild(addedChild)); it.remove(); } } if (add) { lgg.addChild(lggChild, lcs); addedChildren.add(lggChild); // logger.trace("Adding child {}", lggChild.getStringRepresentation()); } } } } return lgg; }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionBool.java
/** * generic test-case// www . ja va2s. c om * * @param p_input test-case data * @throws IllegalAccessException is thrwon on instantiation error * @throws InstantiationException is thrwon on instantiation error */ @Test @UseDataProvider("generate") public final void execute(final Triple<List<ITerm>, Class<? extends IAction>, Stream<Object>> p_input) throws IllegalAccessException, InstantiationException { final List<ITerm> l_return = new ArrayList<>(); p_input.getMiddle().newInstance().execute(false, null, p_input.getLeft(), l_return); Assert.assertArrayEquals(l_return.stream().map(ITerm::raw).toArray(), p_input.getRight().toArray()); }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionCrypto.java
/** * test crypt key generation//from w w w . j a v a 2 s.c om * * @param p_crypt crypt definition */ @Test @UseDataProvider("generatecrypt") public final void createkey(final Triple<String, Integer, Integer> p_crypt) { final List<ITerm> l_return = new ArrayList<>(); new CCreateKey().execute(false, IContext.EMPTYPLAN, Stream.of(CRawTerm.from(p_crypt.getLeft())).collect(Collectors.toList()), l_return); Assert.assertEquals(l_return.size(), p_crypt.getMiddle().intValue()); }