Class ExtSourceXML

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

public class ExtSourceXML extends ExtSource implements ExtSourceApi
Author:
Michal Stava stavamichal@gmail.com
See Also:
Serialized Form
  • Constructor Details

    • ExtSourceXML

      public ExtSourceXML()
  • Method Details

    • setPerunBlImpl

      public static PerunBlImpl setPerunBlImpl(PerunBlImpl perun)
    • 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
    • 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
    • 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)
    • 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
    • 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
    • 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
    • prepareEnvironment

      protected void prepareEnvironment()
    • 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 like
      Throws:
      InternalErrorException
    • convertNodeToMap

      protected Map<String,​String> convertNodeToMap(Node node)
      Get XML node and convert all values by "xmlMapping" attribute to Map In map there are "name=value" data. Attribute xmlMapping is from file perun-extSource.xml
      Parameters:
      node - node for converting
      Returns:
      Map like
      Throws:
      InternalErrorException
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • getCon

      public HttpURLConnection getCon()
    • setCon

      public void setCon(HttpURLConnection con)
    • getAttributes

      protected Map<String,​String> getAttributes()