/*
(non-Javadoc)

@see com.ibm.wsspi.security.audit.AuditService#isAuditRequired()
436278
@Override
    public boolean isAuditRequired(String eventType, String outcome) {
        // TODO: need to handle auditData

        for (Map.Entry<String, List<Map<String, Object>>> handlerMap : handlerEventsMap.entrySet()) {

            List<Map<String, Object>> handlerEventsList = handlerMap.getValue();
            if (handlerEventsList.isEmpty()) {
                if (tc.isDebugEnabled()) {
                    Tr.debug(tc, "handlerEventsList is empty, returning true for isAuditRequired");
                }
                return true;
            }
            for (Map<String, Object> handlerEvents : handlerEventsList) {
                if (handlerEvents.isEmpty()) {
                    if (tc.isDebugEnabled()) {
                        Tr.debug(tc, "no events or outcomes specified, all events and outcomes are honoured");
                    }
                    return true;
                } else {
                    boolean foundMatchingEvent = false;
                    boolean foundAnOutcome = false;
                    boolean foundMatchingEventAndOutcome = false;
                    for (Entry<String, Object> entry : handlerEvents.entrySet()) {
                        if (entry.getKey().equals(AuditConstants.EVENT_NAME) && entry.getValue().equals(eventType)) {
                            foundMatchingEvent = true;
                        } else {
                            if (entry.getKey().equals(AuditConstants.OUTCOME)) {
                                foundAnOutcome = true;
                                if (entry.getValue().toString().equalsIgnoreCase(outcome)) {
                                    if (foundMatchingEvent) {
                                        foundMatchingEventAndOutcome = true;
                                    }
                                }
                            }
                        }

                    }
                    if (foundMatchingEventAndOutcome || (foundMatchingEvent && !foundAnOutcome)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
608758
public boolean isIgnored() {
        NodeMonitor m = ComputerSet.getMonitors().get(this);
        return m==null || m.isIgnored();
    }
760629
private boolean isAccessGranted(ScoreNode[] nodes) throws RepositoryException
   {
      if (isSystemSession)
      {
         return true;
      }
      for (int i = 0; i < nodes.length; i++)
      {
         try
         {
            //if (nodes[i] != null && !accessMgr.isGranted(nodes[i].getNodeId(), PermissionType.READ)) {
            if (nodes[i] != null)
            {
               NodeData nodeData = (NodeData)itemMgr.getItemData(nodes[i].getNodeId());
               if (nodeData == null
                  || !accessMgr.hasPermission(nodeData.getACL(), PermissionType.READ, session.getUserState()
                     .getIdentity()))
               {
                  return false;
               }
            }
         }
         catch (ItemNotFoundException e)
         {
            if (LOG.isTraceEnabled())
            {
               LOG.trace("An exception occurred: " + e.getMessage());
            }
         }
      }
      return true;
   }
476616
public boolean isRequestedSessionIdValid()
    {
        if (WCCustomProperties.CHECK_REQUEST_OBJECT_IN_USE){
            checkRequestObjectInUse();
        }
        // 321485
        boolean sessionInvalid = _requestContext.isRequestedSessionIdValid(((WebAppDispatcherContext) this.getDispatchContext()).getWebApp());
        if (TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
            logger.logp(Level.FINE, CLASS_NAME,"isRequestedSessionIdValid", " " + String.valueOf(sessionInvalid));
        }
        return sessionInvalid;
    }
904080
public boolean isProtected() {
        List<String> requiredRoles = null;
        return !webRequest.isUnprotectedURI() &&
               webRequest.getMatchResponse() != null &&
               (requiredRoles = webRequest.getRequiredRoles()) != null &&
               !requiredRoles.isEmpty();
    }
985809
@Override
    public SIDestinationAddress checkMessagingRequired(SIDestinationAddress requestDestAddr,
                                                       SIDestinationAddress replyDestAddr,
                                                       DestinationType destinationType,
                                                       String alternateUser)

                    throws SIConnectionDroppedException,
                    SIConnectionUnavailableException,
                    SIErrorException,
                    SIIncorrectCallException,
                    SITemporaryDestinationNotFoundException,
                    SIResourceException,
                    SINotAuthorizedException,
                    SINotPossibleInCurrentConfigurationException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "checkMessagingRequired",
                        new Object[] { requestDestAddr,
                                      replyDestAddr,
                                      alternateUser,
                                      destinationType });

        //Assume the bus cannot be skipped
        boolean destinationIsFastPath = false;
        boolean requestIsFastPath = false;
        boolean replyIsFastPath = true;
        boolean foreignBusFound = false;
        boolean destinationIsSendAllowed;
        List<JsDestinationAddress> rrp = new LinkedList<JsDestinationAddress>();
        SIDestinationAddress targetPort = null;
        boolean loopFound = false;
        Set<String> duplicateDestinationNames = null;

        // Synchronize on the close object, we don't want the connection closing
        // while we check if the destination can be fast-pathed
        synchronized (this)
        {
            // See if this connection has been closed
            checkNotClosed();

            //Validate the sending destination addresses is not null
            checkProducerSessionNullParameters(requestDestAddr);

            SecurityContext secContext = null;
            // If security is enabled then we need to set up a security context
            if (_isBusSecure)
            {
                // Add the alternate user string to the security context
                secContext = new SecurityContext(_subject,
                                alternateUser,
                                null,
                                _messageProcessor.getAuthorisationUtils());
            }

            String destinationName = requestDestAddr.getDestinationName();
            String busName = requestDestAddr.getBusName();

            if ((busName == null) || (busName.equals(_messageProcessor.getMessagingEngineBus())))
            {
                //Look up the named destination    
                DestinationHandler destination = null;
                destination = _destinationManager.getDestination(destinationName, busName, false);

                // Check the destination type
                checkDestinationType(destinationType, requestDestAddr, destination, false);

                // Ensure that the destination is put enabled
                destinationIsSendAllowed = destination.isSendAllowed();

                if (!destination.isPubSub() && destination.hasLocal() && destinationIsSendAllowed)
                {
                    PtoPLocalMsgsItemStream ptoPLocalMsgsItemStream =
                                    (PtoPLocalMsgsItemStream) destination.getQueuePoint(_messageProcessor.getMessagingEngineUuid());

                    destinationIsSendAllowed = ptoPLocalMsgsItemStream.isSendAllowed();
                }

                // Check authority to produce to destination
                // If security is disabled then we'll bypass the check
                if (_isBusSecure)
                {
                    checkProducerAuthority(requestDestAddr,
                                           destination,
                                           destinationName,
                                           busName,
                                           secContext,
                                           false);

                    // Go on to check authority to consume from the reply destination.
                    // We do this up front to ensure that an SINotAuth exception can
                    // be thrown as early as possible.                       
                    if (replyDestAddr != null)
                    {
                        String replyDestinationName = replyDestAddr.getDestinationName();
                        String replyBusName = replyDestAddr.getBusName();

                        //Look up the reply destination    
                        DestinationHandler replyDestination =
                                        _destinationManager.getDestination(replyDestinationName,
                                                                           replyBusName,
                                                                           false);

                        // Check authority to produce to the reply destination.  The reply will 
                        // be produced with the same userid as the request
                        // If security is disabled then we'll bypass the check
                        checkDestinationAccess(replyDestination,
                                               replyDestinationName,
                                               replyBusName,
                                               secContext);
                    }
                }

                //Set up the reverse routing path as we go along.
                JsDestinationAddress replyDest = destination.getReplyDestination();
                if ((replyDest != null) && (replyDestAddr != null))
                {
                    rrp.add(replyDest);
                }

                //Now validate each entry on the administered forward routing path.
                //If one is found that breaks the fastpath rules, then leave the
                //loop
                JsDestinationAddress entry = null;
                DestinationHandler frpDestination = destination;

                //Get the administered forward routing path from the named destination
                List frp = destination.getForwardRoutingPath();

                if (frp != null)
                {
                    int frpSize = frp.size();
                    int frpCount = 0;

                    //Ensure there is no infinite loop in the forward routing path
                    duplicateDestinationNames = new HashSet<String>();
                    duplicateDestinationNames.add(destination.getName());

                    while ((!frpDestination.isPubSub()) && //not a topicspace
                           (!foreignBusFound) &&
                           (!loopFound) &&
                           (destinationIsSendAllowed) &&
                           (frpCount < frpSize)) //forward routing path
                                                 //contains entries
                    {
                        // read element from FRP
                        entry = (JsDestinationAddress) frp.get(frpCount);
                        frpCount++;

                        String frpName = entry.getDestinationName();
                        String frpBusName = entry.getBusName();

                        if ((frpBusName == null) || (frpBusName.equals(_messageProcessor.getMessagingEngineBus())))
                        {
                            //Get the named destination from the destination manager
                            frpDestination = _destinationManager.getDestination(frpName, frpBusName, false);

                            // If security is enabled, then we need to check authority to access
                            // the next destination
                            // Check authority to produce to destination
                            // If security is disabled then we'll bypass the check
                            if (_isBusSecure)
                            {
                                checkDestinationAccess(frpDestination,
                                                       frpName,
                                                       frpBusName,
                                                       secContext);
                            }

                            //Set up the reverse routing path as we go along.
                            replyDest = frpDestination.getReplyDestination();
                            if ((replyDest != null) && (replyDestAddr != null))
                            {
                                rrp.add(replyDest);
                            }

                            //If this is the last destination in the FRP, then see if this
                            //destination has a default adminstered FRP which we should now
                            //check.
                            if (frpCount == frpSize)
                            {
                                List additionalFRP = frpDestination.getForwardRoutingPath();
                                if (additionalFRP != null)
                                {
                                    //Before adding an additional forward routing path, ensure it wont make us loop forever
                                    if (duplicateDestinationNames.contains(frpDestination.getName()))
                                    {
                                        loopFound = true;
                                    }
                                    else
                                    {
                                        duplicateDestinationNames.add(frpDestination.getName());
                                        frp = additionalFRP;
                                        frpSize = frp.size();
                                        frpCount = 0;
                                    }
                                }
                            }
                        }
                        else
                        {
                            foreignBusFound = true;
                        }
                    }
                }

                //We have either succesfully checked all the destinations on the
                //administered forward routing path, or frpDestination will be
                //referencing the first destination that failed one of the 
                //checks.  Determine here which is the correct response to give
                //the caller.
                if ((!foreignBusFound) &&
                    (!loopFound) &&
                    (destinationIsSendAllowed) &&
                    (frpDestination.hasLocal()) && //local queue-point
                    (frpDestination.getDestinationType() == DestinationType.PORT) &&
                    (!frpDestination.isPubSub())) //not a topicspace 
                {
                    requestIsFastPath = true;
                    targetPort = JsMainAdminComponentImpl.getSIDestinationAddressFactory().createSIDestinationAddress(frpDestination.getName(), frpDestination.getBus());
                }

                //Now check if the reply message can also be fastpathed.
                //Only worth checking if the request can be.
                if (requestIsFastPath)
                {
                    DestinationHandler rrpDestination = null;

                    while (!rrp.isEmpty())
                    {
                        // Pop off first element of RRP
                        entry = rrp.remove(0);

                        String rrpName = entry.getDestinationName();
                        String rrpBusName = entry.getBusName();

                        if ((rrpBusName != null) &&
                            (!(rrpBusName.equals(_messageProcessor.getMessagingEngineBus()))))
                        {
                            replyIsFastPath = false;
                            rrp.clear();
                        }
                        else
                        {
                            //Get the named destination from the destination manager
                            rrpDestination = _destinationManager.getDestination(rrpName, rrpBusName, false);

                            // If security is enabled, then we need to check authority to access
                            // the next destination
                            // Check authority to produce to destination
                            // If security is disabled then we'll bypass the check
                            if (_isBusSecure)
                            {
                                checkDestinationAccess(rrpDestination,
                                                       rrpName,
                                                       rrpBusName,
                                                       secContext);
                            }
                        }
                    }

                    if (replyIsFastPath)
                    {
                        if (replyDestAddr != null)
                        {
                            //The reverse routing path was checked and is ok.  Now check the final
                            //reply destination.

                            destinationName = replyDestAddr.getDestinationName();
                            busName = replyDestAddr.getBusName();

                            if ((busName != null) &&
                                (!(busName.equals(_messageProcessor.getMessagingEngineBus()))))
                            {
                                replyIsFastPath = false;
                            }
                            else
                            {
                                //Look up the named destination    
                                destination = _destinationManager.getDestination(destinationName, busName, false);

                                boolean replyDestinationHasFRP = false;
                                List replyDestinationFRP = destination.getForwardRoutingPath();
                                if ((replyDestinationFRP != null) &&
                                    (!(replyDestinationFRP.isEmpty())))
                                {
                                    replyDestinationHasFRP = true;
                                }

                                //The reply destination must also have a local queue point and no Forward Routing Path
                                if ((!(destination.hasLocal())) ||
                                    (replyDestinationHasFRP == true) ||
                                    (!(destination.isReceiveAllowed())))
                                {
                                    replyIsFastPath = false;
                                }
                            }
                        }
                    }

                    if ((requestIsFastPath) && (replyIsFastPath))
                    {
                        destinationIsFastPath = true;
                    }
                }
            }
        }

        if (!destinationIsFastPath)
            targetPort = null;

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "checkMessagingRequired", targetPort);

        return targetPort;
    }
1026310
protected boolean isEvictionRequired() {
        boolean evictionRequired = false;
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            int size = primaryTable.size() + secondaryTable.size() + tertiaryTable.size();
            Tr.debug(tc, "The current cache size is " + size + "( " + primaryTable.size() + ", " + secondaryTable.size() + ", " + tertiaryTable.size() + ")");
        }

        if (entryLimit != 0 && entryLimit != Integer.MAX_VALUE) {
            int size = primaryTable.size() + secondaryTable.size() + tertiaryTable.size();

            // If the cache size is greater than its limit, time to purge...
            if (size > entryLimit) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(tc, "The cache size is " + size + "( " + primaryTable.size() + ", " + secondaryTable.size() + ", " + tertiaryTable.size()
                                 + ") which is greater than the cache limit of " + entryLimit + ".");
                evictionRequired = true;
            }
        }
        return evictionRequired;
    }
696028
private boolean checkUpdateRequired(final ConnectionResource _con)
        throws SQLException
    {
        final SQLSelect select = new SQLSelect();
        for (final AbstractColumnWithValue<?> colValue : getColumnWithValues()) {
            select.column(colValue.getColumnName());
        }
        select.from(getTableName());
        select.addPart(SQLPart.WHERE).addColumnPart(null, "ID")
                        .addPart(SQLPart.EQUAL).addValuePart(getIds()[0]);

        final Statement stmt = _con.createStatement();
        final ResultSet rs = stmt.executeQuery(select.getSQL());
        final ArrayListHandler handler = new ArrayListHandler(Context.getDbType().getRowProcessor());
        final List<Object[]> rows = handler.handle(rs);
        rs.close();
        stmt.close();
        if (rows.size() == 1) {
            final Object[] values = rows.get(0);
            int idx = 0;
            final Iterator<AbstractColumnWithValue<?>> colIter = getColumnWithValues().iterator();
            while (colIter.hasNext()) {
                final AbstractColumnWithValue<?> colValue = colIter.next();
                final Object dbValue = values[idx];
                final Object newValue = colValue.getValue();
                if (dbValue instanceof Long) {
                    if (newValue instanceof Long) {
                        if (dbValue.equals(newValue)) {
                            colIter.remove();
                        }
                    } else if (newValue instanceof Integer) {
                        if (dbValue.equals(new Long((Integer) newValue))) {
                            colIter.remove();
                        }
                    }
                } else if (dbValue instanceof BigDecimal) {
                    if (newValue instanceof BigDecimal) {
                        if (((BigDecimal) dbValue).compareTo((BigDecimal) newValue) == 0) {
                            colIter.remove();
                        }
                    } else if (newValue instanceof Long) {
                        if (((BigDecimal) dbValue).compareTo(BigDecimal.valueOf((Long) newValue)) == 0) {
                            colIter.remove();
                        }
                    } else if (newValue instanceof Integer) {
                        if (((BigDecimal) dbValue).compareTo(BigDecimal.valueOf(new Long((Integer) newValue))) == 0) {
                            colIter.remove();
                        }
                    }
                } else if (dbValue instanceof Timestamp) {
                    if (newValue instanceof Timestamp) {
                        if (((Timestamp) dbValue).equals((Timestamp) newValue)) {
                            colIter.remove();
                        }
                    }
                } else if (dbValue instanceof Boolean) {
                    if (newValue instanceof Boolean) {
                        if (((Boolean) dbValue).equals(newValue)) {
                            colIter.remove();
                        }
                    }
                } else if (dbValue instanceof String) {
                    if (newValue instanceof String) {
                        if (((String) dbValue).trim().equals(((String) newValue).trim())) {
                            colIter.remove();
                        }
                    }
                }
                idx++;
            }
        }
        return !getColumnWithValues().isEmpty();
    }
139548
private static boolean isRequired(ValidatorInfo info) {
		if (null != info) {
			for (ConstraintInfo constraint : info.getConstraints()) {
				if (constraint instanceof NotNullConstraintInfo) {
					return true;
				}
			}
		}
		return false;
	}
961831
@Override
    public boolean isSupported(Task task) {
        return task.getType().equals(Task.Type.AUDIT);
    }
1289021
private boolean isAuthorized() {
        SecurityService securityService = securityServiceRef.getService();
        AuthorizationService authzService = securityService.getAuthorizationService();
        boolean isAuthorized = authzService.isAuthorized(ManagementSecurityConstants.ADMIN_RESOURCE_NAME,
                                                         requiredRoles, null);
        return isAuthorized;
    }
398101
@JSONField(serialize = false)
  public boolean isAuthenticated() {
    // TODO: need to support thirdparty login.
    String sessionToken = getSessionToken();
    return !StringUtil.isEmpty(sessionToken);
  }
1067040
protected final boolean isAuthorized(HttpServletRequest req) throws Exception {

        /*
         * This is sensitive data;  we must verify that the user
         * has the appropriate level of access to see it...
         */

        // STEP (1):  Is there an IPerson?
        final IPerson person = personManager.getPerson((HttpServletRequest) req);
        if (person != null) {

            // STEP (2):  Is the person authenticated?
            final ISecurityContext securityContext = person.getSecurityContext();
            if (securityContext != null && securityContext.isAuthenticated()) {

                // STEP (3):  Does this user have SUBSCRIBE permission for permissionsAdminChannel?
                IAuthorizationPrincipal principal =
                        authorizationService.newPrincipal(
                                (String) person.getAttribute(IPerson.USERNAME), IPerson.class);

                final IPortletDefinition permissionsAdminPortlet =
                        portletDefinitionRegistry.getPortletDefinitionByFname(
                                PERMISSIONS_ADMIN_PORTLET_FNAME);
                if (permissionsAdminPortlet == null) {
                    return false;
                }

                final String portletId =
                        permissionsAdminPortlet.getPortletDefinitionId().getStringId();
                if (authorizationService.canPrincipalSubscribe(principal, portletId)) {
                    return true;
                }
            }
        }

        return false;
    }
664417
@SuppressWarnings("PMD.NPathComplexity")
    private static boolean isConfigured(AuditType auditType, JSONArray jsonArray) {
        if (auditType.equals(AuditType.CODE_REVIEW)) {
            return (jsonArray.toJSONString().contains(DashboardAuditStatus.DASHBOARD_REPO_CONFIGURED.name()) ? true : false);
        }
        if (auditType.equals(AuditType.CODE_QUALITY)) {
            return (jsonArray.toJSONString().contains(DashboardAuditStatus.DASHBOARD_CODEQUALITY_CONFIGURED.name()) ? true : false);
        }
        if (auditType.equals(AuditType.STATIC_SECURITY_ANALYSIS)) {
            return (jsonArray.toJSONString().contains(DashboardAuditStatus.DASHBOARD_STATIC_SECURITY_ANALYSIS_CONFIGURED.name()) ? true : false);
        }
        if (auditType.equals(AuditType.LIBRARY_POLICY)) {
            return (jsonArray.toJSONString().contains(DashboardAuditStatus.DASHBOARD_LIBRARY_POLICY_ANALYSIS_CONFIGURED.name()) ? true : false);
        }
        if (auditType.equals(AuditType.TEST_RESULT)) {
            return (jsonArray.toJSONString().contains(DashboardAuditStatus.DASHBOARD_TEST_CONFIGURED.name()) ? true : false);
        }
        if (auditType.equals(AuditType.PERF_TEST)) {
            return (jsonArray.toJSONString().contains(DashboardAuditStatus.DASHBOARD_PERFORMANCE_TEST_CONFIGURED.name()) ? true : false);
        }
        if (auditType.equals(AuditType.BUILD_REVIEW)) {
            return (jsonArray.toJSONString().contains(DashboardAuditStatus.DASHBOARD_BUILD_CONFIGURED.name()) ? true : false);
        }
        return false;
    }
1141943
public boolean isTopicAccessCheckRequired()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "isTopicAccessCheckRequired");
    // Look to the underlying definition
    boolean ret = definition.isTopicAccessCheckRequired();
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "isTopicAccessCheckRequired", Boolean.valueOf(ret));
    return ret;
  }
1164997
private boolean isSatisfied() {
        if(pipelineData.getZonesRequired() != null) {
            return ((pipelineData.getSuccesses() >= required) && (pipelineData.getZoneResponses()
                                                                              .size() >= (pipelineData.getZonesRequired() + 1)));
        } else {
            return pipelineData.getSuccesses() >= required;
        }
    }
657461
@Override
    public void notifyReceiveAllowed(boolean isAllowed)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "notifyReceiveAllowed", new Object[] { Boolean.valueOf(isAllowed), this });

        this.lock();
        try
        {
            try
            {
                checkReceiveAllowed();
            } catch (SISessionUnavailableException e)
            {
                // FFDC
                FFDCFilter.processException(
                                            e,
                                            "com.ibm.ws.sib.processor.impl.JSLocalConsumerPoint.notifyReceiveAllowed",
                                            "1:4287:1.22.5.1",
                                            this);

                SibTr.exception(tc, e);
            } catch (SIResourceException e)
            {
                // FFDC
                FFDCFilter.processException(
                                            e,
                                            "com.ibm.ws.sib.processor.impl.JSLocalConsumerPoint.notifyReceiveAllowed",
                                            "1:4298:1.22.5.1",
                                            this);

                SibTr.exception(tc, e);
            }
        } finally
        {
            this.unlock();
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "notifyReceiveAllowed");
    }