Search in sources :

Example 1 with Scope

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;
}
Also used : Scope(io.jans.as.persistence.model.Scope) BaseCacheService(io.jans.service.BaseCacheService)

Example 2 with 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;
}
Also used : Scope(io.jans.as.persistence.model.Scope) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 3 with 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.");
}
Also used : Scope(io.jans.as.persistence.model.Scope) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with Scope

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();
}
Also used : Scope(io.jans.as.persistence.model.Scope) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Example 5 with Scope

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;
}
Also used : Scope(io.jans.as.persistence.model.Scope)

Aggregations

Scope (io.jans.as.persistence.model.Scope)41 ArrayList (java.util.ArrayList)10 User (io.jans.as.common.model.common.User)8 GluuAttribute (io.jans.model.GluuAttribute)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Test (org.testng.annotations.Test)7 Date (java.util.Date)6 JSONObject (org.json.JSONObject)6 ProtectedApi (io.jans.configapi.core.rest.ProtectedApi)5 HashSet (java.util.HashSet)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 UmaPermission (io.jans.as.model.uma.persistence.UmaPermission)3 UmaScriptByScope (io.jans.as.server.uma.authorization.UmaScriptByScope)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 JSONArray (org.json.JSONArray)3 Client (io.jans.as.common.model.registration.Client)2 JwtSubClaimObject (io.jans.as.model.jwt.JwtSubClaimObject)2 UnmodifiableAuthorizationGrant (io.jans.as.server.model.common.UnmodifiableAuthorizationGrant)2