Example usage for org.apache.commons.lang ArrayUtils isNotEmpty

List of usage examples for org.apache.commons.lang ArrayUtils isNotEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils isNotEmpty.

Prototype

public static boolean isNotEmpty(boolean[] array) 

Source Link

Document

Checks if an array of primitive booleans is not empty or not null.

Usage

From source file:org.wso2.carbon.identity.oauth2.util.ClaimsUtil.java

/**
 * To add the missing claims that are missed in IDP and SP mapping.
 *
 * @param tokenReqMsgCtx             Token request message context.
 * @param userAttributes                 Attributes received from IDP.
 * @param claimsAfterIDPandSPMapping Claims.
 * @param idPClaimMappings           IDP Claim mappings.
 * @return Final claim map with all the claims received from the IDP.
 * @throws IdentityApplicationManagementException Identity Application Management Exception.
 *//* w ww. ja v a 2s.  c o  m*/
private static Map<String, String> addMissingClaims(OAuthTokenReqMessageContext tokenReqMsgCtx,
        Map<String, String> userAttributes, Map<String, String> claimsAfterIDPandSPMapping,
        ClaimMapping[] idPClaimMappings) throws IdentityApplicationManagementException {

    boolean isUserClaimsLoggable = isUserClaimsInTokenLoggable();
    ServiceProvider serviceProvider = getServiceProvider(tokenReqMsgCtx);
    ClaimConfig serviceProviderClaimConfig = serviceProvider.getClaimConfig();
    AuthenticatedUser authenticatedUser = tokenReqMsgCtx.getAuthorizedUser();

    userAttributes.forEach((key, value) -> {
        boolean foundMatching = false;
        String localClaimUri = null;

        // If IDP Claim mapping is not empty.
        if (ArrayUtils.isNotEmpty(idPClaimMappings)) {
            // Go through the claim mappings to identify the missed attributes in IDP level claim mapping.
            for (ClaimMapping claimMapping : idPClaimMappings) {
                if (claimMapping.getRemoteClaim().getClaimUri().equals(key)) {
                    localClaimUri = claimMapping.getLocalClaim().getClaimUri();
                    foundMatching = true;
                    break;
                }
            }
            // If the relevant attribute is not mapped in IDP, add that.
            if (!foundMatching) {
                if (isUserClaimsLoggable) {
                    if (log.isDebugEnabled()) {
                        log.debug("IDP Claim mapping does not exist for " + key + ", hence adding value "
                                + value + " for the user : " + authenticatedUser);
                    }
                }
                claimsAfterIDPandSPMapping.put(key, value);
            } else {
                // If the relevant attribute has mapping in IDP level, check for SP level mapping.
                foundMatching = false;
                ClaimMapping[] spClaimMapping = serviceProviderClaimConfig.getClaimMappings();
                for (ClaimMapping claimMapping : spClaimMapping) {
                    if (claimMapping.getLocalClaim().getClaimUri().equals(localClaimUri)
                            && claimMapping.isRequested()) {
                        foundMatching = true;
                        break;
                    }
                }
                // If the relevant attribute has IDP level mapping but not SP level mapping, add it.
                if (!foundMatching) {
                    if (isUserClaimsLoggable) {
                        if (log.isDebugEnabled()) {
                            log.debug("IDP Claim mapping exist, but SP Claim mapping does not exist for " + key
                                    + ", hence adding value " + value + " for the user : " + authenticatedUser);
                        }
                    }
                    claimsAfterIDPandSPMapping.put(key, value);
                }
            }
        } else {
            // If the IDP level mapping is not there, all the claims coming from IDP are assumed to be local claim.
            ClaimMapping[] spClaimMapping = serviceProviderClaimConfig.getClaimMappings();
            for (ClaimMapping claimMapping : spClaimMapping) {
                if (claimMapping.getLocalClaim().getClaimUri().equals(key) && claimMapping.isRequested()) {
                    foundMatching = true;
                    break;
                }
            }
            // If the attribute does not have the specific mapping in SP level, add the mapping.
            if (!foundMatching) {
                if (isUserClaimsLoggable) {
                    if (log.isDebugEnabled()) {
                        log.debug("SP Claim mapping does not exist for " + key + ", hence adding value " + value
                                + " for the user : " + authenticatedUser);
                    }
                }
                claimsAfterIDPandSPMapping.put(key, value);
            }
        }
    });
    if (isUserClaimsLoggable) {
        if (log.isDebugEnabled()) {
            log.debug("Final set of claims for the user : " + authenticatedUser + ": "
                    + claimsAfterIDPandSPMapping.toString());
        }
    }
    return claimsAfterIDPandSPMapping;
}

From source file:org.wso2.carbon.identity.openidconnect.dao.ScopeClaimMappingDAOImpl.java

@Override
public void addScopes(int tenantId, List<ScopeDTO> scopeClaimsList) throws IdentityOAuth2Exception {

    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();

    scopeClaimsList.forEach(rethrowConsumer(scopeDTO -> {
        String scope = scopeDTO.getName();
        String[] claims = scopeDTO.getClaim();
        try {/*from ww  w.  ja v  a  2s.c om*/
            if (!isScopeExist(scope, tenantId)) {
                int scopeClaimMappingId = jdbcTemplate.withTransaction(tempate -> tempate
                        .executeInsert(SQLQueries.STORE_IDN_OIDC_SCOPES, (preparedStatement -> {
                            preparedStatement.setString(1, scope);
                            preparedStatement.setInt(2, tenantId);
                        }), null, true));
                if (scopeClaimMappingId > 0 && ArrayUtils.isNotEmpty(claims)) {
                    Set<String> claimsSet = new HashSet<>(Arrays.asList(claims));
                    insertClaims(tenantId, scopeClaimMappingId, claimsSet);
                }
                if (log.isDebugEnabled() && ArrayUtils.isNotEmpty(claims)) {
                    log.debug("The scope: " + scope + " and the claims: " + Arrays.asList(claims)
                            + "are successfully" + " inserted for the tenant: " + tenantId);
                }
            } else {
                String errorMessage = "Error while adding scopes. Duplicate scopes can not be added for the tenant: "
                        + tenantId;
                throw new IdentityOAuth2Exception(errorMessage);
            }
        } catch (TransactionException e) {
            String errorMessage = "Error while persisting new claims for the scope for the tenant: " + tenantId;
            throw new IdentityOAuth2Exception(errorMessage, e);
        }

    }));
}

From source file:org.wso2.carbon.identity.openidconnect.dao.ScopeClaimMappingDAOImpl.java

@Override
public void addScope(int tenantId, String scope, String[] claims) throws IdentityOAuth2Exception {

    if (!isScopeExist(scope, tenantId)) {
        JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
        try {/* ww w.ja  va  2  s.c  om*/
            int scopeClaimMappingId = jdbcTemplate.executeInsert(SQLQueries.STORE_IDN_OIDC_SCOPES,
                    (preparedStatement -> {
                        preparedStatement.setString(1, scope);
                        preparedStatement.setInt(2, tenantId);
                    }), null, true);
            if (scopeClaimMappingId > 0 && ArrayUtils.isNotEmpty(claims)) {
                Set<String> claimsSet = new HashSet<>(Arrays.asList(claims));
                insertClaims(tenantId, scopeClaimMappingId, claimsSet);
            }
            if (log.isDebugEnabled() && ArrayUtils.isNotEmpty(claims)) {
                log.debug("The scope: " + scope + " and the claims: " + Arrays.asList(claims)
                        + "are successfully" + " inserted for the tenant: " + tenantId);
            }
        } catch (DataAccessException e) {
            String errorMessage = "Error while persisting scopes for the tenant: " + tenantId;
            throw new IdentityOAuth2Exception(errorMessage, e);
        }
    } else {
        String errorMessage = "The Scope: " + scope + " is already existing.";
        throw new IdentityOAuth2Exception(errorMessage);
    }
}

From source file:org.wso2.carbon.identity.recovery.ui.Utils.java

public static List<String> getChallengeSetUris(ChallengeQuestion[] challengeQuestions) {
    HashSet<String> questionSetNames = new HashSet<String>();
    if (ArrayUtils.isNotEmpty(challengeQuestions)) {
        for (ChallengeQuestion question : challengeQuestions) {
            if (question.getQuestionSetId() != null) {
                questionSetNames.add(question.getQuestionSetId());
            }//from   ww  w .  java2  s  . c om
        }
    }
    List<String> challengeSetUriList = new ArrayList<String>(questionSetNames);
    Collections.sort(challengeSetUriList);
    return challengeSetUriList;
}

From source file:org.wso2.carbon.identity.workflow.impl.WorkflowImplServiceImpl.java

@Override
public void deleteHumanTask(WorkflowRequest workflowRequest) throws WorkflowImplException {
    BPSProfileDAO bpsProfileDAO = new BPSProfileDAO();
    List<WorkflowImplServiceListener> workflowListenerList = WorkflowImplServiceDataHolder.getInstance()
            .getWorkflowListenerList();//from   ww  w.  j a  v  a 2  s . c o m

    for (WorkflowImplServiceListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPreDeleteHumanTask(workflowRequest);
        }
    }
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    List<BPSProfile> bpsProfiles = bpsProfileDAO.listBPSProfiles(tenantId);
    HumanTaskClientAPIAdminClient client = null;
    TSimpleQueryInput input = new TSimpleQueryInput();
    TStatus reservedState = new TStatus();
    reservedState.setTStatus(WFImplConstant.HT_STATE_RESERVED);
    input.addStatus(reservedState);
    TStatus readyState = new TStatus();
    readyState.setTStatus(WFImplConstant.HT_STATE_READY);
    input.addStatus(readyState);
    input.setPageSize(WFImplConstant.DEFAULT_PAGE_SIZE_FOR_HT_LIST);
    input.setPageNumber(WFImplConstant.PAGE_0);
    input.setSimpleQueryCategory(TSimpleQueryCategory.ALL_TASKS);
    for (BPSProfile bpsProfile : bpsProfiles) {
        try {
            String host = bpsProfile.getWorkerHostURL();

            if (bpsProfile.getProfileName().equals(WFImplConstant.DEFAULT_BPS_PROFILE_NAME)) {

                client = new HumanTaskClientAPIAdminClient(host, bpsProfile.getUsername());
            } else {
                client = new HumanTaskClientAPIAdminClient(host, bpsProfile.getUsername(),
                        bpsProfile.getPassword());
            }
            TTaskSimpleQueryResultSet results = client.simpleQuery(input);
            TTaskSimpleQueryResultRow[] humanTasks = results.getRow();
            if (ArrayUtils.isNotEmpty(humanTasks)) {
                for (int j = 0; j < humanTasks.length; j++) {
                    try {
                        Object task = client.getInput(humanTasks[j].getId());
                        InputStream stream = new ByteArrayInputStream(
                                task.toString().getBytes(StandardCharsets.UTF_8));
                        OMElement taskXML = new StAXOMBuilder(stream).getDocumentElement();
                        Iterator<OMElementImpl> iterator = taskXML.getChildElements();
                        while (iterator.hasNext()) {
                            OMElementImpl child = iterator.next();
                            checkMatchingTaskAndDelete(workflowRequest.getRequestId(), client, humanTasks, j,
                                    child);
                        }
                    } catch (IllegalStateFault | XMLStreamException | IllegalArgumentFault | RemoteException
                            | IllegalOperationFault | IllegalAccessFault e) {
                        //If exception throws when retrieving and deleting a specific task, it will continue with
                        // other tasks without terminating.
                        log.warn("Failed to retrieve information of human task : " + humanTasks[j].getName()
                                + ".");
                    }
                }
            }
        } catch (IllegalArgumentFault | RemoteException | IllegalStateFault e) {
            //If exception throws at one iteration of loop, which is testing 1 BPS profile, it will continue with
            // other profiles without terminating.
            log.warn("Failed to delete human task associated for this request in BPS profile : "
                    + bpsProfile.getProfileName());
        }
    }
    for (WorkflowImplServiceListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPostDeleteHumanTask(workflowRequest);
        }
    }
}

From source file:org.wso2.carbon.idp.mgt.IdentityProviderManagementService.java

/**
 * @return/* ww  w  .j  a v a2s.c om*/
 * @throws IdentityProviderManagementException
 */
public String[] getAllLocalClaimUris() throws IdentityProviderManagementException {
    try {
        String claimDialect = LOCAL_DEFAULT_CLAIM_DIALECT;
        ClaimMapping[] claimMappings = CarbonContext.getThreadLocalCarbonContext().getUserRealm()
                .getClaimManager().getAllClaimMappings(claimDialect);
        List<String> claimUris = new ArrayList<String>();
        for (ClaimMapping claimMap : claimMappings) {
            claimUris.add(claimMap.getClaim().getClaimUri());
        }
        String[] allLocalClaimUris = claimUris.toArray(new String[claimUris.size()]);
        if (ArrayUtils.isNotEmpty(allLocalClaimUris)) {
            Arrays.sort(allLocalClaimUris);
        }
        return allLocalClaimUris;
    } catch (Exception e) {
        String message = "Error while reading system claims";
        log.error(message, e);
        throw new IdentityProviderManagementException(message);
    }
}

From source file:org.wso2.carbon.user.mgt.listeners.UserManagementAuditLogger.java

@Override
public boolean doPostAddUser(String userName, Object credential, String[] roleList, Map<String, String> claims,
        String profile, UserStoreManager userStoreManager) {

    if (isEnable()) {
        JSONObject data = new JSONObject();
        data.put(ListenerUtils.CLAIMS_FIELD, new JSONObject(claims));
        if (ArrayUtils.isNotEmpty(roleList)) {
            data.put(ListenerUtils.ROLES_FIELD, new JSONArray(roleList));
        }//  w  w  w  .  j  av  a2s .c  o m
        data.put(ListenerUtils.PROFILE_FIELD, profile);
        audit.warn(createAuditMessage(ListenerUtils.ADD_USER_ACTION,
                ListenerUtils.getEntityWithUserStoreDomain(userName, userStoreManager), data, SUCCESS));
    }
    return true;
}

From source file:org.wso2.carbon.user.mgt.listeners.UserManagementAuditLogger.java

@Override
public boolean doPostAddRole(String roleName, String[] userList, Permission[] permissions,
        UserStoreManager userStoreManager) {

    if (isEnable()) {
        JSONObject dataObject = new JSONObject();
        if (ArrayUtils.isNotEmpty(userList)) {
            dataObject.put(ListenerUtils.USERS_FIELD, new JSONArray(userList));
        }//  w  ww  .  ja  v a2s  .c om
        if (ArrayUtils.isNotEmpty(permissions)) {
            JSONArray permissionsArray = new JSONArray(permissions);
            dataObject.put(ListenerUtils.PERMISSIONS_FIELD, permissionsArray);
        }
        audit.warn(createAuditMessage(ListenerUtils.ADD_ROLE_ACTION,
                ListenerUtils.getEntityWithUserStoreDomain(roleName, userStoreManager), dataObject, SUCCESS));
    }
    return true;
}

From source file:org.wso2.carbon.user.mgt.listeners.UserManagementAuditLogger.java

@Override
public boolean doPostUpdatePermissionsOfRole(String roleName, Permission[] permissions,
        UserStoreManager userStoreManager) {

    if (isEnable()) {
        JSONObject dataObject = new JSONObject();
        if (ArrayUtils.isNotEmpty(permissions)) {
            JSONArray permissionsArray = new JSONArray(permissions);
            dataObject.put(ListenerUtils.PERMISSIONS_FIELD, permissionsArray);
        }//from   w w  w  . j  a v  a2s  . co m

        audit.warn(createAuditMessage(ListenerUtils.UPDATE_PERMISSIONS_OF_ROLE_ACTION,
                ListenerUtils.getEntityWithUserStoreDomain(roleName, userStoreManager), dataObject, SUCCESS));
    }
    return true;
}

From source file:org.wso2.carbon.user.mgt.listeners.UserManagementAuditLogger.java

@Override
public boolean doPostUpdateUserListOfRole(String roleName, String[] deletedUsers, String[] newUsers,
        UserStoreManager userStoreManager) {

    if (isEnable()) {
        JSONObject dataObject = new JSONObject();
        if (ArrayUtils.isNotEmpty(deletedUsers)) {
            dataObject.put(ListenerUtils.DELETED_USERS, new JSONArray(deletedUsers));
        }/*from  w w w  . ja va  2s .  c  o  m*/
        if (ArrayUtils.isNotEmpty(newUsers)) {
            dataObject.put(ListenerUtils.NEW_USERS, new JSONArray(newUsers));
        }
        audit.info(createAuditMessage(ListenerUtils.UPDATE_USERS_OF_ROLE_ACTION,
                ListenerUtils.getEntityWithUserStoreDomain(roleName, userStoreManager), dataObject, SUCCESS));
    }
    return true;
}