Class ExtSourceXML

All Implemented Interfaces:
ExtSourceApi, ExtSourceSimpleApi, Serializable, Comparable<PerunBean>
Direct Known Subclasses:
ExtSourceISXML

public class ExtSourceXML extends ExtSourceImpl implements ExtSourceApi
Author:
Michal Stava stavamichal@gmail.com
See Also:
  • 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 interface ExtSourceSimpleApi
    • convertNodeToMap

      protected Map<String,String> convertNodeToMap(Node node)
      Get XML node and convert all values by "xmlMapping" attribute to Map<String,String> In map there are "name=value" data.

      Attribute xmlMapping is from file perun-extSource.xml

      Parameters:
      node - node for converting
      Returns:
      Map<String, String> like <name,value>
      Throws:
      InternalErrorException
    • convertToXpathSearchString

      protected String convertToXpathSearchString(String query)
      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

      protected InputStream createTwoWaySSLConnection(String uri) throws IOException
      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 error
      InternalErrorException - if some variables are not correctly filled
    • extractValueByRegex

      protected String extractValueByRegex(String value, String regex)
      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 string
      regex - regex in format 'regex/replacement'
      Returns:
      extracted string from value by regex
      Throws:
      InternalErrorException
    • findSubjects

      public List<Map<String,String>> findSubjects(String searchString)
      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 interface ExtSourceApi
      Returns:
      list of maps, which contains attr_name->attr_value (for all extSource attributes)
    • findSubjects

      public List<Map<String,String>> findSubjects(String searchString, int maxResults)
      Description copied from interface: ExtSourceApi
      Finds all subjects with attributes in the external source, that contains searchString limited by the maxResults

      This method is used for getting all logins of subjects in external source with all possible attributes.

      Specified by:
      findSubjects in interface ExtSourceApi
      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 interface ExtSourceSimpleApi
      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 interface ExtSourceSimpleApi
      Returns:
      list of maps, which contains attr_name->attr_value but only for login definition eg. login;MichalS
      Throws:
      ExtSourceUnsupportedOperationException
    • getCon

      public HttpURLConnection getCon()
    • getGroupSubjects

      public List<Map<String,String>> getGroupSubjects(Map<String,String> attributes)
      Description copied from interface: ExtSourceSimpleApi
      Get the list of the subjects in the external group.
      Specified by:
      getGroupSubjects in interface ExtSourceSimpleApi
      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

      public Map<String,String> getSubjectByLogin(String login) throws SubjectNotExistsException
      Description copied from interface: ExtSourceSimpleApi
      Finds subject from the external source by the primary login used in external source.
      Specified by:
      getSubjectByLogin in interface ExtSourceSimpleApi
      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 ExtSourceUnsupportedOperationException
      Description copied from interface: ExtSourceSimpleApi
      Get the list of the subject groups in the external source.
      Specified by:
      getSubjectGroups in interface ExtSourceSimpleApi
      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

      public List<Map<String,String>> getUsersSubjects()
      Description copied from interface: ExtSourceSimpleApi
      Get the list of subjects from the external source.
      Specified by:
      getUsersSubjects in interface ExtSourceSimpleApi
      Returns:
      list of maps, which contains attr_name->attr_value, e.g. firstName->Michal
    • getValueFromXpath

      protected String getValueFromXpath(Node node, String xpathExpression)
      Get xml Node and xpath expression to get value from node by this xpath.
      Parameters:
      node - node for getting value from
      xpathExpression - expression for xpath to looking for value in node
      Returns:
      string extracted from node by xpath
      Throws:
      InternalErrorException
    • prepareEnvironment

      protected void prepareEnvironment()
    • setCon

      public void setCon(HttpURLConnection con)
    • xpathParsing

      protected List<Map<String,String>> xpathParsing(String query, int maxResults)
      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 file
      maxResults - never get more than maxResults results (0 mean unlimited)
      Returns:
      List of results, where result is Map<String,String> like <name, value>
      Throws:
      InternalErrorException