Search in sources :

Example 1 with PolicySearch

use of org.wso2.carbon.identity.entitlement.policy.search.PolicySearch in project carbon-identity-framework by wso2.

the class DecisionResource method getAllEntitlements.

/**
 * API endpoint for returning all entitlements for a given set of parameters
 *
 * @return AllEntitlementResponseModel object
 */
@POST
@Path("entitlements-all")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "Get all entitlements for a given set of parameters", response = AllEntitlementsResponseModel.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "All Entitlements response", response = AllEntitlementsResponseModel.class), @ApiResponse(code = 40010, message = EntitlementEndpointConstants.ERROR_UNAUTHORIZED_MESSAGE, response = ExceptionBean.class), @ApiResponse(code = 40020, message = EntitlementEndpointConstants.ERROR_REQUEST_PARSE_MESSAGE, response = ExceptionBean.class), @ApiResponse(code = 40010, message = EntitlementEndpointConstants.ERROR_RESPONSE_READ_MESSAGE, response = ExceptionBean.class) })
public AllEntitlementsResponseModel getAllEntitlements(@ApiParam(value = "Request Media Type", required = true) @HeaderParam(EntitlementEndpointConstants.ACCEPT_HEADER) String format, @ApiParam(value = "Authentication Type", required = true) @HeaderParam(EntitlementEndpointConstants.AUTHENTICATION_TYPE_HEADER) String authMechanism, @ApiParam(value = "Add HTTP Basic Authorization", required = true) @HeaderParam(EntitlementEndpointConstants.AUTHORIZATION_HEADER) String authorization, @ApiParam(value = "Response Media Type", required = true) @HeaderParam(EntitlementEndpointConstants.CONTENT_TYPE_HEADER) String contentType, @ApiParam(value = "All Entitlements Model", required = true) AllEntitlementsRequestModel request) {
    PolicySearch policySearch = EntitlementEngine.getInstance().getPolicySearch();
    EntitledResultSetDTO resultSet = policySearch.getEntitledAttributes(request.getIdentifier(), request.getGivenAttributes());
    AllEntitlementsResponseModel response = new AllEntitlementsResponseModel();
    response.setEntitledResultSetDTO(resultSet);
    return response;
}
Also used : AllEntitlementsResponseModel(org.wso2.carbon.identity.entitlement.endpoint.resources.models.AllEntitlementsResponseModel) PolicySearch(org.wso2.carbon.identity.entitlement.policy.search.PolicySearch) EntitledResultSetDTO(org.wso2.carbon.identity.entitlement.dto.EntitledResultSetDTO) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with PolicySearch

use of org.wso2.carbon.identity.entitlement.policy.search.PolicySearch in project carbon-identity-framework by wso2.

the class DecisionResource method getEntitledAttributes.

/**
 * API endpoint for returning entitled attributes for a give set of parameters
 *
 * @return EntitledAttributesResponse object
 */
@POST
@Path("entitled-attribs")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "Get entitled attributes for a given set of parameters", response = EntitledAttributesResponseModel.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Entitled Attributes response", response = EntitledAttributesResponseModel.class), @ApiResponse(code = 40010, message = EntitlementEndpointConstants.ERROR_UNAUTHORIZED_MESSAGE, response = ExceptionBean.class), @ApiResponse(code = 40020, message = EntitlementEndpointConstants.ERROR_REQUEST_PARSE_MESSAGE, response = ExceptionBean.class), @ApiResponse(code = 40010, message = EntitlementEndpointConstants.ERROR_RESPONSE_READ_MESSAGE, response = ExceptionBean.class) })
public EntitledAttributesResponseModel getEntitledAttributes(@ApiParam(value = "Request Media Type", required = true) @HeaderParam(EntitlementEndpointConstants.ACCEPT_HEADER) String format, @ApiParam(value = "Authentication Type", required = true) @HeaderParam(EntitlementEndpointConstants.AUTHENTICATION_TYPE_HEADER) String authMechanism, @ApiParam(value = "Add HTTP Basic Authorization", required = true) @HeaderParam(EntitlementEndpointConstants.AUTHORIZATION_HEADER) String authorization, @ApiParam(value = "Response Media Type", required = true) @HeaderParam(EntitlementEndpointConstants.CONTENT_TYPE_HEADER) String contentType, @ApiParam(value = "Entitled Attributes Model", required = true) EntitledAttributesRequestModel request) throws Exception {
    if (request.getSubjectName() == null) {
        log.error("Invalid input data - either the user name or role name should be non-null");
        throw new RequestParseException(40022, "Invalid input data - either the user name or role name should be non-null");
    }
    PolicySearch policySearch = EntitlementEngine.getInstance().getPolicySearch();
    EntitledResultSetDTO resultsSet = policySearch.getEntitledAttributes(request.getSubjectName(), request.getResourceName(), request.getSubjectId(), request.getAction(), request.isEnableChildSearch());
    EntitledAttributesResponseModel response = new EntitledAttributesResponseModel();
    response.setEntitledResultSetDTO(resultsSet);
    return response;
}
Also used : RequestParseException(org.wso2.carbon.identity.entitlement.endpoint.exception.RequestParseException) EntitledAttributesResponseModel(org.wso2.carbon.identity.entitlement.endpoint.resources.models.EntitledAttributesResponseModel) PolicySearch(org.wso2.carbon.identity.entitlement.policy.search.PolicySearch) EntitledResultSetDTO(org.wso2.carbon.identity.entitlement.dto.EntitledResultSetDTO) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 EntitledResultSetDTO (org.wso2.carbon.identity.entitlement.dto.EntitledResultSetDTO)2 PolicySearch (org.wso2.carbon.identity.entitlement.policy.search.PolicySearch)2 RequestParseException (org.wso2.carbon.identity.entitlement.endpoint.exception.RequestParseException)1 AllEntitlementsResponseModel (org.wso2.carbon.identity.entitlement.endpoint.resources.models.AllEntitlementsResponseModel)1 EntitledAttributesResponseModel (org.wso2.carbon.identity.entitlement.endpoint.resources.models.EntitledAttributesResponseModel)1