use of org.xdi.oxauth.model.uma.persistence.ScopeDescription in project oxAuth by GluuFederation.
the class ScopeWS method getScopeDescription.
@GET
@Path("{id}")
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
public Response getScopeDescription(@PathParam("id") String id) {
log.trace("UMA - get scope description: id: {}", id);
try {
if (StringUtils.isNotBlank(id)) {
final ScopeDescription scope = umaScopeService.getInternalScope(id);
if (scope != null) {
final org.xdi.oxauth.model.uma.ScopeDescription jsonScope = new org.xdi.oxauth.model.uma.ScopeDescription();
jsonScope.setIconUri(scope.getIconUrl());
jsonScope.setName(scope.getDisplayName());
return Response.status(Response.Status.OK).entity(ServerUtil.asJson(jsonScope)).build();
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.SERVER_ERROR)).build());
}
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.NOT_FOUND)).build());
}
use of org.xdi.oxauth.model.uma.persistence.ScopeDescription in project oxAuth by GluuFederation.
the class ScopeService method getInternalScope.
public ScopeDescription getInternalScope(String p_scopeId) {
try {
final Filter filter = Filter.create(String.format("&(oxType=%s)(oxId=%s)", UmaScopeType.INTERNAL.getValue(), p_scopeId));
final List<ScopeDescription> entries = ldapEntryManager.findEntries(baseDn(), ScopeDescription.class, filter);
if (entries != null && !entries.isEmpty()) {
// if more then one scope then it's problem, non-deterministic behavior, id must be unique
if (entries.size() > 1) {
log.error("Found more then one internal uma scope by input id: {}" + p_scopeId);
for (ScopeDescription s : entries) {
log.error("Scope, Id: {}, dn: {}", s.getId(), s.getDn());
}
}
return entries.get(0);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}
use of org.xdi.oxauth.model.uma.persistence.ScopeDescription in project oxAuth by GluuFederation.
the class ScopeService method handleInternalScopes.
private List<String> handleInternalScopes(List<String> p_scopeUrls, List<String> result) {
List<String> notProcessedScopeUrls = new ArrayList<String>(p_scopeUrls);
try {
final Filter filter = Filter.create(String.format("&(oxType=%s)", InternalExternal.INTERNAL.getValue()));
final List<ScopeDescription> entries = ldapEntryManager.findEntries(baseDn(), ScopeDescription.class, filter);
if (entries != null && !entries.isEmpty()) {
for (String scopeUrl : p_scopeUrls) {
for (ScopeDescription scopeDescription : entries) {
final String internalScopeUrl = getInternalScopeUrl(scopeDescription);
if (internalScopeUrl.equals(scopeUrl) && !result.contains(internalScopeUrl)) {
result.add(scopeDescription.getDn());
notProcessedScopeUrls.remove(scopeUrl);
}
}
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return notProcessedScopeUrls;
}
use of org.xdi.oxauth.model.uma.persistence.ScopeDescription in project oxAuth by GluuFederation.
the class ScopeService method getScopesByUrls.
public List<ScopeDescription> getScopesByUrls(List<String> p_scopeUrls) {
List<ScopeDescription> scopes = new ArrayList<ScopeDescription>();
try {
// external scopes
Filter filter = createAnyFilterByUrls(p_scopeUrls);
if (filter != null) {
final List<ScopeDescription> entries = ldapEntryManager.findEntries(baseDn(), ScopeDescription.class, filter);
if (entries != null) {
scopes.addAll(entries);
}
}
// internal scopes
filter = Filter.create(String.format("&(oxType=%s)", InternalExternal.INTERNAL.getValue()));
final List<ScopeDescription> entries = ldapEntryManager.findEntries(baseDn(), ScopeDescription.class, filter);
if (entries != null && !entries.isEmpty()) {
for (String scopeUrl : p_scopeUrls) {
for (ScopeDescription scopeDescription : entries) {
final String internalScopeUrl = getInternalScopeUrl(scopeDescription);
if (internalScopeUrl.equals(scopeUrl) && !scopes.contains(internalScopeUrl)) {
scopes.add(scopeDescription);
}
}
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return scopes;
}
use of org.xdi.oxauth.model.uma.persistence.ScopeDescription in project oxTrust by GluuFederation.
the class ScopeDescriptionDownloadAction method downloadFile.
public void downloadFile() {
byte[] resultFile = null;
ScopeDescription scopeDescription = getScopeDescription();
if (scopeDescription != null) {
JSONObject jsonObject = new JSONObject();
try {
HashMap<String, List<String>> pageParams = new HashMap<String, List<String>>();
pageParams.put("scope", Arrays.asList(scopeDescription.getId()));
String umaScope = viewHandlerService.getBookmarkableURL("/uma/scope/scopeDescriptionFile.xhtml", pageParams);
jsonObject.put("name", scopeDescription.getId());
jsonObject.put("icon_uri", umaScope);
resultFile = jsonObject.toString().getBytes("UTF-8");
} catch (Exception ex) {
log.error("Failed to generate json response", ex);
}
}
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
if (resultFile == null) {
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
FileDownloader.sendError(response, "Failed to generate json file");
} else {
ContentDisposition contentDisposition = download ? ContentDisposition.ATTACHEMENT : ContentDisposition.NONE;
ResponseHelper.downloadFile(scopeDescription.getId() + ".json", "application/json;charset=UTF-8", resultFile, contentDisposition, facesContext);
}
}
Aggregations