use of com.apifest.oauth20.bean.Scope 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);
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);
if (ok) {
responseMsg = SCOPE_DELETED_OK_MESSAGE;
} else {
responseMsg = SCOPE_DELETED_NOK_MESSAGE;
}
}
}
return responseMsg;
}
use of com.apifest.oauth20.bean.Scope in project xian by happyyangyuan.
the class IssueAccessToken method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
JSONObject json = new JSONObject() {
{
put("client_id", msg.getString("appId"));
put("client_secret", msg.getString("appSecret"));
put("grant_type", "client_credentials");
}
};
String body = json.toJSONString(), uri = msg.getString("$url");
ByteBuf byteBuffer = Unpooled.wrappedBuffer(body.getBytes());
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri, byteBuffer);
try {
AccessToken token = OAuthService.auth.issueAccessToken(request);
return UnitResponse.success(new JSONObject() {
{
put("appId", msg.getString("appId"));
put("accessToken", token.getToken());
put("valid", token.isValid());
put("expiresIn", token.getExpiresIn());
put("created", token.getCreated());
put("scope", token.getScope());
}
});
} catch (OAuthException e) {
return UnitResponse.exception(e);
}
}
Aggregations