Search in sources :

Example 21 with ToString

use of lombok.ToString in project cas by apereo.

the class WsFederationCredentialsToPrincipalResolver method extractPrincipalId.

/**
 * Extracts the principalId.
 *
 * @param credentials the credentials
 * @return the principal id
 */
@Override
protected String extractPrincipalId(final Credential credentials, final Principal currentPrincipal) {
    final WsFederationCredential wsFedCredentials = (WsFederationCredential) credentials;
    final Map<String, List<Object>> attributes = wsFedCredentials.getAttributes();
    LOGGER.debug("Credential attributes provided are: [{}]", attributes);
    final String idAttribute = this.configuration.getIdentityAttribute();
    if (attributes.containsKey(idAttribute)) {
        LOGGER.debug("Extracting principal id from attribute [{}]", this.configuration.getIdentityAttribute());
        final List<Object> idAttributeAsList = attributes.get(this.configuration.getIdentityAttribute());
        if (idAttributeAsList.size() > 1) {
            LOGGER.warn("Found multiple values for id attribute [{}].", idAttribute);
        }
        final String principalId = idAttributeAsList.get(0).toString();
        LOGGER.debug("Principal Id extracted from credentials: [{}]", principalId);
        return principalId;
    }
    LOGGER.warn("Credential attributes do not include an attribute for [{}]. " + "This will prohibit CAS to construct a meaningful authenticated principal. " + "Examine the released claims and ensure [{}] is allowed", idAttribute, idAttribute);
    return null;
}
Also used : List(java.util.List) ToString(lombok.ToString)

Example 22 with ToString

use of lombok.ToString in project oap by oaplatform.

the class Tree method trace.

public String trace(List<?> query, Predicate<T> filter) {
    final HashMap<T, HashMap<Integer, TraceOperationTypeValues>> result = new HashMap<>();
    final long[][] longQuery = convertQueryToLong(query);
    trace(root, longQuery, result, new TraceBuffer(), true);
    final String queryStr = "query = " + Stream.of(query).zipWithIndex().map(p -> dimensions.get(p._2).name + ":" + printValue(p._1)).collect(joining(",", "[", "]")) + "\n";
    final String out = result.entrySet().stream().filter(e -> filter.test(e.getKey())).map(e -> e.getKey().toString() + ": \n" + e.getValue().entrySet().stream().map(dv -> {
        final Dimension dimension = dimensions.get(dv.getKey());
        return "    " + dimension.name + "/" + dv.getKey() + ": " + dv.getValue().toString(dimension) + " " + queryToString(query, dv.getKey());
    }).collect(joining("\n"))).collect(joining("\n"));
    return queryStr + (out.length() > 0 ? "Expecting:\n" + out : "ALL OK");
}
Also used : Pair(oap.util.Pair) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) MemoryMeter(oap.util.MemoryMeter) Pair.__(oap.util.Pair.__) ArrayUtils(org.apache.commons.lang3.ArrayUtils) HashMap(java.util.HashMap) Strings(oap.util.Strings) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Collectors.toMap(java.util.stream.Collectors.toMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Lists(oap.util.Lists) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ToString(lombok.ToString) Stream(oap.util.Stream) CONTAINS(oap.tree.Dimension.OperationType.CONTAINS) LongStream(java.util.stream.LongStream) Predicate(java.util.function.Predicate) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) lombok.val(lombok.val) OperationType(oap.tree.Dimension.OperationType) Set(java.util.Set) EqualsAndHashCode(lombok.EqualsAndHashCode) NOT_CONTAINS(oap.tree.Dimension.OperationType.NOT_CONTAINS) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Direction(oap.tree.Dimension.Direction) ANY_AS_ARRAY(oap.tree.Consts.ANY_AS_ARRAY) Optional(java.util.Optional) BitSet(java.util.BitSet) Comparator(java.util.Comparator) Collections(java.util.Collections) HashMap(java.util.HashMap) ToString(lombok.ToString)

Example 23 with ToString

use of lombok.ToString in project oap by oaplatform.

the class Client method execute.

@SneakyThrows
private Optional<Response> execute(HttpUriRequest request, Map<String, Object> headers, long timeout) {
    try {
        headers.forEach((name, value) -> request.setHeader(name, value == null ? "" : value.toString()));
        Future<HttpResponse> future = client.execute(request, FUTURE_CALLBACK);
        HttpResponse response = timeout == FOREVER ? future.get() : future.get(timeout, MILLISECONDS);
        Map<String, String> responsHeaders = headers(response);
        Response result;
        if (response.getEntity() != null) {
            HttpEntity entity = response.getEntity();
            try (InputStream is = entity.getContent()) {
                result = new Response(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase(), responsHeaders, Optional.ofNullable(entity.getContentType()).map(ct -> ContentType.parse(entity.getContentType().getValue())), ByteStreams.toByteArray(is));
            }
        } else
            result = new Response(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase(), responsHeaders);
        builder.onSuccess.accept(this);
        return Optional.of(result);
    } catch (ExecutionException e) {
        final ExecutionException newEx = new ExecutionException(request.getURI().toString(), e.getCause());
        builder.onError.accept(this, newEx);
        throw newEx;
    } catch (IOException e) {
        final ExecutionException newEx = new ExecutionException(request.getURI().toString(), e);
        builder.onError.accept(this, newEx);
        throw newEx;
    } catch (InterruptedException | TimeoutException e) {
        builder.onTimeout.accept(this);
        return Optional.empty();
    }
}
Also used : HttpResponse(org.apache.http.HttpResponse) HttpEntity(org.apache.http.HttpEntity) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) HttpResponse(org.apache.http.HttpResponse) ToString(lombok.ToString) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) SneakyThrows(lombok.SneakyThrows)

Example 24 with ToString

use of lombok.ToString in project jcabi-github by jcabi.

the class MkComments method post.

@Override
public Comment post(final String text) throws IOException {
    this.storage.lock();
    final int number;
    try {
        final String timestamp = new Github.Time().toString();
        number = 1 + this.storage.xml().nodes("//comment/number").size();
        this.storage.apply(new Directives().xpath(this.xpath()).add("comment").add("number").set(Integer.toString(number)).up().add("url").set(String.format(// @checkstyle LineLength (1 line)
        "https://api.jcabi-github.invalid/repos/%s/%s/issues/comments/%d", this.repo.user(), this.repo.repo(), number)).up().add("body").set(text).up().add("user").add("login").set(this.self).up().up().add("created_at").set(timestamp).up().add("updated_at").set(timestamp));
    } finally {
        this.storage.unlock();
    }
    Logger.info(this, "comment #%d posted to issue #%d by %s: %[text]s", number, this.issue().number(), this.self, text);
    return this.get(number);
}
Also used : Github(com.jcabi.github.Github) Directives(org.xembly.Directives) ToString(lombok.ToString)

Example 25 with ToString

use of lombok.ToString in project sql-boot by sql-boot.

the class SqlResourceType method read.

@Override
public Stream<DbResource> read(final Uri uri) throws BootException {
    final Map<String, Object> variables = new HashMap<>();
    variables.put("uri", uri);
    return sqlQuery.select(variables).map(o -> {
        final List<Object> path = o.entrySet().stream().filter(v -> (v.getKey().startsWith("@") || v.getKey().startsWith("_"))).map(Entry::getValue).collect(toList());
        final String name = path.get(path.size() - 1).toString();
        final Map<String, Object> headers = o.entrySet().stream().collect(toMap(k -> strip(strip(k.getKey(), "@"), "_"), v -> ofNullable(v.getValue()).orElse(""), (a, b) -> a, LinkedHashMap::new));
        return new DbResourceImpl(name, this, new DbUri(this.name(), path.stream().map(Object::toString).collect(toList())), headers);
    });
}
Also used : Optional.ofNullable(java.util.Optional.ofNullable) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) SqlQuery(com.github.mgramin.sqlboot.sql.SqlQuery) HashMap(java.util.HashMap) BootException(com.github.mgramin.sqlboot.exceptions.BootException) DbResourceImpl(com.github.mgramin.sqlboot.model.resource.impl.DbResourceImpl) LinkedHashMap(java.util.LinkedHashMap) ResourceType(com.github.mgramin.sqlboot.model.resource_type.ResourceType) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Stream(java.util.stream.Stream) Collectors.toMap(java.util.stream.Collectors.toMap) Uri(com.github.mgramin.sqlboot.model.uri.Uri) Map(java.util.Map) DbResource(com.github.mgramin.sqlboot.model.resource.DbResource) Entry(java.util.Map.Entry) ToString(lombok.ToString) StringUtils.strip(org.apache.commons.lang3.StringUtils.strip) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) DbResourceImpl(com.github.mgramin.sqlboot.model.resource.impl.DbResourceImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ToString(lombok.ToString)

Aggregations

ToString (lombok.ToString)28 Map (java.util.Map)6 HashMap (java.util.HashMap)5 List (java.util.List)4 HashSet (java.util.HashSet)3 EclipseNode (lombok.eclipse.EclipseNode)3 Slf4j (lombok.extern.slf4j.Slf4j)3 lombok.val (lombok.val)3 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)2 Github (com.jcabi.github.Github)2 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 LinkedHashMap (java.util.LinkedHashMap)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Collectors.toList (java.util.stream.Collectors.toList)2 Collectors.toMap (java.util.stream.Collectors.toMap)2 Getter (lombok.Getter)2