Search in sources :

Example 16 with EntitlementException

use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.

the class CarbonBasicPolicyPublisherModule method doSend.

private void doSend(String body) throws EntitlementException {
    if (serverUrl != null) {
        serverUrl = serverUrl.trim();
        if (!serverUrl.endsWith("/")) {
            serverUrl += "/";
        }
    }
    String serverEndPoint = serverUrl + "EntitlementPolicyAdminService";
    ServiceClient client = null;
    try {
        MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
        HttpClient httpClient = new HttpClient(httpConnectionManager);
        client = new ServiceClient(configCtx, null);
        Options option = client.getOptions();
        option.setManageSession(true);
        HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
        authenticator.setUsername(serverUserName);
        authenticator.setPassword(serverPassword);
        authenticator.setPreemptiveAuthentication(true);
        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, authenticator);
        option.setProperty(Constants.Configuration.TRANSPORT_URL, serverEndPoint);
        option.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);
        option.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
        client.sendRobust(AXIOMUtil.stringToOM(body));
    } catch (AxisFault axisFault) {
        log.error("Policy publish fails due : " + axisFault.getMessage(), axisFault);
        throw new EntitlementException("Policy publish fails due : " + axisFault.getMessage());
    } catch (XMLStreamException e) {
        log.error("Policy publish fails due : " + e.getMessage(), e);
        throw new EntitlementException("Policy publish fails due : " + e.getMessage());
    } finally {
        if (client != null) {
            try {
                client.cleanupTransport();
                client.cleanup();
            } catch (AxisFault axisFault) {
                log.error("Error while cleaning HTTP client", axisFault);
            }
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) Options(org.apache.axis2.client.Options) EntitlementException(org.wso2.carbon.identity.entitlement.EntitlementException) HttpTransportProperties(org.apache.axis2.transport.http.HttpTransportProperties) XMLStreamException(javax.xml.stream.XMLStreamException) ServiceClient(org.apache.axis2.client.ServiceClient) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)

Example 17 with EntitlementException

use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.

the class CarbonPDPPublisher method publish.

@Override
public void publish(PolicyDTO policyDTO, String action, boolean enabled, int order) throws EntitlementException {
    PolicyStoreManager manager = EntitlementAdminEngine.getInstance().getPolicyStoreManager();
    if (EntitlementConstants.PolicyPublish.ACTION_CREATE.equals(action)) {
        policyDTO.setPolicyOrder(order);
        policyDTO.setActive(enabled);
        manager.addPolicy(policyDTO);
    } else if (EntitlementConstants.PolicyPublish.ACTION_DELETE.equals(action)) {
        manager.removePolicy(policyDTO);
    } else if (EntitlementConstants.PolicyPublish.ACTION_UPDATE.equals(action)) {
        manager.updatePolicy(policyDTO);
    } else if (EntitlementConstants.PolicyPublish.ACTION_ENABLE.equals(action)) {
        policyDTO.setActive(true);
        manager.enableDisablePolicy(policyDTO);
    } else if (EntitlementConstants.PolicyPublish.ACTION_DISABLE.equals(action)) {
        policyDTO.setActive(false);
        manager.enableDisablePolicy(policyDTO);
    } else if (EntitlementConstants.PolicyPublish.ACTION_ORDER.equals(action)) {
        policyDTO.setPolicyOrder(order);
        manager.orderPolicy(policyDTO);
    }
}
Also used : PolicyStoreManager(org.wso2.carbon.identity.entitlement.policy.store.PolicyStoreManager)

Example 18 with EntitlementException

use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.

the class PolicyAttributeBuilder method getPolicyMetaDataFromPolicy.

/**
 * This creates properties object which contains the policy meta data.
 *
 * @return properties object which contains the policy meta data
 * @throws EntitlementException throws
 */
public Properties getPolicyMetaDataFromPolicy() throws EntitlementException {
    List<AttributeDTO> attributeDTOs = new ArrayList<AttributeDTO>();
    try {
        attributeDTOs = createPolicyMetaData(policy, attributeDTOs);
    } catch (EntitlementException e) {
        throw new EntitlementException("Can not create Policy MetaData for given policy");
    }
    int attributeElementNo = 0;
    Properties properties = new Properties();
    if (attributeDTOs != null) {
        for (AttributeDTO attributeDTO : attributeDTOs) {
            properties.setProperty(PDPConstants.POLICY_META_DATA + attributeElementNo, attributeDTO.getCategory() + PDPConstants.ATTRIBUTE_SEPARATOR + attributeDTO.getAttributeValue() + PDPConstants.ATTRIBUTE_SEPARATOR + attributeDTO.getAttributeId() + PDPConstants.ATTRIBUTE_SEPARATOR + attributeDTO.getAttributeDataType());
            attributeElementNo++;
        }
    }
    return properties;
}
Also used : AttributeDTO(org.wso2.carbon.identity.entitlement.dto.AttributeDTO) EntitlementException(org.wso2.carbon.identity.entitlement.EntitlementException) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 19 with EntitlementException

use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.

the class EntitlementAdminService method refreshAttributeFinder.

/**
 * Refreshes the supported Attribute ids of a given attribute finder module
 *
 * @param attributeFinder Canonical name of the attribute finder class.
 * @throws EntitlementException throws if fails to  refresh
 */
public void refreshAttributeFinder(String attributeFinder) throws EntitlementException {
    Map<PIPAttributeFinder, Properties> designators = EntitlementServiceComponent.getEntitlementConfig().getDesignators();
    if (attributeFinder != null && designators != null && !designators.isEmpty()) {
        Set<Map.Entry<PIPAttributeFinder, Properties>> pipAttributeFinders = designators.entrySet();
        for (Map.Entry<PIPAttributeFinder, Properties> entry : pipAttributeFinders) {
            if (attributeFinder.equals(entry.getKey().getClass().getName()) || attributeFinder.equals(entry.getKey().getModuleName())) {
                try {
                    entry.getKey().init(entry.getValue());
                    entry.getKey().clearCache();
                    CarbonAttributeFinder carbonAttributeFinder = EntitlementEngine.getInstance().getCarbonAttributeFinder();
                    carbonAttributeFinder.init();
                } catch (Exception e) {
                    throw new EntitlementException("Error while refreshing attribute finder - " + attributeFinder);
                }
                break;
            }
        }
    }
}
Also used : CarbonAttributeFinder(org.wso2.carbon.identity.entitlement.pip.CarbonAttributeFinder) PIPAttributeFinder(org.wso2.carbon.identity.entitlement.pip.PIPAttributeFinder) AbstractPIPAttributeFinder(org.wso2.carbon.identity.entitlement.pip.AbstractPIPAttributeFinder) Properties(java.util.Properties) Map(java.util.Map)

Example 20 with EntitlementException

use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.

the class EntitlementAdminService method refreshResourceFinder.

/**
 * Refreshes the supported resource id of a given resource finder module
 *
 * @param resourceFinder Canonical name of the resource finder class.
 * @throws EntitlementException throws if fails to  refresh
 */
public void refreshResourceFinder(String resourceFinder) throws EntitlementException {
    Map<PIPResourceFinder, Properties> resourceFinders = EntitlementServiceComponent.getEntitlementConfig().getResourceFinders();
    if (resourceFinder != null && resourceFinders != null && !resourceFinders.isEmpty()) {
        for (Map.Entry<PIPResourceFinder, Properties> entry : resourceFinders.entrySet()) {
            if (resourceFinder.equals(entry.getKey().getClass().getName()) || resourceFinder.equals(entry.getKey().getModuleName())) {
                try {
                    entry.getKey().init(entry.getValue());
                    entry.getKey().clearCache();
                    CarbonAttributeFinder carbonAttributeFinder = EntitlementEngine.getInstance().getCarbonAttributeFinder();
                    carbonAttributeFinder.init();
                } catch (Exception e) {
                    throw new EntitlementException("Error while refreshing attribute finder - " + resourceFinder);
                }
                break;
            }
        }
    }
}
Also used : CarbonAttributeFinder(org.wso2.carbon.identity.entitlement.pip.CarbonAttributeFinder) Properties(java.util.Properties) Map(java.util.Map) PIPResourceFinder(org.wso2.carbon.identity.entitlement.pip.PIPResourceFinder)

Aggregations

EntitlementException (org.wso2.carbon.identity.entitlement.EntitlementException)42 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)23 ArrayList (java.util.ArrayList)19 PolicyDTO (org.wso2.carbon.identity.entitlement.dto.PolicyDTO)18 Resource (org.wso2.carbon.registry.core.Resource)18 Registry (org.wso2.carbon.registry.core.Registry)13 Collection (org.wso2.carbon.registry.core.Collection)12 Properties (java.util.Properties)11 AbstractPolicy (org.wso2.balana.AbstractPolicy)9 PolicyPublisher (org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher)9 PolicyStoreDTO (org.wso2.carbon.identity.entitlement.dto.PolicyStoreDTO)7 Map (java.util.Map)6 StatusHolder (org.wso2.carbon.identity.entitlement.dto.StatusHolder)6 PAPPolicyStoreManager (org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreManager)6 AttributeDTO (org.wso2.carbon.identity.entitlement.dto.AttributeDTO)5 PAPPolicyStore (org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStore)5 PolicyAttributeBuilder (org.wso2.carbon.identity.entitlement.policy.PolicyAttributeBuilder)5 PolicyVersionManager (org.wso2.carbon.identity.entitlement.policy.version.PolicyVersionManager)5 CertificateEncodingException (java.security.cert.CertificateEncodingException)4 SignatureException (org.opensaml.xmlsec.signature.support.SignatureException)4