Class ExtSourceXML
- All Implemented Interfaces:
ExtSourceApi
,ExtSourceSimpleApi
,Serializable
,Comparable<PerunBean>
- Direct Known Subclasses:
ExtSourceISXML
- Author:
- Michal Stava stavamichal@gmail.com
- See Also:
-
Field Summary
Fields inherited from class cz.metacentrum.perun.core.impl.ExtSourceImpl
perunBl
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
If extSource needs to be closed, this method must be called.convertNodeToMap
(Node node) Get XML node and convert all values by "xmlMapping" attribute to Mapinvalid input: '<'String,String> In map there are "name=value" data.protected String
convertToXpathSearchString
(String query) Take plaintext query and create xpath query with concat function if needed.protected InputStream
Get https uri of xml document and create two way ssl connection using truststore and keystore.protected String
extractValueByRegex
(String value, String regex) Get regex in format 'regex/replacement' and value to get data from.findSubjects
(String searchString) Finds all subjects with attributes in the external source, that contains searchString.findSubjects
(String searchString, int maxResults) Finds all subjects with attributes in the external source, that contains searchString limited by the maxResultsfindSubjectsLogins
(String searchString) Finds all subjects logins in the external source, that contains searchString.findSubjectsLogins
(String searchString, int maxResulsts) Finds all subjects logins in the external source, that contains searchString, limited by the maxResults.getCon()
getGroupSubjects
(Map<String, String> attributes) Get the list of the subjects in the external group.getSubjectByLogin
(String login) Finds subject from the external source by the primary login used in external source.getSubjectGroups
(Map<String, String> attributes) Get the list of the subject groups in the external source.Get the list of subjects from the external source.protected String
getValueFromXpath
(Node node, String xpathExpression) Get xml Node and xpath expression to get value from node by this xpath.protected void
void
setCon
(HttpURLConnection con) xpathParsing
(String query, int maxResults) Get query and maxResults.Methods inherited from class cz.metacentrum.perun.core.impl.ExtSourceImpl
getAttributes
Methods inherited from class cz.metacentrum.perun.core.api.ExtSource
compareTo, equals, getBeanName, getName, getType, hashCode, serializeToString, setName, setType, toString
Methods inherited from class cz.metacentrum.perun.core.api.Auditable
getCreatedAt, getCreatedBy, getCreatedByUid, getModifiedAt, getModifiedBy, getModifiedByUid, setCreatedAt, setCreatedBy, setCreatedByUid, setModifiedAt, setModifiedBy, setModifiedByUid
-
Constructor Details
-
ExtSourceXML
public ExtSourceXML()
-
-
Method Details
-
close
public void close()Description copied from interface:ExtSourceSimpleApi
If extSource needs to be closed, this method must be called.- Specified by:
close
in interfaceExtSourceSimpleApi
-
convertNodeToMap
Get XML node and convert all values by "xmlMapping" attribute to Mapinvalid input: '<'String,String> In map there are "name=value" data.Attribute xmlMapping is from file perun-extSource.xml
- Parameters:
node
- node for converting- Returns:
- Mapinvalid input: '<'String, String> like invalid input: '<'name,value>
- Throws:
InternalErrorException
-
convertToXpathSearchString
Take plaintext query and create xpath query with concat function if needed. IMPORTANT: especially if there are these characters: ' (single quote) and " (double quotes)- Parameters:
query
- string for xpath query in plain text format- Returns:
- string for xpath, if there is needed, concat is used, if not, string without concet in quotes is returned, empty string if nothing in query
-
createTwoWaySSLConnection
Get https uri of xml document and create two way ssl connection using truststore and keystore.- Parameters:
uri
- https uri to xml document- Returns:
- input stream with xml document
- Throws:
IOException
- if there is some input/output errorInternalErrorException
- if some variables are not correctly filled
-
extractValueByRegex
Get regex in format 'regex/replacement' and value to get data from. Use regex and replacement to get data from value.IMPORTANT: Regex must be always in format 'regex/replacement' and must have exactly 1 existence of character '/' ex. '[abc](a)[b]/$1'
- Parameters:
value
- some stringregex
- regex in format 'regex/replacement'- Returns:
- extracted string from value by regex
- Throws:
InternalErrorException
-
findSubjects
Description copied from interface:ExtSourceApi
Finds all subjects with attributes in the external source, that contains searchString.This method is used for getting all logins of subjects in external source with all possible attributes.
- Specified by:
findSubjects
in interfaceExtSourceApi
- Parameters:
searchString
-- Returns:
- list of maps, which contains attr_name->attr_value (for all extSource attributes)
-
findSubjects
Description copied from interface:ExtSourceApi
Finds all subjects with attributes in the external source, that contains searchString limited by the maxResultsThis method is used for getting all logins of subjects in external source with all possible attributes.
- Specified by:
findSubjects
in interfaceExtSourceApi
- Parameters:
searchString
-maxResults
- define max number of returned results, 0 means unlimited- Returns:
- list of maps, which contains attr_name->attr_value (for all extSource attributes)
-
findSubjectsLogins
public List<Map<String,String>> findSubjectsLogins(String searchString, int maxResulsts) throws ExtSourceUnsupportedOperationException Description copied from interface:ExtSourceSimpleApi
Finds all subjects logins in the external source, that contains searchString, limited by the maxResults.This method is used for getting all logins of subjects in external source and then use them to searching in external source for other subjects attributes
- Specified by:
findSubjectsLogins
in interfaceExtSourceSimpleApi
- Parameters:
searchString
-maxResulsts
- limit returned results- Returns:
- list of maps, which contains attr_name->attr_value but only for login definition eg. login;MichalS
- Throws:
ExtSourceUnsupportedOperationException
-
findSubjectsLogins
public List<Map<String,String>> findSubjectsLogins(String searchString) throws ExtSourceUnsupportedOperationException Description copied from interface:ExtSourceSimpleApi
Finds all subjects logins in the external source, that contains searchString.This method is used for getting all logins of subjects in external source and then use them to searching in external source for other subjects attributes.
- Specified by:
findSubjectsLogins
in interfaceExtSourceSimpleApi
- Parameters:
searchString
-- Returns:
- list of maps, which contains attr_name->attr_value but only for login definition eg. login;MichalS
- Throws:
ExtSourceUnsupportedOperationException
-
getCon
-
getGroupSubjects
Description copied from interface:ExtSourceSimpleApi
Get the list of the subjects in the external group.- Specified by:
getGroupSubjects
in interfaceExtSourceSimpleApi
- Parameters:
attributes
- map of attributes used for quering the external source- Returns:
- list of maps, which contains attr_name->attr_value, e.g. firstName->Michal
-
getSubjectByLogin
Description copied from interface:ExtSourceSimpleApi
Finds subject from the external source by the primary login used in external source.- Specified by:
getSubjectByLogin
in interfaceExtSourceSimpleApi
- Parameters:
login
- login used in the external source- Returns:
- map which contains attr_name -> attr_value, e.g. firstName->Michal
- Throws:
SubjectNotExistsException
- if the subject cannot be found
-
getSubjectGroups
public List<Map<String,String>> getSubjectGroups(Map<String, String> attributes) throws ExtSourceUnsupportedOperationExceptionDescription copied from interface:ExtSourceSimpleApi
Get the list of the subject groups in the external source.- Specified by:
getSubjectGroups
in interfaceExtSourceSimpleApi
- Parameters:
attributes
- map of attributes used for quering the external source- Returns:
- list of maps, which contains attr name and attr value
- Throws:
ExtSourceUnsupportedOperationException
-
getUsersSubjects
Description copied from interface:ExtSourceSimpleApi
Get the list of subjects from the external source.- Specified by:
getUsersSubjects
in interfaceExtSourceSimpleApi
- Returns:
- list of maps, which contains attr_name->attr_value, e.g. firstName->Michal
-
getValueFromXpath
Get xml Node and xpath expression to get value from node by this xpath.- Parameters:
node
- node for getting value fromxpathExpression
- expression for xpath to looking for value in node- Returns:
- string extracted from node by xpath
- Throws:
InternalErrorException
-
prepareEnvironment
protected void prepareEnvironment() -
setCon
-
xpathParsing
Get query and maxResults. Prepare document and xpathExpression by query. Get all nodes by xpath from document and parse them one by one.The way of xml take from "file" or "uri" (configuration file)
- Parameters:
query
- xpath query from config filemaxResults
- never get more than maxResults results (0 mean unlimited)- Returns:
- List of results, where result is Mapinvalid input: '<'String,String> like invalid input: '<'name, value>
- Throws:
InternalErrorException
-