How to use the dirac.lib.credentials.getUserDN function in DIRAC

To help you get started, we’ve selected a few DIRAC examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / systems / configuration.py View on Github external
  @jsonify
  def commitConfiguration( self ):
    if not authorizeAction():
      return S_ERROR( "You are not authorized to commit configurations!! Bad boy!" )
    gLogger.always( "User %s is commiting a new configuration version" % credentials.getUserDN() )
    modifier = self.__getModificator()
    modifier.loadFromBuffer( session[ 'cfgData' ] )
    retDict = modifier.commit()
    if not retDict[ 'OK' ]:
      return S_ERROR( retDict[ 'Message' ] )
    return S_OK()
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / jobs / JobMonitor.py View on Github external
def __getProxyStatus(self,secondsOverride = None):

    from DIRAC.FrameworkSystem.Client.ProxyManagerClient import ProxyManagerClient

    proxyManager = ProxyManagerClient()
    group = str(credentials.getSelectedGroup())
    if group == "visitor":
      return {"success":"false","error":"User is anonymous or is not registered in the system"}
    userDN = str(credentials.getUserDN())
    if secondsOverride and str(secondsOverride).isdigit():
      validSeconds = int(secondsOverride)
    else:
      defaultSeconds = 24 * 3600 + 60 # 24H + 1min
      validSeconds = gConfig.getValue("/Registry/DefaultProxyLifeTime",defaultSeconds)
    gLogger.info("\033[0;31m userHasProxy(%s, %s, %s) \033[0m" % (userDN,group,validSeconds))
    result = proxyManager.userHasProxy(userDN,group,validSeconds)
    if result["OK"]:
      if result["Value"]:
        c.result = {"success":"true","result":"true"}
      else:
        c.result = {"success":"true","result":"false"}
    else:
      c.result = {"success":"false","error":"false"}
    gLogger.info("\033[0;31m PROXY: \033[0m",result)
    return c.result
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / jobs / JobMonitor.py View on Github external
  @jsonify
  def submit(self):
    pagestart = time()
    RPC = getRPCClient("WorkloadManagement/JobMonitoring")
    user = str(credentials.getUsername())
    userDN = str(credentials.getUserDN())
    group = str(credentials.getSelectedGroup())
    result = RPC.getOwners()
    haveJobsToDisplay = False
    if result["OK"]:
      resultEligible = self.__getEligibleOwners( userDN, group )
      if resultEligible['OK']:
        for own in resultEligible['Value']:
          if own in result["Value"]:
            # There is something to display probably
            haveJobsToDisplay = True
            break
        if not haveJobsToDisplay:
          c.result = {"success":"false","error":"You don't have any jobs eligible to display"}
          return c.result
      else:
        c.result = {"success":"false","error":"Failed to evaluate eligible users"}
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / info / general.py View on Github external
def registerUser(self,paramcopy):
    gLogger.info("Start processing a registration request")
    """
    Unfortunately there is no way to get rid of empty text values in JS,
    so i have to hardcode it on server side. Hate it!
    """
    default_values = ["John Smith","jsmith","john.smith@gmail.com","+33 9 10 00 10 00"]
    default_values.append("Select preferred virtual organization(s)")
    default_values.append("Select your country")
    default_values.append("Any additional information you want to provide to administrators")
    # Check for having a DN but no username
    dn = getUserDN()
    username = getUsername()
    gLogger.debug("User's DN: %s and DIRAC username: %s" % (dn, username))
    if not username == "anonymous":
      error = "You are already registered in DIRAC with username: %s" % username
      gLogger.debug("Service response: %s" % error)
      return {"success":"false","error":error}
    else:
      if not dn:
        error = "Certificate is not loaded to a browser or DN is absent"
        gLogger.debug("Service response: %s" % error)
        return {"success":"false","error":error}
    body = ""
    userMail = False
    vo = []
    # Check for user's email, creating mail body
    gLogger.debug("Request's body:")
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / systems / SystemAdministration.py View on Github external
  @jsonify
  def sysinfo( self ):

    DN = getUserDN()
    group = getSelectedGroup()

    #TODO: remove hosts code after v6r7 since it will be built-in
    result = gConfig.getSections( "/Registry/Hosts" )
    if not result[ "Value" ]:
      return { "success" : "false" , "error" : result[ "Message" ] }
    hosts = result[ "Value" ]

    client = SystemAdministratorIntegrator( hosts = hosts , delegatedDN=DN ,
                                          delegatedGroup=group )
    result = client.getHostInfo()
    gLogger.debug( result )
    if not result[ "OK" ]:
      return { "success" : "false" , "error" : result[ "Message" ] }
    result = result[ "Value" ]
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / production / ProductionRequest.py View on Github external
def getRequestFields(self):
    result = dict.fromkeys(self.localFields,None)
    result.update(dict.fromkeys(self.simcondFields))
    for x in ['App','Ver','Opt','DDDb','CDb','EP']:
      for i in range(1,8):
        result['p%d%s' % (i,x)] = None
    result['userName'] = credentials.getUsername()
    result['userDN'] = credentials.getUserDN()
    return result
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / jobs / JobMonitor.py View on Github external
def display(self):
    pagestart = time()
    group = credentials.getSelectedGroup()
    if group == "visitor" and credentials.getUserDN() == "":
      return render("/login.mako")
    c.select = self.__getSelectionData()
    if not c.select.has_key("extra"):
      groupProperty = credentials.getProperties(group)
      if "JobAdministrator" not in groupProperty and "JobSharing" not in groupProperty:
        c.select["extra"] = {"owner":credentials.getUsername()}
    return render("jobs/JobMonitor.mako")
################################################################################
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / info / general.py View on Github external
def __sendMessage( self ):
  
    """
    This function is used to send a mail to specific group of DIRAC user
    Expected parameters from request are group, title, body
    """
    
    gLogger.info("Start message broadcasting")

    checkUserCredentials()
    dn = getUserDN()
    if not dn:
      error = "Certificate is not loaded in the browser or DN is absent"
      gLogger.error( "Service response: %s" % error )
      return { "success" : "false" , "error" : error }
    username = getUsername()
    if username == "anonymous":
      error = "Sending an anonymous message is forbidden"
      gLogger.error( "Service response: %s" % error )
      return { "success" : "false" , "error" : error }
    gLogger.info( "DN: %s" % dn )

    email = gConfig.getValue( "/Registry/Users/%s/Email" % username , "" )
    gLogger.debug( "/Registry/Users/%s/Email - '%s'" % ( username , email ) )
    emil = email.strip()
      
    if not email: