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);
}
}
}
}
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);
}
}
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;
}
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;
}
}
}
}
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;
}
}
}
}
Aggregations