Commit fbb2a21c authored by Raj Shah's avatar Raj Shah
Browse files

Release 3.2.51

parent 7f5e9d2c
......@@ -7,9 +7,9 @@
* Licensed 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.
......
......@@ -7,9 +7,9 @@
* Licensed 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.
......
......@@ -7,9 +7,9 @@
* Licensed 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.
......@@ -142,7 +142,7 @@ public class AuthorizationDecision extends Ind2uceEntity {
*/
public static final AuthorizationDecision getDecisionAllow() {
return new AuthorizationDecision(DECISION_ALLOW);
}
/**
......@@ -152,7 +152,7 @@ public class AuthorizationDecision extends Ind2uceEntity {
*/
public static final AuthorizationDecision getDecisionInhibit() {
return new AuthorizationDecision(DECISION_INHIBIT);
}
/**
......@@ -293,7 +293,7 @@ public class AuthorizationDecision extends Ind2uceEntity {
public void setAuthorizationActionNames(List<String> authorizationActionNames) {
this.authorizationActionNames = authorizationActionNames;
}
/**
* Sets how much the event should be delayed.
*
......
......@@ -7,9 +7,9 @@
* Licensed 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.
......
......@@ -7,9 +7,9 @@
* Licensed 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.
......
/*-
* =================================LICENSE_START=================================
* IND2UCE
* %%
* Copyright (C) 2017 Fraunhofer IESE (www.iese.fraunhofer.de)
* %%
* Licensed 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.
* =================================LICENSE_END=================================
*/
package de.fraunhofer.iese.ind2uce.api.policy;
public interface IPolicyValidator {
public boolean validateXMLSchema(String policyString) throws InvalidPolicyException;
boolean checkPolicySolution(Policy p) throws InvalidPolicyException;
}
/*-
* =================================LICENSE_START=================================
* IND2UCE
* %%
* Copyright (C) 2017 Fraunhofer IESE (www.iese.fraunhofer.de)
* %%
* Licensed 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.
* =================================LICENSE_END=================================
*/
package de.fraunhofer.iese.ind2uce.api.policy;
public interface ITimerValidator {
public boolean validateXMLSchema(String timerString) throws InvalidTimerException;
boolean checkTimerSolution(Timer t) throws InvalidTimerException;
}
......@@ -2,7 +2,7 @@
* =================================LICENSE_START=================================
* IND2UCE
* %%
* Copyright (C) 2016 Fraunhofer IESE (www.iese.fraunhofer.de)
* Copyright (C) 2017 Fraunhofer IESE (www.iese.fraunhofer.de)
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,43 +17,16 @@
* limitations under the License.
* =================================LICENSE_END=================================
*/
package de.fraunhofer.iese.ind2uce.api.policy;
/**
*
*/
package de.fraunhofer.iese.ind2uce.api.common;
/**
* Roles fpr the PMP.
*
* @author Bernd Peltzer-Bartels
*/
public enum Ind2uceRole {
SOLUTION_DEVELOPER("Developer"), ADMINISTRATOR("Admin"),
/**
* This role is not stored with user. It' for components, only.
*/
PDP("PDP"), CLIENT("CLIENT");
private final String text;
public class InvalidPolicyException extends Exception {
private Ind2uceRole(final String text) {
this.text = text;
}
public InvalidPolicyException(String string, Exception e) {
super(string, e);
}
/**
* To spring role.
*
* @return the string
*/
public String toSpringRole() {
return "ROLE_" + this.name();
}
public InvalidPolicyException(String string) {
super(string);
}
@Override
public String toString() {
return this.text;
}
}
/*-
* =================================LICENSE_START=================================
* IND2UCE
* %%
* Copyright (C) 2017 Fraunhofer IESE (www.iese.fraunhofer.de)
* %%
* Licensed 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.
* =================================LICENSE_END=================================
*/
package de.fraunhofer.iese.ind2uce.api.policy;
public class InvalidTimerException extends Exception {
public InvalidTimerException(String string, Exception e) {
super(string, e);
}
public InvalidTimerException(String string) {
super(string);
}
}
......@@ -7,9 +7,9 @@
* Licensed 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.
......
......@@ -7,9 +7,9 @@
* Licensed 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.
......
......@@ -7,9 +7,9 @@
* Licensed 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.
......@@ -151,7 +151,7 @@ public class PipRequest<T> extends Ind2uceEntity implements ParameterListProvide
return false;
}
} catch (final NullPointerException e) {
String msg = "Param: " + curParam.getName() + " is NOT present.";
final String msg = "Param: " + curParam.getName() + " is NOT present.";
LOG.debug(msg);
LOG.trace(msg, e);
return false;
......
......@@ -7,9 +7,9 @@
* Licensed 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.
......@@ -34,12 +34,12 @@ import java.util.HashMap;
import java.util.Map;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.Transient;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
......@@ -65,11 +65,28 @@ public class Policy {
@EmbeddedId
private PolicyId id;
@Transient
private boolean xmlValid = false;
@Transient
private boolean scopeValid = false;
public boolean isScopeValid() {
return this.scopeValid;
}
@Transient
private InvalidPolicyException invalidPolicyException;
/**
* The deployed.
*/
private boolean deployed;
public InvalidPolicyException getInvalidPolicyException() {
return this.invalidPolicyException;
}
/**
* The policy description.
*/
......@@ -103,12 +120,17 @@ public class Policy {
*
* @param id the id
* @param policy the policy
* @deprecated
*/
@Deprecated
public Policy(PolicyId id, String policy) {
super();
this.id = id;
this.policy = policy;
this.validateXML();
this.validateScope();
}
/**
......@@ -117,6 +139,7 @@ public class Policy {
* @param id the id
* @param policy the policy
* @param description the description
* @deprecated
*/
@Deprecated
public Policy(PolicyId id, String policy, String description) {
......@@ -124,18 +147,62 @@ public class Policy {
this.id = id;
this.policy = policy;
this.description = description;
this.validateXML();
this.validateScope();
}
/**
* Instantiates a new policy.
*
* @param policy the policy
* @throws InvalidPolicyException
*/
public Policy(String policy) {
super();
this.policy = policy;
this.id = new PolicyId(this.readAttribute("//policy/@id"));
this.description = this.readAttribute("//policy/@description");
this.validateXML();
this.extractIdAndDescription();
this.validateScope();
}
public boolean isXmlValid() {
return this.xmlValid;
}
private boolean validateScope() {
try {
this.scopeValid = new PolicyValidator().checkPolicySolution(this);
} catch (final InvalidPolicyException e) {
this.scopeValid = false;
this.invalidPolicyException = e;
} catch (final Exception e) {
LOG.warn("Exception in method validateScope", e);
}
return this.scopeValid;
}
public void extractIdAndDescription() {
try {
this.id = new PolicyId(this.readAttribute("//policy/@id"));
this.description = this.readAttribute("//policy/@description");
} catch (final Exception e) {
LOG.error("Exception in method extractIdAndDescription", e);
}
}
public boolean validateXML() {
try {
this.xmlValid = new PolicyValidator().validateXMLSchema(this.policy);
} catch (final InvalidPolicyException e) {
this.xmlValid = false;
this.invalidPolicyException = e;
}
return this.xmlValid;
}
/**
......@@ -143,10 +210,15 @@ public class Policy {
*
* @param policy the policy
* @param description the description
* @throws InvalidPolicyException
*/
public Policy(String policy, String description) {
this(policy);
this.policy = policy;
this.description = description;
this.validateXML();
this.extractIdAndDescription();
this.validateScope();
}
/**
......@@ -175,9 +247,9 @@ public class Policy {
return false;
}
final Policy policy = (Policy)o;
final Policy thePolicy = (Policy)o;
return this.id != null ? this.id.equals(policy.id) : policy.id == null;
return this.id != null ? this.id.equals(thePolicy.id) : thePolicy.id == null;
}
......@@ -259,8 +331,9 @@ public class Policy {
final XPathFactory xpathFactory = XPathFactory.newInstance();
final XPath xpath = xpathFactory.newXPath();
final XPathExpression expr = xpath.compile(xpathString);
final String names = (String)expr.evaluate(document, XPathConstants.STRING);
return names;
return (String)expr.evaluate(document, XPathConstants.STRING);
} catch (IOException | SAXException | XPathExpressionException | ParserConfigurationException e) {
throw new IllegalArgumentException("Policy does not have attribute", e);
}
......
......@@ -7,9 +7,9 @@
* Licensed 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.
......
......@@ -20,209 +20,39 @@
package de.fraunhofer.iese.ind2uce.api.policy;
import de.fraunhofer.iese.ind2uce.api.component.identifier.EnforcementScopeId;
import de.fraunhofer.iese.ind2uce.logger.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import java.io.IOException;
import java.io.StringReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
/**
* The Class PolicyValidator.
*/
public class PolicyValidator {
/**
* The Constant LOG.
*/
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(PolicyValidator.class);
/**
* The Constant SCHEMA_RESOURCE_FILEPATH.
*/
private static final String SCHEMA_RESOURCE_FILEPATH = "/languageSchema/enfLanguage.xsd";
/**
* The schema.
*/
private static Schema schema;
public class PolicyValidator implements IPolicyValidator {
/**
* The validator.
*/
private static Validator validator;
private static final IPolicyValidator POLICY_VALIDATOR_25 = new PolicyValidator25();
static {
try {
final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final URL url = PolicyValidator.class.getResource(SCHEMA_RESOURCE_FILEPATH);
schema = schemaFactory.newSchema(url);
private static final IPolicyValidator POLICY_VALIDATOR_46 = new PolicyValidator46();
validator = schema.newValidator();
validator.setErrorHandler(new ErrorHandler() {
@Override
public void error(SAXParseException exception) throws SAXException {
LOG.error("Validation error: " + exception.getMessage());
throw exception;
}
@Override
public void fatalError(SAXParseException exception) throws SAXException {
LOG.error("Validation fatal error: " + exception.getMessage());
throw exception;
}
@Override
public void warning(SAXParseException exception) throws SAXException {
LOG.error("Validation warning: " + exception.getMessage());
throw exception;
}
});
LOG.info("Successfully loaded schema");
} catch (final SAXException e) {
LOG.error("Unable to create schema", e);
@Override
public boolean validateXMLSchema(String policy) throws InvalidPolicyException {
if (policy == null) {
throw new InvalidPolicyException("Policy must not be null");
}
}
public static boolean validatePolicyOfSolution(String policyString) {
boolean valid = true;