本文整理汇总了Java中net.oauth.OAuthMessage.getAuthorizationHeader方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthMessage.getAuthorizationHeader方法的具体用法?Java OAuthMessage.getAuthorizationHeader怎么用?Java OAuthMessage.getAuthorizationHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.oauth.OAuthMessage
的用法示例。
在下文中一共展示了OAuthMessage.getAuthorizationHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticate
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
public Header authenticate(Credentials credentials, HttpRequest request)
throws AuthenticationException {
String uri;
String method;
HttpUriRequest uriRequest = getHttpUriRequest(request);
if (uriRequest != null) {
uri = uriRequest.getURI().toString();
method = uriRequest.getMethod();
} else {
// Some requests don't include the server name in the URL.
RequestLine requestLine = request.getRequestLine();
uri = requestLine.getUri();
method = requestLine.getMethod();
}
try {
OAuthMessage message = new OAuthMessage(method, uri, null);
OAuthAccessor accessor = getAccessor(credentials);
message.addRequiredParameters(accessor);
String authorization = message.getAuthorizationHeader(getRealm());
return new BasicHeader("Authorization", authorization);
} catch (Exception e) {
throw new AuthenticationException(null, e);
}
}
示例2: authenticate
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
public Header authenticate(Credentials credentials, HttpRequest request) throws AuthenticationException {
String uri;
String method;
HttpUriRequest uriRequest = getHttpUriRequest(request);
if (uriRequest != null) {
uri = uriRequest.getURI().toString();
method = uriRequest.getMethod();
} else {
// Some requests don't include the server name in the URL.
RequestLine requestLine = request.getRequestLine();
uri = requestLine.getUri();
method = requestLine.getMethod();
}
try {
OAuthMessage message = new OAuthMessage(method, uri, null);
OAuthAccessor accessor = getAccessor(credentials);
message.addRequiredParameters(accessor);
String authorization = message.getAuthorizationHeader(getRealm());
return new BasicHeader("Authorization", authorization);
} catch (Exception e) {
throw new AuthenticationException(null, e);
}
}
示例3: synchronizeMoodleExtSiteMemberships
import net.oauth.OAuthMessage; //导入方法依赖的package包/类
private final void synchronizeMoodleExtSiteMemberships(final Site site, final String membershipsId, final String membershipsUrl, final String oauth_consumer_key, boolean isEmailTrustedConsumer) {
// Lookup the secret
final String configPrefix = "basiclti.provider." + oauth_consumer_key + ".";
final String oauth_secret = serverConfigurationService.getString(configPrefix+ "secret", null);
if (oauth_secret == null) {
log.error("launch.key.notfound {}. This site's memberships will NOT be synchronised.", oauth_consumer_key);
return;
}
String type = "readMembershipsWithGroups";
String uuid = UUID.randomUUID().toString();
String xml = "<sourcedId>" + membershipsId + "</sourcedId>";
StringBuilder sb = new StringBuilder("<?xml version = \"1.0\" encoding = \"UTF-8\"?>");
sb.append("<imsx_POXEnvelope xmlns = \"http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0\">");
sb.append("<imsx_POXHeader>");
sb.append("<imsx_POXRequestHeaderInfo>");
sb.append("<imsx_version>V1.0</imsx_version>");
sb.append("<imsx_messageIdentifier>" + uuid + "</imsx_messageIdentifier>");
sb.append("</imsx_POXRequestHeaderInfo>");
sb.append("</imsx_POXHeader>");
sb.append("<imsx_POXBody>");
sb.append("<" + type + "Request>");
sb.append(xml);
sb.append("</" + type + "Request>");
sb.append("</imsx_POXBody>");
sb.append("</imsx_POXEnvelope>");
String callXml = sb.toString();
if(log.isDebugEnabled()) log.debug("callXml: {}", callXml);
String bodyHash = OAuthSignatureMethod.base64Encode(LegacyShaUtil.sha1(callXml));
log.debug(bodyHash);
OAuthMessage om = new OAuthMessage("POST", membershipsUrl, null);
om.addParameter("oauth_body_hash", bodyHash);
om.addParameter("oauth_consumer_key", oauth_consumer_key);
om.addParameter("oauth_signature_method", "HMAC-SHA1");
om.addParameter("oauth_version", "1.0");
om.addParameter("oauth_timestamp", new Long(new Date().getTime()).toString());
OAuthConsumer oc = new OAuthConsumer(null, oauth_consumer_key, oauth_secret, null);
try {
OAuthSignatureMethod osm = OAuthSignatureMethod.newMethod("HMAC-SHA1",new OAuthAccessor(oc));
osm.sign(om);
String authzHeader = om.getAuthorizationHeader(null);
if(log.isDebugEnabled()) log.debug("AUTHZ HEADER: {}", authzHeader);
URL url = new URL(membershipsUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Authorization", authzHeader);
connection.setRequestProperty("Content-Length", "" + Integer.toString(callXml.getBytes().length));
connection.setRequestProperty("Content-Type", "text/xml");
connection.setUseCaches (false);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
bw.write(callXml);
bw.flush();
bw.close();
processMembershipsResponse(connection, site, oauth_consumer_key, isEmailTrustedConsumer);
} catch (Exception e) {
log.warn("Problem synchronizing Mooodle memberships.", e);
}
}