本文整理汇总了Java中org.apache.commons.httpclient.auth.AuthScope.ANY_REALM属性的典型用法代码示例。如果您正苦于以下问题:Java AuthScope.ANY_REALM属性的具体用法?Java AuthScope.ANY_REALM怎么用?Java AuthScope.ANY_REALM使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.httpclient.auth.AuthScope
的用法示例。
在下文中一共展示了AuthScope.ANY_REALM属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAnonymousContent
public void testAnonymousContent() throws Exception {
// disable credentials -> anonymous session
final URL url = new URL(HTTP_BASE_URL);
final AuthScope scope = new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM);
httpClient.getParams().setAuthenticationPreemptive(false);
httpClient.getState().setCredentials(scope, null);
try {
assertContent();
} finally {
// re-enable credentials -> admin session
httpClient.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
httpClient.getState().setCredentials(scope, defaultcreds);
}
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:16,代码来源:AnonymousAccessTest.java
示例2: assertAuthenticatedHttpStatus
/** Verify that given URL returns expectedStatusCode
* @throws IOException */
public void assertAuthenticatedHttpStatus(Credentials creds, String urlString, int expectedStatusCode, String assertMessage) throws IOException {
URL baseUrl = new URL(HTTP_BASE_URL);
AuthScope authScope = new AuthScope(baseUrl.getHost(), baseUrl.getPort(), AuthScope.ANY_REALM);
GetMethod getMethod = new GetMethod(urlString);
getMethod.setDoAuthentication(true);
Credentials oldCredentials = httpClient.getState().getCredentials(authScope);
try {
httpClient.getState().setCredentials(authScope, creds);
final int status = httpClient.executeMethod(getMethod);
if(assertMessage == null) {
assertEquals(urlString,expectedStatusCode, status);
} else {
assertEquals(assertMessage, expectedStatusCode, status);
}
} finally {
httpClient.getState().setCredentials(authScope, oldCredentials);
}
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:21,代码来源:AuthenticatedTestUtil.java
示例3: assertAuthenticatedPostStatus
/** Execute a POST request and check status */
public void assertAuthenticatedPostStatus(Credentials creds, String url, int expectedStatusCode, List<NameValuePair> postParams, String assertMessage)
throws IOException {
final PostMethod post = new PostMethod(url);
post.setFollowRedirects(false);
URL baseUrl = new URL(HTTP_BASE_URL);
AuthScope authScope = new AuthScope(baseUrl.getHost(), baseUrl.getPort(), AuthScope.ANY_REALM);
post.setDoAuthentication(true);
Credentials oldCredentials = httpClient.getState().getCredentials(authScope);
try {
httpClient.getState().setCredentials(authScope, creds);
if(postParams!=null) {
final NameValuePair [] nvp = {};
post.setRequestBody(postParams.toArray(nvp));
}
final int status = httpClient.executeMethod(post);
if(assertMessage == null) {
assertEquals(expectedStatusCode, status);
} else {
assertEquals(assertMessage, expectedStatusCode, status);
}
} finally {
httpClient.getState().setCredentials(authScope, oldCredentials);
}
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:28,代码来源:AuthenticatedTestUtil.java
示例4: testCredentialsMatching
public void testCredentialsMatching() {
Credentials creds1 = new UsernamePasswordCredentials("name1", "pass1");
Credentials creds2 = new UsernamePasswordCredentials("name2", "pass2");
Credentials creds3 = new UsernamePasswordCredentials("name3", "pass3");
AuthScope scope1 = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM);
AuthScope scope2 = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, "somerealm");
AuthScope scope3 = new AuthScope("somehost", AuthScope.ANY_PORT, AuthScope.ANY_REALM);
HttpState state = new HttpState();
state.setCredentials(scope1, creds1);
state.setCredentials(scope2, creds2);
state.setCredentials(scope3, creds3);
Credentials got = state.getCredentials(
new AuthScope("someotherhost", 80, "someotherrealm", "basic"));
Credentials expected = creds1;
assertEquals(expected, got);
got = state.getCredentials(
new AuthScope("someotherhost", 80, "somerealm", "basic"));
expected = creds2;
assertEquals(expected, got);
got = state.getCredentials(
new AuthScope("somehost", 80, "someotherrealm", "basic"));
expected = creds3;
assertEquals(expected, got);
}
示例5: addAuth
@Override
public void addAuth(AuthCredentials creds) {
String host = (StringUtils.isBlank(creds.getHost()) || "*".equals(creds.getHost())) ? AuthScope.ANY_HOST : creds.getHost();
String realm = (StringUtils.isBlank(creds.getRealm()) || "*".equals(creds.getRealm())) ? AuthScope.ANY_REALM : creds.getRealm();
int port = NumberUtils.toInt(creds.getPortString(), AuthScope.ANY_PORT);
String scheme = creds.getScheme() != null ? creds.getScheme().getRepresentation() : AuthScope.ANY_SCHEME;
Credentials defaultcreds = new UsernamePasswordCredentials(creds.getUserName(), creds.getPassword());
httpclient.getState().setCredentials(new AuthScope(host, port, realm, scheme), defaultcreds);
}
示例6: setProxyCredentials
public void setProxyCredentials(String username, String password) {
if (username == null || username.trim().length() == 0)
return;
Credentials cred = new UsernamePasswordCredentials(username, password);
AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT,
AuthScope.ANY_REALM);
client.getState().setProxyCredentials(scope, cred);
proxyAuthent = true;
}
示例7: setCredentials
public void setCredentials(String username, String password) {
Credentials cred = new UsernamePasswordCredentials(username, password);
AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT,
AuthScope.ANY_REALM);
client.getState().setCredentials(scope, cred);
client.getParams().setAuthenticationPreemptive(true);
serverAuthent = true;
}
示例8: getAuthenticatedContent
/** retrieve the contents of given URL and assert its content type
* @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be checked
* @throws IOException
* @throws HttpException */
public String getAuthenticatedContent(Credentials creds, String url, String expectedContentType, List<NameValuePair> params, int expectedStatusCode) throws IOException {
final GetMethod get = new GetMethod(url);
URL baseUrl = new URL(HTTP_BASE_URL);
AuthScope authScope = new AuthScope(baseUrl.getHost(), baseUrl.getPort(), AuthScope.ANY_REALM);
get.setDoAuthentication(true);
Credentials oldCredentials = httpClient.getState().getCredentials(authScope);
try {
httpClient.getState().setCredentials(authScope, creds);
if(params != null) {
final NameValuePair [] nvp = new NameValuePair[0];
get.setQueryString(params.toArray(nvp));
}
final int status = httpClient.executeMethod(get);
final InputStream is = get.getResponseBodyAsStream();
final StringBuffer content = new StringBuffer();
final String charset = get.getResponseCharSet();
final byte [] buffer = new byte[16384];
int n = 0;
while( (n = is.read(buffer, 0, buffer.length)) > 0) {
content.append(new String(buffer, 0, n, charset));
}
assertEquals("Expected status " + expectedStatusCode + " for " + url + " (content=" + content + ")",
expectedStatusCode,status);
final Header h = get.getResponseHeader("Content-Type");
if(expectedContentType == null) {
if(h!=null) {
fail("Expected null Content-Type, got " + h.getValue());
}
} else if(CONTENT_TYPE_DONTCARE.equals(expectedContentType)) {
// no check
} else if(h==null) {
fail(
"Expected Content-Type that starts with '" + expectedContentType
+" but got no Content-Type header at " + url
);
} else {
assertTrue(
"Expected Content-Type that starts with '" + expectedContentType
+ "' for " + url + ", got '" + h.getValue() + "'",
h.getValue().startsWith(expectedContentType)
);
}
return content.toString();
} finally {
httpClient.getState().setCredentials(authScope, oldCredentials);
}
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:54,代码来源:AuthenticatedTestUtil.java
示例9: getAuthenticatedPostContent
/** retrieve the contents of given URL and assert its content type
* @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be checked
* @throws IOException
* @throws HttpException */
public String getAuthenticatedPostContent(Credentials creds, String url, String expectedContentType, List<NameValuePair> postParams, int expectedStatusCode) throws IOException {
final PostMethod post = new PostMethod(url);
URL baseUrl = new URL(HTTP_BASE_URL);
AuthScope authScope = new AuthScope(baseUrl.getHost(), baseUrl.getPort(), AuthScope.ANY_REALM);
post.setDoAuthentication(true);
Credentials oldCredentials = httpClient.getState().getCredentials(authScope);
try {
httpClient.getState().setCredentials(authScope, creds);
if(postParams!=null) {
final NameValuePair [] nvp = {};
post.setRequestBody(postParams.toArray(nvp));
}
final int status = httpClient.executeMethod(post);
final InputStream is = post.getResponseBodyAsStream();
final StringBuffer content = new StringBuffer();
final String charset = post.getResponseCharSet();
final byte [] buffer = new byte[16384];
int n = 0;
while( (n = is.read(buffer, 0, buffer.length)) > 0) {
content.append(new String(buffer, 0, n, charset));
}
assertEquals("Expected status " + expectedStatusCode + " for " + url + " (content=" + content + ")",
expectedStatusCode,status);
final Header h = post.getResponseHeader("Content-Type");
if(expectedContentType == null) {
if(h!=null) {
fail("Expected null Content-Type, got " + h.getValue());
}
} else if(CONTENT_TYPE_DONTCARE.equals(expectedContentType)) {
// no check
} else if(h==null) {
fail(
"Expected Content-Type that starts with '" + expectedContentType
+" but got no Content-Type header at " + url
);
} else {
assertTrue(
"Expected Content-Type that starts with '" + expectedContentType
+ "' for " + url + ", got '" + h.getValue() + "'",
h.getValue().startsWith(expectedContentType)
);
}
return content.toString();
} finally {
httpClient.getState().setCredentials(authScope, oldCredentials);
}
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:55,代码来源:AuthenticatedTestUtil.java
示例10: addSecurityContextToHeader
/**
* Adds the user ID and password to the HTTP headers using BASIC security.
* Adds the parameter of the thread local security context to the HTTP header.
*
* @param getMethod
*/
protected void addSecurityContextToHeader(HttpClient client, GetMethod getMethod,
boolean includeVistaSecurityContext)
{
// BTW, don't import the Credentials class because there is an app specific Credentials
// that derives from the java Principal class, which is where the thread local
// secutity context is stored
org.apache.commons.httpclient.Credentials imageXChangeCredentials = null;
try
{
ProxyService imageService = proxyServices.getProxyService(ProxyServiceType.image);
if(imageService.getCredentials() instanceof String)
imageXChangeCredentials =
new UsernamePasswordCredentials(imageService.getUid(), (String)(imageService.getCredentials()) );
AuthScope imageXChangeAuthScope = new AuthScope(imageService.getHost(), imageService.getPort(), AuthScope.ANY_REALM);
client.getState().setCredentials(imageXChangeAuthScope, imageXChangeCredentials);
}
catch(ProxyServiceNotFoundException psnfX)
{
logger.warn("Cannot find image proxy service to set credentials, continuing without", psnfX);
}
//Header authorizationHeader = new Header("Authorization", "Basic ");
//getMethod.setRequestHeader(authorizationHeader);
// the thread local security credentials (the VistA specific stuff) is written into
// app specific HTTP headers
TransactionContext transactionContext = TransactionContextFactory.get();
// 3-11-2008 DKB - modified to send all headers except the DUZ if includeVistaSecurityContext is false
// the silver BIA was throwing an error because we were not sending httpHeaderFullName, httpHeaderSiteName,
// httpHeaderSiteNumber and httpHeaderSSN
if(includeVistaSecurityContext)
{
if(transactionContext.getDuz() != null)
getMethod.setRequestHeader(new Header(TransactionContextHttpHeaders.httpHeaderDuz,
transactionContext.getDuz()));
String securityToken = transactionContext.getBrokerSecurityToken();
if(securityToken != null && securityToken.length() > 0)
getMethod.setRequestHeader(new Header(TransactionContextHttpHeaders.httpHeaderBrokerSecurityTokenId,
securityToken));
String cacheLocationId = transactionContext.getCacheLocationId();
if(cacheLocationId != null && cacheLocationId.length() > 0)
getMethod.setRequestHeader(new Header(TransactionContextHttpHeaders.httpHeaderCacheLocationId,
cacheLocationId));
String userDivision = transactionContext.getUserDivision();
if(userDivision != null && userDivision.length() > 0)
getMethod.setRequestHeader(new Header(TransactionContextHttpHeaders.httpHeaderUserDivision,
userDivision));
}
if(transactionContext.getFullName() != null)
getMethod.setRequestHeader(new Header(TransactionContextHttpHeaders.httpHeaderFullName,
transactionContext.getFullName()));
if(transactionContext.getSiteName() != null)
getMethod.setRequestHeader(new Header(TransactionContextHttpHeaders.httpHeaderSiteName,
transactionContext.getSiteName()));
if(transactionContext.getSiteNumber() != null)
getMethod.setRequestHeader(new Header(TransactionContextHttpHeaders.httpHeaderSiteNumber,
transactionContext.getSiteNumber()));
if(transactionContext.getSsn() != null)
getMethod.setRequestHeader(new Header(TransactionContextHttpHeaders.httpHeaderSSN,
transactionContext.getSsn()));
if(transactionContext.getTransactionId() != null)
getMethod.setRequestHeader(new Header(TransactionContextHttpHeaders.httpHeaderTransactionId,
transactionContext.getTransactionId()));
// 1/8/07 JMW - Add the purpose of use to the request for images
getMethod.setRequestHeader(new Header(TransactionContextHttpHeaders.httpHeaderPurposeOfUse,
Requestor.PurposeOfUse.routineMedicalCare.getDescription()));
}
示例11: getCommonsHttpSolrServer
public static CommonsHttpSolrServer getCommonsHttpSolrServer(JobConf job) throws MalformedURLException {
HttpClient client=new HttpClient();
// Check for username/password
if (job.getBoolean(SolrConstants.USE_AUTH, false)) {
String username = job.get(SolrConstants.USERNAME);
LOG.info("Authenticating as: " + username);
AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);
client.getState().setCredentials(scope, new UsernamePasswordCredentials(username, job.get(SolrConstants.PASSWORD)));
HttpClientParams params = client.getParams();
params.setAuthenticationPreemptive(true);
client.setParams(params);
}
return new CommonsHttpSolrServer(job.get(SolrConstants.SERVER_URL), client);
}