use of info.xiancloud.core.apidoc.annotation.DocOAuth20Sub in project xian by happyyangyuan.
the class OAuth20Handler method invokeExceptionHandler.
@DocOAuth20Sub(name = "invokeExceptionHandler", dec = "触发异常事件监听器的回调方法", method = "", url = "", args = { @DocOAuth20SubIn(name = "req", dec = "HTTP请求封装对象", require = true, type = FullHttpRequest.class) })
private void invokeExceptionHandler(Exception ex, FullHttpRequest request) {
List<Class<? extends ExceptionEventHandler>> handlers = LifecycleEventHandlers.exceptionHandlers;
for (int i = 0; i < handlers.size(); i++) {
try {
ExceptionEventHandler handler = handlers.get(i).newInstance();
handler.handleException(ex, request);
} catch (InstantiationException e) {
throw new RuntimeException("cannot instantiate exception handler", e);
} catch (IllegalAccessException e) {
throw new RuntimeException("cannot invoke exception handler", e);
}
}
}
use of info.xiancloud.core.apidoc.annotation.DocOAuth20Sub 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 info.xiancloud.core.apidoc.annotation.DocOAuth20Sub 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 info.xiancloud.core.apidoc.annotation.DocOAuth20Sub in project xian by happyyangyuan.
the class OAuth20Handler method handleGetClientApplication.
@DocOAuth20Sub(name = "handleGetClientApplication", dec = "获取单个application相关信息", method = "GET", url = "/oauth2.0/applications/{LOCAL_NODE_ID}", args = { @DocOAuth20SubIn(name = "client_id", dec = "client_id", require = true, type = String.class) })
FullHttpResponse handleGetClientApplication(FullHttpRequest req) {
FullHttpResponse response;
Matcher m = APPLICATION_PATTERN.matcher(req.uri());
if (m.find()) {
String clientId = m.group(1);
ApplicationInfo appInfo = auth.getApplicationInfo(clientId);
if (appInfo != null) {
String json = JSON.toJSONString(appInfo);
LOG.debug(json);
response = ResponseBuilder.createOkResponse(json);
} else {
response = ResponseBuilder.createResponse(HttpResponseStatus.NOT_FOUND, ResponseBuilder.CLIENT_APP_NOT_EXIST);
}
} else {
response = ResponseBuilder.createNotFoundResponse();
}
return response;
}
use of info.xiancloud.core.apidoc.annotation.DocOAuth20Sub 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;
}
Aggregations