use of com.apifest.oauth20.bean.ApplicationInfo in project xian by happyyangyuan.
the class OAuth20Handler method filterClientApps.
List<ApplicationInfo> filterClientApps(FullHttpRequest req, List<ApplicationInfo> apps) {
List<ApplicationInfo> filteredApps = new ArrayList<>();
QueryStringDecoder dec = new QueryStringDecoder(req.uri());
Map<String, List<String>> params = dec.parameters();
if (params != null) {
String status = QueryParameter.getFirstElement(params, "status");
Integer statusInt;
if (status != null && !status.isEmpty()) {
try {
statusInt = Integer.valueOf(status);
for (ApplicationInfo app : apps) {
if (Objects.equals(app.getStatus(), statusInt)) {
filteredApps.add(app);
}
}
} catch (NumberFormatException e) {
// status is invalid, ignore it
filteredApps = Collections.unmodifiableList(apps);
}
} else {
filteredApps = Collections.unmodifiableList(apps);
}
}
return filteredApps;
}
use of com.apifest.oauth20.bean.ApplicationInfo in project xian by happyyangyuan.
the class ScopeService method getClientAppsByScope.
protected List<ApplicationInfo> getClientAppsByScope(String scopeName) {
List<ApplicationInfo> scopeApps = new ArrayList<>();
List<ApplicationInfo> allApps = DBManagerFactory.getInstance().getAllApplications().blockingGet();
for (ApplicationInfo app : allApps) {
if (app.getScope() != null && app.getScope().contains(scopeName)) {
scopeApps.add(app);
break;
}
}
return scopeApps;
}
use of com.apifest.oauth20.bean.ApplicationInfo 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).blockingGet();
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 com.apifest.oauth20.bean.ApplicationInfo in project xian by happyyangyuan.
the class ScopeService method deleteScope.
/**
* Deletes a scope. If the scope does not exists, returns an error.
*
* @param scopeName scopeName
* @return String message that will be returned in the response
*/
public String deleteScope(String scopeName) throws OAuthException {
String responseMsg;
Scope foundScope = DBManagerFactory.getInstance().findScope(scopeName).blockingGet();
if (foundScope == null) {
LOG.error("scope does not exist");
throw new OAuthException(SCOPE_NOT_EXIST, HttpResponseStatus.BAD_REQUEST);
} else {
// first, check whether there is a client app registered with that scope
List<ApplicationInfo> registeredApps = getClientAppsByScope(scopeName);
if (registeredApps.size() > 0) {
responseMsg = SCOPE_USED_BY_APP_MESSAGE;
} else {
boolean ok = DBManagerFactory.getInstance().deleteScope(scopeName).blockingGet();
if (ok) {
responseMsg = SCOPE_DELETED_OK_MESSAGE;
} else {
responseMsg = SCOPE_DELETED_NOK_MESSAGE;
}
}
}
return responseMsg;
}
use of com.apifest.oauth20.bean.ApplicationInfo in project xian by happyyangyuan.
the class RedisDBManager method getAllApplications.
@Override
public Single<List<ApplicationInfo>> getAllApplications() {
List<ApplicationInfo> list = new ArrayList<>();
return CacheMapUtil.values(CLIENT_CREDENTIALS_KEY).switchIfEmpty(Single.just(new ArrayList<>())).map(values -> {
for (String json : values) {
ClientCredentials credentials = JSON.parseObject(json, ClientCredentials.class);
ApplicationInfo app = ApplicationInfo.loadFromClientCredentials(credentials);
if (app != null) {
list.add(app);
}
}
return list;
});
}
Aggregations