Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-11446

Coverity, Resource leak in SecurityIdentity (Elytron)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 7.1.0.ER3
    • 7.1.0.DR19
    • Security
    • None

      Coverity found possible resource leak. On 2 places there is created ServerAuthenticationContext in SecurityIdentity but is not closed.

      SecurityIdentity.java
          public SecurityIdentity createRunAsIdentity(Principal principal, boolean authorize) throws SecurityException {
              Assert.checkNotNullParam("principal", principal);
              // rewrite principal
              final SecurityManager sm = System.getSecurityManager();
              if (sm != null) {
                  sm.checkPermission(SET_RUN_AS_PERMISSION);
              }
      
              final ServerAuthenticationContext context = securityDomain.createNewAuthenticationContext(this, MechanismConfigurationSelector.constantSelector(MechanismConfiguration.EMPTY));
              try {
                  if (! (context.importIdentity(this) && context.authorize(principal, authorize))) {
                      throw log.runAsAuthorizationFailed(this.principal, principal, null);
                  }
              } catch (RealmUnavailableException e) {
                  throw log.runAsAuthorizationFailed(this.principal, context.getAuthenticationPrincipal(), e);
              }
              return context.getAuthorizedIdentity();
          }
      
          public SecurityIdentity createRunAsAnonymous(boolean authorize) throws SecurityException {
              final SecurityManager sm = System.getSecurityManager();
              if (sm != null) {
                  sm.checkPermission(SET_RUN_AS_PERMISSION);
              }
      
              final ServerAuthenticationContext context = securityDomain.createNewAuthenticationContext(this, MechanismConfigurationSelector.constantSelector(MechanismConfiguration.EMPTY));
              if (! context.authorizeAnonymous(authorize)) {
                  throw log.runAsAuthorizationFailed(principal, AnonymousPrincipal.getInstance(), null);
              }
              return context.getAuthorizedIdentity();
          }
      

      In SecurityDomainTrustManager newly created ServerAuthenticationContext is closed in try-with-resource

      SecurityDomainTrustManager.java
      try (final ServerAuthenticationContext authenticationContext = securityDomain.createNewAuthenticationContext(mechanismConfigurationSelector)) {
      

      https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=22525060&defectInstanceId=5116909&mergedDefectId=1440894&fileStart=376&fileEnd=625

              rhn-support-ivassile Ilia Vassilev
              mchoma@redhat.com Martin Choma
              Martin Choma Martin Choma
              Martin Choma Martin Choma
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: