use of com.apifest.oauth20.bean.Scope in project xian by happyyangyuan.
the class ScopeService method getScopeByName.
public String getScopeByName(String scopeName) throws OAuthException {
String jsonString = null;
Scope scope = DBManagerFactory.getInstance().findScope(scopeName);
if (scope != null) {
try {
jsonString = JSON.toJSONString(scope);
} catch (Exception e) {
LOG.error("cannot load scopes", e);
throw new OAuthException(e, null, HttpResponseStatus.BAD_REQUEST);
}
} else {
throw new OAuthException(SCOPE_NOT_EXIST, HttpResponseStatus.NOT_FOUND);
}
return jsonString;
}
use of com.apifest.oauth20.bean.Scope in project xian by happyyangyuan.
the class OAuth20Handler method handleRegister.
@DocOAuth20Sub(name = "handleRegister", dec = "注册application", method = "POST", url = "/oauth2.0/applications", args = { @DocOAuth20SubIn(name = "name", dec = "application名称", require = true, type = String.class), @DocOAuth20SubIn(name = "scope", dec = "支持由空格分割的多个scope", require = true, type = String.class), @DocOAuth20SubIn(name = "redirect_uri", dec = "redirect_uri", require = true, type = String.class), @DocOAuth20SubIn(name = "client_id", dec = "client_id", require = false, type = String.class), @DocOAuth20SubIn(name = "client_secret", dec = "client_secret", require = false, type = String.class), @DocOAuth20SubIn(name = "description", dec = "用户自定义application描述", require = false, type = String.class), @DocOAuth20SubIn(name = "application_details", dec = "用户自定义的多个键值对", require = false, type = Map.class) })
FullHttpResponse handleRegister(FullHttpRequest req) {
FullHttpResponse response = null;
try {
ClientCredentials creds = auth.issueClientCredentials(req);
String jsonString = JSON.toJSONString(creds);
LOG.info("credentials:" + jsonString);
response = ResponseBuilder.createOkResponse(jsonString);
} catch (OAuthException ex) {
response = ResponseBuilder.createOAuthExceptionResponse(ex);
invokeExceptionHandler(ex, req);
} catch (Exception e1) {
LOG.error("error handle register", e1);
invokeExceptionHandler(e1, req);
}
if (response == null) {
LOG.warn("response is null !", new Throwable());
response = ResponseBuilder.createBadRequestResponse(ResponseBuilder.CANNOT_REGISTER_APP);
}
return response;
}
use of com.apifest.oauth20.bean.Scope in project xian by happyyangyuan.
the class OAuth20Handler method handleGetScope.
@DocOAuth20Sub(name = "handleGetScope", dec = "获取单个scope", method = "GET", url = "/oauth2.0/scopes/{scopeName}", args = { @DocOAuth20SubIn(name = "scope", dec = "scope name", require = true, type = String.class) })
private FullHttpResponse handleGetScope(FullHttpRequest req) {
FullHttpResponse response;
Matcher m = OAUTH_CLIENT_SCOPE_PATTERN.matcher(req.uri());
if (m.find()) {
String scopeName = m.group(1);
ScopeService scopeService = getScopeService();
try {
String responseMsg = scopeService.getScopeByName(scopeName);
response = ResponseBuilder.createOkResponse(responseMsg);
} catch (OAuthException e) {
invokeExceptionHandler(e, req);
response = ResponseBuilder.createResponse(e.getHttpStatus(), e.getMessage());
}
} else {
response = ResponseBuilder.createNotFoundResponse();
}
return response;
}
use of com.apifest.oauth20.bean.Scope in project xian by happyyangyuan.
the class OAuth20Handler method handleAuthorize.
@DocOAuth20Sub(name = "handleAuthorize", dec = "获取code", method = "GET", url = "/oauth2.0/auth-codes", args = { @DocOAuth20SubIn(name = "response_type", dec = "response_type仅支持code类型", require = true, type = String.class), @DocOAuth20SubIn(name = "client_id", dec = "client_id", require = true, type = String.class), @DocOAuth20SubIn(name = "state", dec = "state为用户自定义内容,重定向时会带上该参数", require = false, type = String.class), @DocOAuth20SubIn(name = "redirect_uri", dec = "redirect_uri", require = true, type = String.class), @DocOAuth20SubIn(name = "user_id", dec = "用户自定义值", require = false, type = String.class), @DocOAuth20SubIn(name = "scope", dec = "支持由空格分割的多个scope", require = true, type = String.class) })
private FullHttpResponse handleAuthorize(FullHttpRequest req) {
FullHttpResponse response;
try {
String redirectURI = auth.issueAuthorizationCode(req);
// TODO: validation http protocol?
LOG.info(String.format("redirectURI: %s", redirectURI));
// return auth_code
response = ResponseBuilder.createOkResponse(new JSONObject() {
{
put("redirect_uri", redirectURI);
}
}.toString());
/*accessTokensLog.info("authCode " + response.content().toString(CharsetUtil.UTF_8));*/
} catch (OAuthException ex) {
response = ResponseBuilder.createOAuthExceptionResponse(ex);
invokeExceptionHandler(ex, req);
}
return response;
}
use of com.apifest.oauth20.bean.Scope in project xian by happyyangyuan.
the class OAuth20Handler method handleDeleteScope.
@DocOAuth20Sub(name = "handleDeleteScope", dec = "删除单个scope", method = "DELETE", url = "/oauth2.0/scopes/{scopeName}", args = { @DocOAuth20SubIn(name = "scope", dec = "scope name", require = true, type = String.class) })
FullHttpResponse handleDeleteScope(FullHttpRequest req) {
FullHttpResponse response;
Matcher m = OAUTH_CLIENT_SCOPE_PATTERN.matcher(req.uri());
if (m.find()) {
String scopeName = m.group(1);
ScopeService scopeService = getScopeService();
try {
String responseMsg = scopeService.deleteScope(scopeName);
response = ResponseBuilder.createOkResponse(responseMsg);
} catch (OAuthException e) {
invokeExceptionHandler(e, req);
response = ResponseBuilder.createResponse(e.getHttpStatus(), e.getMessage());
}
} else {
response = ResponseBuilder.createNotFoundResponse();
}
return response;
}
Aggregations