基本認証はhttp-builder-ngで動作しません - 認証要求はngによって渡されませんか?基本認証http-builder-ng
build.gradle
group 'org.vinay.rest'
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
// https://mvnrepository.com/artifact/io.github.http-builder-ng/http-builder-ng-core
testRuntime group: 'io.github.http-builder-ng', name: 'http-builder-ng-core', version: '0.17.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.spockframework', name: 'spock-core', version: '1.0-groovy-2.4'
testCompile group: 'ch.qos.logback', name: 'logback-classic', version:'1.0.13'
}
GetD2LUserBySourcedIdSpec.groovy
import spock.lang.Specification
import groovyx.net.http.HttpBuilder
/**
* Created by e5017581 on 11/07/2017.
*/
class GetD2LUserBySourcedIdSpec extends Specification {
def "test get /users call with d2lSourced Id"() {
given:
def httpClient = HttpBuilder.configure {
request.uri = 'http://esbvucmv5.vu.edu.au/D2L/2.0'
//request.headers['Authorization'] = 'Basic ZDJscnM6MTRkMmxycw=='
//request.headers['Content-Type'] = "application/json"
request.auth.basic'd2lrs', '14d2lrs'
}
when:
def user = httpClient.get {
//request.auth.basic 'd2lrs', '14d2lrs'
//request.headers['Authorization'] = 'Basic ZDJscnM6MTRkMmxycw=='
request.uri.path = '/users/'
request.uri.query = [sourcedId: 's4504565']
}
then:
println user.dump()
null != user
}
}
のhttp-ログ:
com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 "GetD2LUserBySourcedIdSpec,test get /users call with d2lSourced Id"
15:41:36,714 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.groovy] at [file:/C:/Users/e5017581/IdeaProjects/http-builder-ng2/build/resources/test/logback.groovy]
15:41:36,935 |-INFO in [email protected] - Added status listener of type [ch.qos.logback.core.status.OnConsoleStatusListener]
15:41:36,946 |-INFO in [email protected] - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
15:41:36,947 |-INFO in [email protected] - Naming appender as [CONSOLE]
15:41:37.100 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Request-Header: Accept-Encoding -> [gzip, deflate]
15:41:37.306 [main] DEBUG g.net.http.JavaHttpBuilder.content - Response-Body: null
15:41:37.307 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Date -> Tue, 11 Jul 2017 05:41:37 GMT
15:41:37.307 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Content-Type -> text/plain
15:41:37.307 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Content-Length -> 42
15:41:37.307 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Connection -> keep-alive
15:41:37.307 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Server -> Mule/SNAPSHOT
15:41:37.307 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: WWW-Authenticate -> Basic realm="realm"
15:41:37.307 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: http.status -> 401
15:41:37.307 [main] DEBUG g.net.http.JavaHttpBuilder.headers - Response-Header: Set-Cookie -> VUpersist=rd2480o00000000000000000000ffff0a4c0016o80; path=/; Httponly
groovyx.net.http.HttpException: Unauthorized
at groovyx.net.http.NativeHandlers.failure(NativeHandlers.java:69)
at groovy.lang.Closure.call(Closure.java:423)
at groovyx.net.http.fn.ClosureBiFunction.apply(ClosureBiFunction.java:45)
at groovyx.net.http.HttpBuilder$ResponseHandlerFunction.apply(HttpBuilder.java:1834)
at groovyx.net.http.JavaHttpBuilder$Action.lambda$execute$2(JavaHttpBuilder.java:157)
at groovyx.net.http.JavaHttpBuilder$ThreadLocalAuth.with(JavaHttpBuilder.java:320)
at groovyx.net.http.JavaHttpBuilder$Action.execute(JavaHttpBuilder.java:111)
at groovyx.net.http.JavaHttpBuilder.createAndExecute(JavaHttpBuilder.java:362)
at groovyx.net.http.JavaHttpBuilder.doGet(JavaHttpBuilder.java:369)
at groovyx.net.http.HttpObjectConfigImpl.nullInterceptor(HttpObjectConfigImpl.java:45)
at groovyx.net.http.HttpBuilder.get(HttpBuilder.java:360)
at groovyx.net.http.HttpBuilder.get(HttpBuilder.java:1311)
at GetD2LUserBySourcedIdSpec.test get /users call with d2lSourced Id(GetD2LUserBySourcedIdSpec.groovy:19)
Process finished with exit code -1
使用するサーバーとこれに関連するサーバーログを含める必要があります。 – cjstehno
私は春のセキュリティ(基本とダイジェスト)と認証が期待通りに機能する単純なスプリングブートアプリケーション(tomcat)に対してテストしました。 Undertowに対してもテストされています。あなたのサーバーが何かの理由で間違っているとか、間違っていると言えます。サーバーが何らかの理由で適切にサポートされていないことがわかったら、プロジェクトで問題を作成してください。 – cjstehno
ご回答いただきありがとうございます。私たちは、RESTエンドポイント用のmulesoft 3.8.0エンタープライズ版サーバーを使用しています。間違ったクレデンシャルを持つ郵便配達員と一緒にしようとすると、私は迷惑メールのログにエラーが表示されますが、スクリプトを試してもログは表示されません。 – Vinay