Skip to content

Commit

Permalink
Adding logs to XacmlAttributeHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
rnavagamuwa committed Mar 26, 2019
1 parent e900f1d commit d73bb74
Showing 1 changed file with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import org.apache.http.ssl.SSLContextBuilder;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
Expand All @@ -26,7 +29,6 @@
import org.wso2.spring.security.abac.cache.Cache;
import org.wso2.spring.security.abac.cache.CacheManager;
import org.wso2.spring.security.abac.cache.EhCacheManager;
import org.wso2.spring.security.abac.exception.AttributeEvaluatorException;
import org.wso2.spring.security.abac.soaputils.CustomSSLHttpClientFactory;
import org.wso2.spring.security.abac.soaputils.EntitlementServiceClient;
import org.wso2.spring.security.abac.soaputils.wsdl.EntitledResultSetDTO;
Expand All @@ -51,6 +53,8 @@
@SuppressWarnings("WeakerAccess")
public class XacmlAttributeHandler implements AttributeHandler {

private static final Logger logger = LoggerFactory.getLogger(XacmlAttributeHandler.class);

private static String XACML_PDP_AUTHORIZE_URL;
private static String XACML_PDP_RESOURCE_LIST_URL;
private static String XACML_PDP_ENTITLEMENT_SERVICE_URL;
Expand Down Expand Up @@ -86,12 +90,26 @@ public XacmlAttributeHandler() {

} catch (IOException e) {

//todo stop the whole app
throw new AttributeEvaluatorException("Failed to read the XACML PDP Url", e);
logger.error("Failed to read properties from application.properties", e);
stopApplication();
}

if (XACML_PDP_AUTHORIZE_URL == null) {
//todo stop the whole app

logger.error("xacml.pdp.url.authorize property is null null in application.properties");
stopApplication();
}

if (XACML_PDP_RESOURCE_LIST_URL == null) {

logger.error("xacml.pdp.url.resource.list property is null in application.properties");
stopApplication();
}

if (XACML_PDP_ENTITLEMENT_SERVICE_URL == null) {

logger.error("xacml.pdp.url.entitlement.service property is null in application.properties");
stopApplication();
}

try {
Expand Down Expand Up @@ -136,15 +154,16 @@ public XacmlAttributeHandler() {
.build()));
} catch (Exception e) {

//todo stop the whole app
throw new AttributeEvaluatorException("Failed to read keystore or truststore", e);
logger.error("Failed to read trustStore/keyStore", e);
SpringApplication.run(XacmlAttributeHandler.class).close();
}

this.restHeaders = new HttpHeaders();
this.restHeaders.setContentType(MediaType.APPLICATION_JSON);
this.restHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
this.restHeaders.set("WSO2-Identity-User", "admin");

logger.info("XacmlAttributeHandler successfully initiated");
}

@Override
Expand Down Expand Up @@ -254,4 +273,9 @@ private KeyStore loadPfx(String file, char[] password) throws Exception {
return keyStore;
}

private static void stopApplication() {

SpringApplication.run(XacmlAttributeHandler.class).close();
}

}

0 comments on commit d73bb74

Please sign in to comment.