forked from community/device-mgt-core
Adding the final changes of the policy implementation, Added the simple policy evaluation implementation
parent
bddf71f2de
commit
90ff502b21
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.simple.policy.decision.point.internal;
|
||||||
|
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManager;
|
||||||
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
|
public class PolicyDecisionPointDataHolder {
|
||||||
|
|
||||||
|
private RealmService realmService;
|
||||||
|
private PolicyManager policyManager;
|
||||||
|
|
||||||
|
private static PolicyDecisionPointDataHolder dataHolder = new PolicyDecisionPointDataHolder();
|
||||||
|
|
||||||
|
private PolicyDecisionPointDataHolder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PolicyDecisionPointDataHolder getInstance() {
|
||||||
|
return dataHolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RealmService getRealmService() {
|
||||||
|
return realmService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRealmService(RealmService realmService) {
|
||||||
|
this.realmService = realmService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PolicyManager getPolicyManager() {
|
||||||
|
return policyManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPolicyManager(PolicyManager policyManager) {
|
||||||
|
this.policyManager = policyManager;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.simple.policy.decision.point.internal;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManager;
|
||||||
|
import org.wso2.carbon.simple.policy.decision.point.PolicyEvaluationServiceImpl;
|
||||||
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component name="org.wso2.carbon.simple.policy.decision.PolicyEvaluationServiceComponent" immediate="true"
|
||||||
|
* @scr.reference name="user.realmservice.default"
|
||||||
|
* interface="org.wso2.carbon.user.core.service.RealmService"
|
||||||
|
* cardinality="1..1"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setRealmService"
|
||||||
|
* unbind="unsetRealmService"
|
||||||
|
* @scr.reference name="org.wso2.carbon.devicemgt.policy.manager"
|
||||||
|
* interface="org.wso2.carbon.policy.mgt.core.PolicyManager"
|
||||||
|
* cardinality="0..1"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setPolicyManagerService"
|
||||||
|
* unbind="unsetPolicyManagerService"
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PolicyEvaluationServiceComponent {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(PolicyEvaluationServiceComponent.class);
|
||||||
|
|
||||||
|
protected void activate(ComponentContext componentContext) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Activating the simple policy evaluation bundle.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(),
|
||||||
|
new PolicyEvaluationServiceImpl(), null);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
log.error("Error occurred while initializing the simple policy evaluation bundle");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deactivate(ComponentContext componentContext) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("De-activating the simple policy evaluation bundle.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets Realm Service
|
||||||
|
*
|
||||||
|
* @param realmService An instance of RealmService
|
||||||
|
*/
|
||||||
|
protected void setRealmService(RealmService realmService) {
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Setting Realm Service");
|
||||||
|
}
|
||||||
|
PolicyDecisionPointDataHolder.getInstance().setRealmService(realmService);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsets Realm Service
|
||||||
|
*
|
||||||
|
* @param realmService An instance of RealmService
|
||||||
|
*/
|
||||||
|
protected void unsetRealmService(RealmService realmService) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Unsetting Realm Service");
|
||||||
|
}
|
||||||
|
PolicyDecisionPointDataHolder.getInstance().setRealmService(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void setPolicyManagerService(PolicyManager policyManagerService) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Unsetting PolicyManager Service");
|
||||||
|
}
|
||||||
|
PolicyDecisionPointDataHolder.getInstance().setPolicyManager(policyManagerService);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void unsetPolicyManagerService(PolicyManager policyManagerService) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Unsetting PolicyManager Service");
|
||||||
|
}
|
||||||
|
PolicyDecisionPointDataHolder.getInstance().setPolicyManager(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue