
    Vh%1                         d dl mZmZmZ eZddgddZdZdZdZ	d d	l
mZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlZd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionz1.1preview	certified)metadata_versionstatussupported_bya  
---
module: cyberark_authentication
short_description: CyberArk Authentication using PAS Web Services SDK.
author:
    - Edward Nunez (@enunez-cyberark)
    - Cyberark Bizdev (@cyberark-bizdev)
version_added: '1.0.0'
description:
    - Authenticates to CyberArk Vault using Privileged Account Security
      Web Services SDK and creates a session fact that can be used by other
      modules. It returns an Ansible fact called I(cyberark_session). Every
      module can use this fact as C(cyberark_session) parameter.
options:
    state:
        default: present
        choices: [present, absent]
        description:
            - Specifies if an authentication logon/logoff and a
              cyberark_session should be added/removed.
        type: str
    username:
        description:
            - The name of the user who will logon to the Vault.
        type: str
    password:
        description:
            - The password of the user.
        type: str
    new_password:
        description:
            - The new password of the user. This parameter is optional,
              and enables you to change a password.
        type: str
    api_base_url:
        description:
            - A string containing the base URL of the server hosting
              CyberArk's Privileged Account Security Web Services SDK.
        type: str
    validate_certs:
        type: bool
        default: 'true'
        description:
            - If C(false), SSL certificates will not be validated.  This
              should only set to C(false) used on personally controlled
              sites using self-signed certificates.
    use_ldap_authentication:
        type: bool
        default: 'false'
        description:
            - Whether or not LDAP will be used.
    use_windows_authentication:
        type: bool
        default: 'false'
        description:
            - Whether or not Windows will be used.
    use_cyberark_authentication:
        type: bool
        default: 'false'
        description:
            - Whether or not LDAP will be used.
    use_radius_authentication:
        type: bool
        default: 'false'
        description:
            - Whether or not users will be authenticated via a RADIUS
              server. Valid values are true/false.
    connection_number:
        type: int
        description:
            - To support multiple connections for same user specify
            - different value for this parameter.
    concurrentSession:
        type: bool
        default: false
        description:
            - Whether or not to allow concurrent sessions for the same user.
    cyberark_session:
        description:
            - Dictionary set by a CyberArk authentication containing the
              different values to perform actions on a logged-on CyberArk
              session.
        type: dict
    timeout:
        description:
            - Allows you set a timeout for when your authenticating to Cyberark
        default: 10
        type: int
a9  
- name: Logon - use_shared_logon_authentication
  cyberark_authentication:
    api_base_url: "{{ web_services_base_url }}"
    use_shared_logon_authentication: true

- name: Logon - Not use_shared_logon_authentication
  cyberark_authentication:
    api_base_url: "{{ web_services_base_url }}"
    username: "{{ password_object.password }}"
    password: "{{ password_object.passprops.username }}"
    use_shared_logon_authentication: false

- name: Logoff from CyberArk Vault
  cyberark_authentication:
    state: absent
    cyberark_session: "{{ cyberark_session }}"
a  
cyberark_session:
    description: Authentication facts.
    returned: success
    type: complex
    contains:
        api_base_url:
            description:
                - Base URL for API calls. Returned in the cyberark_session,
                  so it can be used in subsequent calls.
            type: str
            returned: always
        token:
            description:
                - The token that identifies the session, encoded in BASE 64.
            type: str
            returned: always
        use_shared_logon_authentication:
            description:
                - Whether or not Shared Logon Authentication was used to
                  establish the session.
            type: bool
            returned: always
        validate_certs:
            description: Whether or not SSL certificates should be validated.
            type: bool
            returned: always
)to_text)AnsibleModule)open_url)	HTTPError)HTTPExceptionNc           
         | j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d	   }	| j                   d
   }
| j                   d   }| j                   d   }| j                   d   }| j                  r|d }ddd}d}|
dk(  r>|rd}n|rd}n	|rd}nd}	d}||d}||	r||d<   |rd|d<   t        j                  |      }n|d   }|d   }|d   |d<   d}d }d}d }	 t	        ||z   d||||      }|j                         d&k(  rX|
dk(  r<d}	 t        t        j                  |j                                     }d|||d)i}|d}ndi i}|||j                         fS | j                  d*|z   |+       y # t
        t        f$ r9}| j                  d ||d!t        |      ||j                  "       Y d }~d }~wt        $ r/}| j                  d#||d$t        |      |d%"       Y d }~d }~ww xY w# t        $ r+}| j                  d't        |      z  ||d%(       Y d }~d }~ww xY w),Napi_base_urlvalidate_certsusernamepasswordnew_passworduse_radius_authenticationuse_ldap_authenticationuse_windows_authenticationuse_cyberark_authenticationstatecyberark_sessionconcurrentSessiontimeoutzapplication/jsonz$CyberArk/1.0 (Ansible; cyberark.pas))zContent-Typez
User-Agent presentz"/PasswordVault/API/Auth/LDAP/Logonz$/PasswordVault/API/Auth/radius/Logonz%/PasswordVault/API/auth/Windows/LogonTz&/PasswordVault/API/Auth/CyberArk/Logon)r   r   newPasswordtokenAuthorizationz/PasswordVault/API/Auth/LogoffFPOST)methodheadersdatar   r   z{Error while performing authentication.Please validate parameters provided, and ability to logon to CyberArk.
*** end_point=z
 ==> )msgr%   status_codez=Unknown error while performing authentication.
*** end_point=
   zError obtaining token
%s)r'   payloadr%   r(   )r!   r   r   zerror in end_point=>)r'   r%   )params
check_modejsondumpsr   r   r   	fail_jsonr   code	Exceptiongetcodestrloadsread)moduler   r   r   r   r   
use_radiususe_ldapuse_windowsuse_cyberarkr   r   r   r   r%   r,   	end_pointpayload_dictresultchangedresponsehttp_exceptionunknown_exceptionr!   es                            x/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cyberark/pas/plugins/modules/cyberark_authentication.pyprocessAuthenticationrF      s3    ==0L]]#34N}}Z(H}}Z(H==0L:;J}}67H-- <=K==!>?L MM'"E}}%78&9:mmI&G \5 +<G
 G	 <I>I?I  L@I %-(C#*6L' 04L,-**\*
 (7)*:;#3G#<  5	FGH"
9$)
D S I EDJJx}}78" #"$0&4%F '  )"-F!1!1!344 	3i?QK }% 
 Y(?A &++ 	 		
 		
  

  G4E,FH  	 	
 	


6    3wqzB## "	 !  s<   9G (,I I/HI%II	J!I??Jc                  "   ddidddddiddddddddd	ddd	ddd	ddd	ddd	dd
idddgddddidd
d	d} g dddgddgddgddgg}dddgfdddgfg}ddgg}t        | |||d      }t        |      \  }}}|j                  |||       y )Ntyper5   booltrue)rH   defaultT)rH   no_logF)rK   rH   intr   absent)rH   choicesrK   dict
   )r   r   r   r   r   r   r   r   r   r   connection_numberr   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   )argument_specmutually_exclusiverequired_ifrequired_togethersupports_check_mode)r@   ansible_factsr(   )r   rF   	exit_json)fieldsrT   rU   rV   r8   r@   r?   r(   s           rE   mainr[   H  s*     #)f=UO"d3!&$716%G27&H/4f#E38&'I).?$e_!8, 

 $V,!51%F4	
 
%n5	%~6	"N3	+, 
)n-.	(/01K
 %j12-+ F &;6%B"Wfk
WFT    __main__)
__future__r   r   r   rH   __metaclass__ANSIBLE_METADATADOCUMENTATIONEXAMPLESRETURNansible.module_utils._textr   ansible.module_utils.basicr   ansible.module_utils.urlsr   +ansible.module_utils.six.moves.urllib.errorr   *ansible.module_utils.six.moves.http_clientr   r/   rF   r[   __name__ r\   rE   <module>rk      sx   
 C B  k Xt&
: / 4 . A D cRL9Ux zF r\   