本文整理汇总了Java中org.apache.oltu.oauth2.common.utils.OAuthUtils类的典型用法代码示例。如果您正苦于以下问题:Java OAuthUtils类的具体用法?Java OAuthUtils怎么用?Java OAuthUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OAuthUtils类属于org.apache.oltu.oauth2.common.utils包,在下文中一共展示了OAuthUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: retrieveAccessToken
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
@Override
public AccessToken retrieveAccessToken(ClientDetails clientDetails, Set<String> scopes, boolean includeRefreshToken) throws OAuthSystemException {
String scope = OAuthUtils.encodeScopes(scopes);
final String username = currentUsername();
final String clientId = clientDetails.getClientId();
final String authenticationId = authenticationIdGenerator.generate(clientId, username, scope);
AccessToken accessToken = oauthRepository.findAccessToken(clientId, username, authenticationId);
if (accessToken == null) {
accessToken = createAndSaveAccessToken(clientDetails, includeRefreshToken, username, authenticationId);
LOG.debug("Create a new AccessToken: {}", accessToken);
}
return accessToken;
}
示例2: retrieveNewAccessToken
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
@Override
public AccessToken retrieveNewAccessToken(ClientDetails clientDetails, Set<String> scopes) throws OAuthSystemException {
String scope = OAuthUtils.encodeScopes(scopes);
final String username = currentUsername();
final String clientId = clientDetails.getClientId();
final String authenticationId = authenticationIdGenerator.generate(clientId, username, scope);
AccessToken accessToken = oauthRepository.findAccessToken(clientId, username, authenticationId);
if (accessToken != null) {
LOG.debug("Delete existed AccessToken: {}", accessToken);
oauthRepository.deleteAccessToken(accessToken);
}
accessToken = createAndSaveAccessToken(clientDetails, false, username, authenticationId);
LOG.debug("Create a new AccessToken: {}", accessToken);
return accessToken;
}
示例3: retrieve
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
public AccessToken retrieve() throws OAuthSystemException {
String scope = OAuthUtils.encodeScopes(scopes);
final String clientId = clientDetails.clientId();
//username = clientId
final String authenticationId = authenticationIdGenerator.generate(clientId, clientId, scope);
AccessToken accessToken = oauthRepository.findAccessToken(clientId, clientId, authenticationId);
boolean needCreated = needCreated(clientId, accessToken);
if (needCreated) {
//Ignore refresh_token
accessToken = createAndSaveAccessToken(clientDetails, false, clientId, authenticationId);
LOG.debug("Create a new AccessToken: {}", accessToken);
}
return accessToken;
}
示例4: retrieve
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
public AccessToken retrieve() throws OAuthSystemException {
String scope = OAuthUtils.encodeScopes(scopes);
final String clientId = clientDetails.clientId();
final String authenticationId = authenticationIdGenerator.generate(clientId, username, scope);
AccessToken accessToken = oauthRepository.findAccessToken(clientId, username, authenticationId);
boolean needCreated = needCreated(clientId, accessToken);
if (needCreated) {
accessToken = createAndSaveAccessToken(clientDetails, clientDetails.supportRefreshToken(), username, authenticationId);
LOG.debug("Create a new AccessToken: {}", accessToken);
}
return accessToken;
}
示例5: retrieve
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
public AccessToken retrieve() throws OAuthSystemException {
String scope = OAuthUtils.encodeScopes(scopes);
final String username = currentUsername();
final String clientId = clientDetails.clientId();
final String authenticationId = authenticationIdGenerator.generate(clientId, username, scope);
AccessToken accessToken = oauthRepository.findAccessToken(clientId, username, authenticationId);
if (accessToken == null) {
accessToken = createAndSaveAccessToken(clientDetails, includeRefreshToken, username, authenticationId);
LOG.debug("Create a new AccessToken: {}", accessToken);
}
return accessToken;
}
示例6: preHandle
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
/**
* check client and redirect back with OAuth authorization code
*/
@Override
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
I18N i18n = new I18N(request.getLocale());
if (!SecurityUtils.getSubject().isAuthenticated()) {
throw new IllegalStateException(i18n.getString("NOT_AUTHENTICATED"));
}
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
try {
if (noSavedRequest())
return processOAuthRequest(httpRequest, httpResponse);
else
return processSavedRequest(httpRequest, httpResponse);
} catch (OAuthProblemException ex) {
if (OAuthUtils.isEmpty(ex.getError()))
return ResponseUtils.processResponse(httpResponse, ex.getRedirectUri(),
ResponseUtils.responseInvalidRequest(ex.getDescription()));
return ResponseUtils.processResponse(httpResponse, ex.getRedirectUri(),
ResponseUtils.responseBadRequest(ex));
}
}
示例7: CheckAccessToken
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
protected boolean CheckAccessToken(HttpServletRequest request, HttpServletResponse response)
throws IOException, OAuthSystemException {
try {
String accessToken = new OAuthAccessResourceRequest(request).getAccessToken();
if (oAuthService.checkAccessToken(accessToken, request))
return true;
// because OLTU client not process error in response header
// so still send JSON data back, the client need process this error
I18N i18n = new I18N(request.getLocale());
return ResponseUtils.processResponse(response, null,
ResponseUtils.responseInvalidToken(i18n.getString("INVALID_TOKEN")));
} catch (OAuthProblemException ex) {
if (OAuthUtils.isEmpty(ex.getError()))
return ResponseUtils.processResponse(response, null,
ResponseUtils.responseInvalidRequest(ex.getDescription()));
return ResponseUtils.processResponse(response, null,
OAuthRSResponse.errorResponse(HttpServletResponse.SC_UNAUTHORIZED).error(ex));
}
}
示例8: onAccessDenied
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response)
throws Exception {
String error = request.getParameter(OAuthError.OAUTH_ERROR);
String description = request.getParameter(OAuthError.OAUTH_ERROR_DESCRIPTION);
if (!OAuthUtils.isEmpty(error))
return processAuthorizationError(request, response, error, description);
if (!OAuthUtils.isEmpty(state) && !state.equals(request.getParameter(OAuth.OAUTH_STATE)))
return processAuthorizationError(request, response, OAuthError.CodeResponse.SERVER_ERROR,
"server response state inconsistent with sent state");
Subject subject = getSubject(request, response);
if (!subject.isAuthenticated()) {
if (OAuthUtils.isEmpty(request.getParameter(OAuth.OAUTH_CODE))) {
saveRequestAndRedirectToLogin(request, response);
return false;
}
}
return executeLogin(request, response);
}
示例9: authorize
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
/**
* authorize by URI, the client must be HTTP session authenticated before
* OAuth authorization
*
* @param client
* HTTP client
* @return {@link OAuthClientToken} object
* @throws OAuthSystemException
* If an OAuth system exception occurs
* @throws OAuthProblemException
* If an OAuth problem exception occurs
*/
public OAuthClientToken authorize(CloseableHttpClient client)
throws OAuthSystemException, OAuthProblemException {
try {
CloseableHttpResponse response = client.execute(new HttpGet(getQueryURI()));
try {
String content = EntityUtils.toString(response.getEntity());
OAuthAuthzResponse oAuthResponse = new OAuthAuthzResponse();
oAuthResponse.init(content, null, response.getStatusLine().getStatusCode());
if (!OAuthUtils.isEmpty(state) && !state.equals(oAuthResponse.getState())) {
throw OAuthProblemException.error(OAuthError.CodeResponse.SERVER_ERROR,
"server response state inconsistent with sent state");
}
return OAuthClientToken.authCode(oAuthResponse.getCode(), oAuthResponse.getScopes());
} finally {
response.close();
}
} catch (IOException ex) {
throw new OAuthSystemException(ex);
}
}
示例10: initValidator
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
/**
* Initialize a grant type validator
*
* @return an instance of OAuthValidator
* @throws OAuthProblemException
* @throws OAuthSystemException
*/
@Override
protected OAuthValidator<HttpServletRequest> initValidator() throws OAuthProblemException, OAuthSystemException {
String requestTypeValue = getParam(OAuth.OAUTH_GRANT_TYPE);
if (OAuthUtils.isEmpty(requestTypeValue)) {
throw OAuthUtils.handleOAuthProblemException("Missing grant_type parameter value");
}
Class<? extends OAuthValidator<HttpServletRequest>> clazz = OAuthServerConfiguration
.getInstance().getSupportedGrantTypeValidators().get(requestTypeValue);
if (clazz == null) {
if (log.isDebugEnabled()) {
//Do not change this log format as these logs use by external applications
log.debug("Unsupported Grant Type : " + requestTypeValue +
" for client id : " + getClientId());
}
throw OAuthUtils.handleOAuthProblemException("Invalid grant_type parameter value");
}
return OAuthUtils.instantiateClass(clazz);
}
示例11: initValidator
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
protected OAuthValidator<HttpServletRequest> initValidator() throws OAuthProblemException, OAuthSystemException {
String responseTypeValue = getParam(OAuth.OAUTH_RESPONSE_TYPE);
if (OAuthUtils.isEmpty(responseTypeValue)) {
throw OAuthUtils.handleOAuthProblemException("Missing response_type parameter value");
}
Class<? extends OAuthValidator<HttpServletRequest>> clazz = OAuthServerConfiguration
.getInstance().getSupportedResponseTypeValidators().get(responseTypeValue);
if (clazz == null) {
if (log.isDebugEnabled()) {
//Do not change this log format as these logs use by external applications
log.debug("Unsupported Response Type : " + responseTypeValue +
" for client id : " + getClientId());
}
throw OAuthUtils.handleOAuthProblemException("Invalid response_type parameter value");
}
return OAuthUtils.instantiateClass(clazz);
}
示例12: setRequestBody
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
private void setRequestBody(OAuthClientRequest request, String requestMethod, HttpURLConnection httpURLConnection)
throws IOException {
String requestBody = request.getBody();
if (OAuthUtils.isEmpty(requestBody)) {
return;
}
if (OAuth.HttpMethod.POST.equals(requestMethod) || OAuth.HttpMethod.PUT.equals(requestMethod)) {
httpURLConnection.setDoOutput(true);
OutputStream ost = httpURLConnection.getOutputStream();
PrintWriter pw = new PrintWriter(ost);
pw.print(requestBody);
pw.flush();
pw.close();
}
}
示例13: retrievePasswordAccessToken
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
@Override
public AccessToken retrievePasswordAccessToken(ClientDetails clientDetails, Set<String> scopes, String username) throws OAuthSystemException {
String scope = OAuthUtils.encodeScopes(scopes);
final String clientId = clientDetails.getClientId();
final String authenticationId = authenticationIdGenerator.generate(clientId, username, scope);
AccessToken accessToken = oauthRepository.findAccessToken(clientId, username, authenticationId);
boolean needCreate = false;
if (accessToken == null) {
needCreate = true;
LOG.debug("Not found AccessToken from repository, will create a new one, client_id: {}", clientId);
} else if (accessToken.tokenExpired()) {
LOG.debug("Delete expired AccessToken: {} and create a new one, client_id: {}", accessToken, clientId);
oauthRepository.deleteAccessToken(accessToken);
needCreate = true;
} else {
LOG.debug("Use existed AccessToken: {}, client_id: {}", accessToken, clientId);
}
if (needCreate) {
accessToken = createAndSaveAccessToken(clientDetails, clientDetails.supportRefreshToken(), username, authenticationId);
LOG.debug("Create a new AccessToken: {}", accessToken);
}
return accessToken;
}
示例14: retrieveClientCredentialsAccessToken
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
@Override
public AccessToken retrieveClientCredentialsAccessToken(ClientDetails clientDetails, Set<String> scopes) throws OAuthSystemException {
String scope = OAuthUtils.encodeScopes(scopes);
final String clientId = clientDetails.getClientId();
//username = clientId
final String authenticationId = authenticationIdGenerator.generate(clientId, clientId, scope);
AccessToken accessToken = oauthRepository.findAccessToken(clientId, clientId, authenticationId);
boolean needCreate = false;
if (accessToken == null) {
needCreate = true;
LOG.debug("Not found AccessToken from repository, will create a new one, client_id: {}", clientId);
} else if (accessToken.tokenExpired()) {
LOG.debug("Delete expired AccessToken: {} and create a new one, client_id: {}", accessToken, clientId);
oauthRepository.deleteAccessToken(accessToken);
needCreate = true;
} else {
LOG.debug("Use existed AccessToken: {}, client_id: {}", accessToken, clientId);
}
if (needCreate) {
//Ignore refresh_token
accessToken = createAndSaveAccessToken(clientDetails, false, clientId, authenticationId);
LOG.debug("Create a new AccessToken: {}", accessToken);
}
return accessToken;
}
示例15: generate
import org.apache.oltu.oauth2.common.utils.OAuthUtils; //导入依赖的package包/类
public String generate(String clientId, String username, String scope) {
Map<String, String> map = new HashMap<>();
map.put(OAuth.OAUTH_CLIENT_ID, clientId);
//check it is client only
if (!clientId.equals(username)) {
map.put(OAuth.OAUTH_USERNAME, username);
}
if (!OAuthUtils.isEmpty(scope)) {
map.put(OAuth.OAUTH_SCOPE, scope);
}
return digest(map);
}