Search in sources :

Example 11 with NotFoundException

use of org.wso2.charon3.core.exceptions.NotFoundException in project OpenAM by OpenRock.

the class AuthorizationRequestEndpoint method isEntitled.

private boolean isEntitled(UmaProviderSettings umaProviderSettings, OAuth2ProviderSettings oauth2ProviderSettings, PermissionTicket permissionTicket, String requestingPartyId) throws EntitlementException, ServerException, UmaException {
    String realm = permissionTicket.getRealm();
    String resourceSetId = permissionTicket.getResourceSetId();
    String resourceName = UmaConstants.UMA_POLICY_SCHEME;
    Subject resourceOwnerSubject;
    try {
        ResourceSetStore store = oauth2ProviderSettings.getResourceSetStore();
        Set<ResourceSetDescription> results = store.query(QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_SET_ID, resourceSetId));
        if (results.size() != 1) {
            throw new NotFoundException("Could not find Resource Set, " + resourceSetId);
        }
        resourceName += results.iterator().next().getId();
        resourceOwnerSubject = UmaUtils.createSubject(createIdentity(results.iterator().next().getResourceOwnerId(), realm));
    } catch (NotFoundException e) {
        debug.message("Couldn't find resource that permission ticket is registered for", e);
        throw new ServerException("Couldn't find resource that permission ticket is registered for");
    }
    Subject requestingPartySubject = UmaUtils.createSubject(createIdentity(requestingPartyId, realm));
    beforeAuthorization(permissionTicket, requestingPartySubject, resourceOwnerSubject);
    // Implicitly grant access to the resource owner
    if (isRequestingPartyResourceOwner(requestingPartySubject, resourceOwnerSubject)) {
        afterAuthorization(true, permissionTicket, requestingPartySubject, resourceOwnerSubject);
        return true;
    }
    List<Entitlement> entitlements = umaProviderSettings.getPolicyEvaluator(requestingPartySubject, permissionTicket.getResourceServerClientId().toLowerCase()).evaluate(realm, requestingPartySubject, resourceName, null, false);
    Set<String> requestedScopes = permissionTicket.getScopes();
    Set<String> requiredScopes = new HashSet<>(requestedScopes);
    for (Entitlement entitlement : entitlements) {
        for (String requestedScope : requestedScopes) {
            final Boolean actionValue = entitlement.getActionValue(requestedScope);
            if (actionValue != null && actionValue) {
                requiredScopes.remove(requestedScope);
            }
        }
    }
    boolean isAuthorized = requiredScopes.isEmpty();
    afterAuthorization(isAuthorized, permissionTicket, requestingPartySubject, resourceOwnerSubject);
    return isAuthorized;
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Subject(javax.security.auth.Subject) ResourceSetStore(org.forgerock.oauth2.resources.ResourceSetStore) Entitlement(com.sun.identity.entitlement.Entitlement) HashSet(java.util.HashSet)

Example 12 with NotFoundException

use of org.wso2.charon3.core.exceptions.NotFoundException in project OpenAM by OpenRock.

the class OpenIDConnectProviderDiscovery method discover.

/**
     * Returns the response to a request to discover the OpenId Connect provider.
     *
     * @param resource The resource.
     * @param rel The rel.
     * @param deploymentUrl The deployment url of the OpenId Connect provider.
     * @param request The OAuth2 request.
     * @return A {@code Map} of the OpenId Connect provider urls.
     * @throws BadRequestException If the request is malformed.
     * @throws NotFoundException If the user cannot be found.
     */
public Map<String, Object> discover(String resource, String rel, String deploymentUrl, OAuth2Request request) throws BadRequestException, NotFoundException {
    if (resource == null || resource.isEmpty()) {
        logger.error("No resource provided in discovery.");
        throw new BadRequestException("No resource provided in discovery.");
    }
    if (rel == null || rel.isEmpty() || !rel.equalsIgnoreCase("http://openid.net/specs/connect/1.0/issuer")) {
        logger.error("No or invalid rel provided in discovery.");
        throw new BadRequestException("No or invalid rel provided in discovery.");
    }
    String userid = null;
    //test if the resource is a uri
    try {
        final URI object = new URI(resource);
        if (object.getScheme().equalsIgnoreCase("https") || object.getScheme().equalsIgnoreCase("http")) {
            //resource is of the form of https://example.com/
            if (!object.getPath().isEmpty()) {
                //resource is of the form of https://example.com/joe
                userid = object.getPath();
                userid = userid.substring(1, userid.length());
            }
        } else if (object.getScheme().equalsIgnoreCase("acct")) {
            //resource is not uri so only option is it is an email of form acct:joe@example.com
            String s = new String(resource);
            s = s.replaceFirst("acct:", "");
            final int firstAt = s.indexOf('@');
            userid = s.substring(0, firstAt);
        } else {
            logger.error("Invalid parameters.");
            throw new BadRequestException("Invalid parameters.");
        }
    } catch (Exception e) {
        logger.error("Invalid parameters.", e);
        throw new BadRequestException("Invalid parameters.");
    }
    if (userid != null) {
        if (!openIDConnectProvider.isUserValid(userid, request)) {
            logger.error("Invalid parameters.");
            throw new NotFoundException("Invalid parameters.");
        }
    }
    final Map<String, Object> response = new HashMap<String, Object>();
    response.put("subject", resource);
    final Set<Object> set = new HashSet<Object>();
    final Map<String, Object> objectMap = new HashMap<String, Object>();
    objectMap.put("rel", rel);
    objectMap.put("href", deploymentUrl + "/oauth2");
    set.add(objectMap);
    response.put("links", set);
    return response;
}
Also used : HashMap(java.util.HashMap) BadRequestException(org.forgerock.oauth2.core.exceptions.BadRequestException) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) URI(java.net.URI) BadRequestException(org.forgerock.oauth2.core.exceptions.BadRequestException) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) HashSet(java.util.HashSet)

Example 13 with NotFoundException

use of org.wso2.charon3.core.exceptions.NotFoundException in project siddhi by wso2.

the class SiddhiApiServiceImpl method siddhiArtifactUndeploySiddhiAppGet.

@Override
public Response siddhiArtifactUndeploySiddhiAppGet(String siddhiAppName) throws NotFoundException {
    String jsonString = new Gson().toString();
    if (siddhiAppName != null) {
        if (siddhiAppRunTimeMap.containsKey(siddhiAppName)) {
            siddhiAppRunTimeMap.remove(siddhiAppName);
            siddhiAppConfigurationMap.remove(siddhiAppName);
            siddhiAppSpecificInputHandlerMap.remove(siddhiAppName);
            jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.OK, "Siddhi app removed successfully"));
        } else {
            jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.ERROR, "There is no siddhi app exist " + "with provided name : " + siddhiAppName));
        }
    } else {
        jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.ERROR, "nvalid Request"));
    }
    return Response.ok().entity(jsonString).build();
}
Also used : ApiResponseMessage(org.wso2.siddhi.service.api.ApiResponseMessage) Gson(com.google.gson.Gson)

Example 14 with NotFoundException

use of org.wso2.charon3.core.exceptions.NotFoundException in project siddhi by wso2.

the class SiddhiApiServiceImpl method siddhiArtifactDeployPost.

@Override
public Response siddhiArtifactDeployPost(String siddhiApp) throws NotFoundException {
    log.info("SiddhiApp = " + siddhiApp);
    String jsonString = new Gson().toString();
    try {
        SiddhiApp parsedSiddhiApp = SiddhiCompiler.parse(siddhiApp);
        String siddhiAppName = AnnotationHelper.getAnnotationElement(SiddhiServiceConstants.ANNOTATION_NAME_NAME, null, parsedSiddhiApp.getAnnotations()).getValue();
        if (!siddhiAppRunTimeMap.containsKey(siddhiApp)) {
            SiddhiAppConfiguration siddhiAppConfiguration = new SiddhiAppConfiguration();
            siddhiAppConfiguration.setName(siddhiAppName);
            siddhiAppConfigurationMap.put(siddhiAppName, siddhiAppConfiguration);
            SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
            if (siddhiAppRuntime != null) {
                Set<String> streamNames = siddhiAppRuntime.getStreamDefinitionMap().keySet();
                Map<String, InputHandler> inputHandlerMap = new ConcurrentHashMap<>(streamNames.size());
                for (String streamName : streamNames) {
                    inputHandlerMap.put(streamName, siddhiAppRuntime.getInputHandler(streamName));
                }
                siddhiAppSpecificInputHandlerMap.put(siddhiAppName, inputHandlerMap);
                siddhiAppRunTimeMap.put(siddhiAppName, siddhiAppRuntime);
                siddhiAppRuntime.start();
                jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.OK, "Siddhi app is deployed " + "and runtime is created"));
            }
        } else {
            jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.ERROR, "There is a Siddhi app already " + "exists with same name"));
        }
    } catch (Exception e) {
        jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.ERROR, e.getMessage()));
    }
    return Response.ok().entity(jsonString).build();
}
Also used : ApiResponseMessage(org.wso2.siddhi.service.api.ApiResponseMessage) InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) Gson(com.google.gson.Gson) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiAppConfiguration(org.wso2.siddhi.service.util.SiddhiAppConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NotFoundException(org.wso2.siddhi.service.api.NotFoundException)

Example 15 with NotFoundException

use of org.wso2.charon3.core.exceptions.NotFoundException in project siddhi by wso2.

the class SiddhiApiTestCase method testDeployAndUndeploy.

@Test
public /**
 * Check deploy and undeploy functionality
 */
void testDeployAndUndeploy() throws NotFoundException {
    SiddhiApiServiceImpl apiService = new SiddhiApiServiceImpl();
    String siddhiApp = "@app:name('filterTest1') " + "" + "define stream cseEventStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from cseEventStream[70 > price] " + "select symbol, price " + "insert into outputStream;" + "" + "@info(name = 'query2') " + "from outputStream[70 > price] " + "select symbol, price " + "insert into outputStream2 ;";
    Response response = apiService.siddhiArtifactDeployPost(siddhiApp);
    Assert.assertEquals(response.getStatus(), 200, "HTTP 200 should be returned");
    Assert.assertTrue(response.getEntity().toString().contains("Siddhi app is deployed and runtime is created"), "Siddhi App creation message should be returned");
    Response undeployResponse = apiService.siddhiArtifactUndeploySiddhiAppGet("filterTest1");
    Assert.assertEquals(undeployResponse.getStatus(), 200, "HTTP 200 should be returned");
    Assert.assertTrue(undeployResponse.getEntity().toString().contains("Siddhi app removed successfully"), "Siddhi App removed message should be returned");
}
Also used : Response(javax.ws.rs.core.Response) SiddhiApiServiceImpl(org.wso2.siddhi.service.impl.SiddhiApiServiceImpl) Test(org.testng.annotations.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)171 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)144 HashMap (java.util.HashMap)121 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)120 Response (javax.ws.rs.core.Response)106 Test (org.junit.Test)100 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)99 Request (org.wso2.msf4j.Request)75 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)48 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)44 ArrayList (java.util.ArrayList)36 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)31 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)29 Map (java.util.Map)25 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)25 NotFoundException (org.forgerock.oauth2.core.exceptions.NotFoundException)24 ApplicationCreationResponse (org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse)23 PoliciesApiServiceImpl (org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl)20 Application (org.wso2.carbon.apimgt.core.models.Application)19 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)18