Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ind2uce
core
Commits
fbb2a21c
Commit
fbb2a21c
authored
Feb 26, 2018
by
Raj Shah
Browse files
Release 3.2.51
parent
7f5e9d2c
Changes
127
Show whitespace changes
Inline
Side-by-side
src/main/java/de/fraunhofer/iese/ind2uce/api/component/interfaces/package-info.java
View file @
fbb2a21c
src/main/java/de/fraunhofer/iese/ind2uce/api/component/package-info.java
View file @
fbb2a21c
src/main/java/de/fraunhofer/iese/ind2uce/api/policy/AuthorizationDecision.java
View file @
fbb2a21c
src/main/java/de/fraunhofer/iese/ind2uce/api/policy/Event.java
View file @
fbb2a21c
src/main/java/de/fraunhofer/iese/ind2uce/api/policy/ExecuteAction.java
View file @
fbb2a21c
src/main/java/de/fraunhofer/iese/ind2uce/api/policy/IPolicyValidator.java
0 → 100644
View file @
fbb2a21c
/*-
* =================================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
;
}
src/main/java/de/fraunhofer/iese/ind2uce/api/policy/ITimerValidator.java
0 → 100644
View file @
fbb2a21c
/*-
* =================================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
;
}
src/main/java/de/fraunhofer/iese/ind2uce/api/
common/Ind2uceRole
.java
→
src/main/java/de/fraunhofer/iese/ind2uce/api/
policy/InvalidPolicyException
.java
View file @
fbb2a21c
...
...
@@ -2,7 +2,7 @@
* =================================LICENSE_START=================================
* IND2UCE
* %%
* Copyright (C) 201
6
Fraunhofer IESE (www.iese.fraunhofer.de)
* Copyright (C) 201
7
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
{
public
class
InvalidPolicyException
extends
Exception
{
SOLUTION_DEVELOPER
(
"Developer"
),
ADMINISTRATOR
(
"Admin"
),
/**
* This role is not stored with user. It' for components, only.
*/
PDP
(
"PDP"
),
CLIENT
(
"CLIENT"
);
private
final
String
text
;
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
;
}
}
src/main/java/de/fraunhofer/iese/ind2uce/api/policy/InvalidTimerException.java
0 → 100644
View file @
fbb2a21c
/*-
* =================================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
);
}
}
src/main/java/de/fraunhofer/iese/ind2uce/api/policy/Modifier.java
View file @
fbb2a21c
src/main/java/de/fraunhofer/iese/ind2uce/api/policy/ModifierEngine.java
View file @
fbb2a21c
src/main/java/de/fraunhofer/iese/ind2uce/api/policy/PipRequest.java
View file @
fbb2a21c
...
...
@@ -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
;
...
...
src/main/java/de/fraunhofer/iese/ind2uce/api/policy/Policy.java
View file @
fbb2a21c
...
...
@@ -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
.
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
p
olicy
=
(
Policy
)
o
;
final
Policy
theP
olicy
=
(
Policy
)
o
;
return
this
.
id
!=
null
?
this
.
id
.
equals
(
p
olicy
.
id
)
:
p
olicy
.
id
==
null
;
return
this
.
id
!=
null
?
this
.
id
.
equals
(
theP
olicy
.
id
)
:
theP
olicy
.
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
);
}
...
...
src/main/java/de/fraunhofer/iese/ind2uce/api/policy/PolicyType.java
View file @
fbb2a21c
src/main/java/de/fraunhofer/iese/ind2uce/api/policy/PolicyValidator.java
View file @
fbb2a21c
...
...
@@ -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
;
/**
* The validator.
*/
private
static
Validator
validator
;
public
class
PolicyValidator
implements
IPolicyValidator
{
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_25
=
new
PolicyValidator25
();
validator
=
schema
.
new
Validator
();
private
static
final
IPolicyValidator
POLICY_VALIDATOR_46
=
new
Policy
Validator
46
();
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
);
}
}
public
static
boolean
validatePolicyOfSolution
(
String
policyString
)
{
boolean
valid
=
true
;
try
{
valid
=
PolicyValidator
.
validateXML
(
policyString
);
}
catch
(
SAXException
|
IOException
e
)
{
throw
new
IllegalArgumentException
(
"Policy is not valid according to XML Schema"
);
public
boolean
validateXMLSchema
(
String
policy
)
throws
InvalidPolicyException
{
if
(
policy
==
null
)
{
throw
new
InvalidPolicyException
(
"Policy must not be null"
);
}
final
Policy
p
=
new
Policy
(
policyString
);
final
String
solutionId
=
p
.
getId
().
getScope
();
try
{
final
DocumentBuilderFactory
documentumentBuilderFactory
=
DocumentBuilderFactory
.
newInstance
();
documentumentBuilderFactory
.
setNamespaceAware
(
true
);
final
DocumentBuilder
documentumentBuilder
=
documentumentBuilderFactory
.
newDocumentBuilder
();
final
Document
document
=
documentumentBuilder
.
parse
(
new
InputSource
(
new
StringReader
(
policyString
)));
final
XPathFactory
xpathFactory
=
XPathFactory
.
newInstance
();
final
XPath
xpath
=
xpathFactory
.
newXPath
();
final
HashMap
<
String
,
String
>
prefMap
=
new
HashMap
<
String
,
String
>()
{
{
this
.
put
(
"tns"
,
"http://www.iese.fraunhofer.de/ind2uce/3.0.25/enforcementLanguage"
);
this
.
put
(
"pip"
,
"http://www.iese.fraunhofer.de/ind2uce/3.0.25/pip"
);
}
};
final
SimpleNamespaceContext
namespaces
=
new
SimpleNamespaceContext
(
prefMap
);
xpath
.
setNamespaceContext
(
namespaces
);
// check PEP events
XPathExpression
expr
=
xpath
.
compile
(
".//tns:event"
);
NodeList
names
=
(
NodeList
)
expr
.
evaluate
(
document
,
XPathConstants
.
NODESET
);
final
List
<
String
>
errors
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
;
i
<
names
.
getLength
();
i
++)
{
final
Node
n
=
names
.
item
(
i
);
final
String
actionName
=
n
.
getAttributes
().
getNamedItem
(
"action"
).
getNodeValue
();
final
String
v
=
actionName
.
split
(
":"
)[
2
];
if
(!
new
EnforcementScopeId
(
v
).
getIdentifier
().
equals
(
solutionId
))
{
errors
.
add
(
"Event "
+
actionName
+
" does not refer to an action of solution "
+
solutionId
+
"."
);
}
}
// check PIP methods
expr
=
xpath
.
compile
(
".//pip:string|.//pip:boolean|.//pip:int|.//pip:float|.//pip:double|.//pip:object|.//pip:list"
);
names
=
(
NodeList
)
expr
.
evaluate
(
document
,
XPathConstants
.
NODESET
);
for
(
int
i
=
0
;
i
<
names
.
getLength
();
i
++)
{
final
Node
n
=
names
.
item
(
i
);
final
String
actionName
=
n
.
getAttributes
().
getNamedItem
(
"method"
).
getNodeValue
();
final
String
v
=
actionName
.
split
(
":"
)[
2
];
if
(!
new
EnforcementScopeId
(
v
).
getIdentifier
().
equals
(
solutionId
))
{
errors
.
add
(
"ExecuteAction "
+
actionName
+
" does not refer to a PXP of solution "
+
solutionId
+
"."
);
}
}
// check PXP methods
expr
=
xpath
.
compile
(
".//tns:executeAction"
);
names
=
(
NodeList
)
expr
.
evaluate
(
document
,
XPathConstants
.
NODESET
);
for
(
int
i
=
0
;
i
<
names
.
getLength
();
i
++)
{
final
Node
n
=
names
.
item
(
i
);
final
String
methodName
=
n
.
getAttributes
().
getNamedItem
(
"name"
).
getNodeValue
();
final
String
v
=
methodName
.
split
(
":"
)[
2
];
if
(!
new
EnforcementScopeId
(
v
).
getIdentifier
().
equals
(
solutionId
))
{
errors
.
add
(
"PIP "
+
methodName
+
" does not belong to solution "
+
solutionId
+
"."
);
if
(
policy
.
contains
(
"http://www.iese.fraunhofer.de/ind2uce/3.0.25/enforcementLanguage"
))
{
return
POLICY_VALIDATOR_25
.
validateXMLSchema
(
policy
);
}
else
if
(
policy
.
contains
(
""
))
{
return
POLICY_VALIDATOR_46
.
validateXMLSchema
(
policy
);
}
throw
new
InvalidPolicyException
(
"Unsupported policy version"
);
}
if
(
errors
.
size
()
>
0
)
{
final
StringBuilder
b
=
new
StringBuilder
();
b
.
append
(
"Policy is invalid due to the following errors:\n"
);
for
(
final
String
error
:
errors
)
{
b
.
append
(
error
);
b
.
append
(
"\n"
);
}
throw
new
IllegalArgumentException
(
b
.
toString
());
}
}
catch
(
IOException
|
SAXException
|
XPathExpressionException
|
ParserConfigurationException
e
)
{
throw
new
IllegalArgumentException
(
"Policy does not have attribute"
,
e
);
}
return
valid
;
@Override
public
boolean
checkPolicySolution
(
Policy
policy
)
throws
InvalidPolicyException
{
if
(
policy
==
null
)
{
throw
new
InvalidPolicyException
(
"Policy must not be null"
);
}
/**
* Validate XML.
*
* @param document the document
* @return true, if successful
* @throws SAXException the SAX exception
* @throws IOException Signals that an I/O exception has occurred.
*/
private
static
boolean
validateXML
(
Source
document
)
throws
SAXException
,
IOException
{
if
(
validator
==
null
)
{
throw
new
SAXException
(
"Unable to create schema"
);
}
validator
.
validate
(
document
);
LOG
.
info
(
"Policy is valid according to schema"
);
return
true
;
if
(
policy
.
getPolicy
().
contains
(
"http://www.iese.fraunhofer.de/ind2uce/3.0.25/enforcementLanguage"
))
{
return
POLICY_VALIDATOR_25
.
checkPolicySolution
(
policy
);
}
else
{
return
POLICY_VALIDATOR_46
.
checkPolicySolution
(
policy
);
}
/**
* Validate XML.
*
* @param document the document
* @return true, if successful
* @throws SAXException the SAX exception
* @throws IOException Signals that an I/O exception has occurred.
*/
public
static
boolean
validateXML
(
String
document
)
throws
SAXException
,
IOException
{
return
validateXML
(
new
StreamSource
(
new
StringReader
(
document
)));
}
}
src/main/java/de/fraunhofer/iese/ind2uce/api/policy/PolicyValidator25.java
0 → 100644
View file @
fbb2a21c
/*-
* =================================LICENSE_START=================================
* IND2UCE
* %%
* Copyright (C) 2016 Fraunhofer IESE (www.iese.fraunhofer.de)
* %%