use of io.jans.as.persistence.model.Scope in project jans by JanssenProject.
the class ScopeService method getScopeByDn.
/**
* returns Scope by Dn
*
* @return Scope
*/
public Scope getScopeByDn(String dn) {
BaseCacheService usedCacheService = getCacheService();
final Scope scope = usedCacheService.getWithPut(dn, () -> ldapEntryManager.find(Scope.class, dn), 60);
if (scope != null && StringUtils.isNotBlank(scope.getId())) {
// put also by id, since we call it by id and dn
usedCacheService.put(scope.getId(), scope);
}
return scope;
}
use of io.jans.as.persistence.model.Scope in project jans by JanssenProject.
the class SpontaneousScopeService method createSpontaneousScopeIfNeeded.
public Scope createSpontaneousScopeIfNeeded(Set<String> regExps, String scopeId, String clientId) {
Scope fromPersistence = scopeService.getScopeById(scopeId);
if (fromPersistence != null) {
// scope already exists
return fromPersistence;
}
final Pair<Boolean, String> isAllowed = isAllowedBySpontaneousScopes(regExps, scopeId);
if (!isAllowed.getFirst()) {
log.error("Forbidden by client. Check client configuration.");
return null;
}
Scope regexpScope = scopeService.getScopeById(isAllowed.getSecond());
Scope scope = new Scope();
scope.setDefaultScope(false);
scope.setDescription("Spontaneous scope: " + scope);
scope.setDisplayName(scopeId);
scope.setId(scopeId);
scope.setInum(UUID.randomUUID().toString());
scope.setScopeType(ScopeType.SPONTANEOUS);
scope.setDeletable(true);
scope.setExpirationDate(new Date(getLifetime()));
scope.setDn("inum=" + scope.getInum() + "," + staticConfiguration.getBaseDn().getScopes());
scope.getAttributes().setSpontaneousClientId(clientId);
scope.getAttributes().setSpontaneousClientScopes(Lists.newArrayList(isAllowed.getSecond()));
scope.setUmaAuthorizationPolicies(regexpScope != null ? regexpScope.getUmaAuthorizationPolicies() : new ArrayList<>());
scopeService.persist(scope);
log.trace("Created spontaneous scope: " + scope.getId() + ", dn: " + scope.getDn());
return scope;
}
use of io.jans.as.persistence.model.Scope in project jans by JanssenProject.
the class UmaScopeIconWS method getScopeDescription.
@GET
@Path("{id}")
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
public Response getScopeDescription(@PathParam("id") String id) {
log.trace("UMA - get scope's icon : id: {}", id);
errorResponseFactory.validateComponentEnabled(ComponentType.UMA);
try {
if (StringUtils.isNotBlank(id)) {
final Scope scope = umaScopeService.getScope(id);
if (scope != null && StringUtils.isNotBlank(scope.getIconUrl())) {
return Response.temporaryRedirect(new URI(scope.getIconUrl())).build();
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
throw errorResponseFactory.createWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, UmaErrorResponseType.SERVER_ERROR, "Internal error.");
}
throw errorResponseFactory.createWebApplicationException(Response.Status.NOT_FOUND, UmaErrorResponseType.NOT_FOUND, "Scope not found.");
}
use of io.jans.as.persistence.model.Scope in project jans by JanssenProject.
the class ScopesResource method patchScope.
@PATCH
@Consumes(MediaType.APPLICATION_JSON_PATCH_JSON)
@ProtectedApi(scopes = { ApiAccessConstants.SCOPES_WRITE_ACCESS })
@Path(ApiConstants.INUM_PATH)
public Response patchScope(@PathParam(ApiConstants.INUM) @NotNull String inum, @NotNull String pathString) throws JsonPatchException, IOException {
log.debug("SCOPES to be patched - inum = " + inum + " , pathString = " + pathString);
Scope existingScope = scopeService.getScopeByInum(inum);
checkResourceNotNull(existingScope, SCOPE);
existingScope = Jackson.applyPatch(pathString, existingScope);
scopeService.updateScope(existingScope);
existingScope = scopeService.getScopeByInum(inum);
log.debug("SCOPE patched is - " + existingScope.getId());
return Response.ok(existingScope).build();
}
use of io.jans.as.persistence.model.Scope in project jans by JanssenProject.
the class RegisterRestWebServiceImpl method clientScopesToString.
private String clientScopesToString(Client client) {
String[] scopeDns = client.getScopes();
if (scopeDns != null) {
String[] scopeNames = new String[scopeDns.length];
for (int i = 0; i < scopeDns.length; i++) {
Scope scope = scopeService.getScopeByDn(scopeDns[i]);
scopeNames[i] = scope.getId();
}
return StringUtils.join(scopeNames, " ");
}
return null;
}
Aggregations