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

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

Introduction

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

Prototype

public static short[] removeElement(short[] array, short element) 

Source Link

Document

Removes the first occurrence of the specified element from the specified array.

Usage

From source file:org.wso2.carbon.appfactory.tenant.mgt.util.AppFactoryTenantMgtUtil.java

/**
 * Removes admin and everyone role from the set of roles
 * /*from www . ja va 2  s.  c o m*/
 * @param roles
 * @return
 */
public static String[] removeEveryoneRoles(String[] roles) {
    String everyOneRoleName = getRealmService().getBootstrapRealmConfiguration().getEveryOneRoleName();
    return (String[]) ArrayUtils.removeElement(roles, everyOneRoleName);
}

From source file:org.wso2.carbon.directory.server.manager.DirectoryServerApplicationMgtListener.java

@Override
public void doExportServiceProvider(ServiceProvider serviceProvider, Boolean exportSecrets)
        throws IdentityApplicationManagementException {

    InboundAuthenticationConfig inboundAuthenticationConfig = serviceProvider.getInboundAuthenticationConfig();
    if (inboundAuthenticationConfig != null
            && inboundAuthenticationConfig.getInboundAuthenticationRequestConfigs() != null) {
        for (InboundAuthenticationRequestConfig authConfig : inboundAuthenticationConfig
                .getInboundAuthenticationRequestConfigs()) {
            if (KERBEROS.equals(authConfig.getInboundAuthType())) {
                inboundAuthenticationConfig.setInboundAuthenticationRequestConfigs(
                        (InboundAuthenticationRequestConfig[]) ArrayUtils.removeElement(
                                inboundAuthenticationConfig.getInboundAuthenticationRequestConfigs(),
                                authConfig));
                return;
            }/*from  w  w  w . j  a v  a  2s. com*/
        }
    }
}

From source file:org.wso2.carbon.governance.lcm.internal.LifeCycleServiceImpl.java

private LCStateBean getCheckListItems(Resource artifactResource, String artifactLC, String[] roleNames,
        UserRegistry registry) throws RegistryException {

    String artifactLCState = artifactResource.getProperty("registry.lifecycle." + artifactLC + ".state");

    LCStateBean lifeCycleStateBean = new LCStateBean();
    if (artifactLCState == null) {
        return lifeCycleStateBean;
    }// w  w w  .j a  v a 2  s  .  c  o  m
    lifeCycleStateBean.setLifeCycleName(artifactLC);
    lifeCycleStateBean.setLifeCycleState(artifactLCState);

    List<LifeCycleCheckListItemBean> checkListItemList = new ArrayList<>();
    List<LifeCycleApprovalBean> lifeCycleApprovalBeanList = new ArrayList<>();

    String[] aspectActions = registry.getAspectActions(artifactResource.getPath(), artifactLC);
    if (aspectActions != null && aspectActions.length > 0) {
        LifeCycleActionsBean lifecycleActionsEntry = new LifeCycleActionsBean();
        lifecycleActionsEntry.setLifecycle(artifactLC);
        lifecycleActionsEntry.setActions(aspectActions);
        lifeCycleStateBean.setLifeCycleActionsBean(lifecycleActionsEntry);
    }

    Properties lifecycleProps = artifactResource.getProperties();

    List<String> permissionList = new ArrayList();
    List<String> approvePermissionList = new ArrayList();

    Map<String, List<LifeCycleInputBean>> lifeCycleInputBeanMap = new HashMap();

    Set propertyKeys = lifecycleProps.keySet();

    for (Object propertyObj : propertyKeys) {
        String propertyKey = (String) propertyObj;
        String checkListPrefix = "registry.custom_lifecycle.checklist.";
        String permissionSuffix = ".item.permission";

        String votePrefix = "registry.custom_lifecycle.votes.";
        String votePermissionSuffix = ".vote.permission";
        if (propertyKey.startsWith(checkListPrefix) && propertyKey.endsWith(permissionSuffix)
                && propertyKey.contains(GovernanceConstants.LIFECYCLE_PROPERTY_SEPERATOR + artifactLC
                        + GovernanceConstants.LIFECYCLE_PROPERTY_SEPERATOR)) {
            for (String role : roleNames) {
                List<String> propValues = (List<String>) lifecycleProps.get(propertyKey);
                for (String propValue : propValues) {
                    String key = propertyKey.replace(checkListPrefix, "").replace(permissionSuffix, "");
                    if (propValue.equals(role)) {
                        permissionList.add(key);
                    } else if (propValue.startsWith(checkListPrefix) && propValue.endsWith(permissionSuffix)) {
                        permissionList.add(key);
                    }
                }
            }
        }
        if (propertyKey.startsWith(votePrefix) && propertyKey.endsWith(votePermissionSuffix)
                && propertyKey.contains(GovernanceConstants.LIFECYCLE_PROPERTY_SEPERATOR + artifactLC
                        + GovernanceConstants.LIFECYCLE_PROPERTY_SEPERATOR)) {
            for (String role : roleNames) {
                List<String> propValues = (List<String>) lifecycleProps.get(propertyKey);
                for (String propValue : propValues) {
                    String key = propertyKey.replace(votePrefix, "").replace(votePermissionSuffix, "");
                    if (propValue.equals(role)) {
                        approvePermissionList.add(key);
                    } else if (propValue.startsWith(votePrefix) && propValue.endsWith(votePermissionSuffix)) {
                        approvePermissionList.add(key);
                    }
                }
            }
        }
    }
    String lifecyleInputs = REGISTRY_CUSTOM_LIFECYCLE_INPUTS;
    for (Object key : lifecycleProps.keySet()) {
        if (key.toString().startsWith(lifecyleInputs + artifactLC + "." + artifactLCState)) {
            List<String> propValues = (List<String>) lifecycleProps.get(key);
            LifeCycleInputBean lifeCycleInputBean = new LifeCycleInputBean();
            lifeCycleInputBean.setName(propValues.get(1));
            lifeCycleInputBean.setRequired(Boolean.getBoolean(propValues.get(2)));
            lifeCycleInputBean.setLabel(propValues.get(3));
            lifeCycleInputBean.setPlaceHolder(propValues.get(4));
            lifeCycleInputBean.setTooltip(propValues.get(5));
            lifeCycleInputBean.setRegex(propValues.get(6));
            List<LifeCycleInputBean> lifeCycleInputBeanList = lifeCycleInputBeanMap.get(propValues.get(0));
            if (lifeCycleInputBeanList == null) {
                lifeCycleInputBeanList = new ArrayList<LifeCycleInputBean>();
            }
            lifeCycleInputBeanList.add(lifeCycleInputBean);
            lifeCycleInputBeanMap.put(propValues.get(0), lifeCycleInputBeanList);
        }
    }

    for (Object propertyObj : propertyKeys) {
        String propertyKey = (String) propertyObj;

        String checkListPrefix = "registry.custom_lifecycle.checklist.";
        String checkListSuffix = ".item";

        String prefixVote = "registry.custom_lifecycle.votes.";
        String suffixVote = ".vote";

        if (propertyKey.startsWith(checkListPrefix) && propertyKey.endsWith(checkListSuffix)
                && propertyKey.contains(GovernanceConstants.LIFECYCLE_PROPERTY_SEPERATOR + artifactLC
                        + GovernanceConstants.LIFECYCLE_PROPERTY_SEPERATOR)) {
            List<String> propValues = (List<String>) lifecycleProps.get(propertyKey);
            LifeCycleCheckListItemBean checkListItem = new LifeCycleCheckListItemBean();
            if (propValues != null && propValues.size() > 2) {
                for (String param : propValues) {
                    if ((param.startsWith("status:"))) {
                        checkListItem.setStatus(param.substring(7));
                    } else if ((param.startsWith("name:"))) {
                        checkListItem.setName(param.substring(5));
                    } else if ((param.startsWith("value:"))) {
                        checkListItem.setValue(Boolean.parseBoolean(param.substring(6)));
                    } else if ((param.startsWith("order:"))) {
                        checkListItem.setOrder(Integer.parseInt(param.substring(6)));
                    }
                }
            }
            String key = propertyKey.replace(checkListPrefix, "").replace(checkListSuffix, "");
            if (permissionList.contains(key)) {
                checkListItem.setVisible("true");
            }

            checkListItemList.add(checkListItem);
        } else if (propertyKey.startsWith(prefixVote) && propertyKey.endsWith(suffixVote)
                && propertyKey.contains(GovernanceConstants.LIFECYCLE_PROPERTY_SEPERATOR + artifactLC
                        + GovernanceConstants.LIFECYCLE_PROPERTY_SEPERATOR)) {
            List<String> propValues = (List<String>) lifecycleProps.get(propertyKey);
            LifeCycleApprovalBean approveItem = new LifeCycleApprovalBean();
            approveItem.setVisible("false");
            if (propValues != null && propValues.size() > 2) {
                for (String param : propValues) {
                    if ((param.startsWith("name:"))) {
                        approveItem.setName(param.substring(5));
                    }
                    if ((param.startsWith("users:"))) {
                        boolean userVoted = false;
                        String users = param.replace("users:", "");
                        String[] votedUsers = users.split(",");
                        userVoted = Arrays.asList(votedUsers).contains(registry.getUserName());
                        approveItem.setValue(userVoted);
                    }
                    if ((param.startsWith("votes:"))) {
                        approveItem.setRequiredVote(Integer.parseInt(param.substring(6)));
                    }
                    if ((param.startsWith("current:"))) {
                        approveItem.setCurrentVote(Integer.parseInt(param.substring(8)));
                    }
                    if ((param.startsWith("order:"))) {
                        approveItem.setOrder(Integer.parseInt(param.substring(6)));
                    }
                }
            }
            String key = propertyKey.replace(prefixVote, "").replace(suffixVote, "");

            if (approvePermissionList.contains(key)) {
                approveItem.setVisible("true");
            }
            if (lifeCycleStateBean.getLifeCycleActionsBean() != null) {
                LifeCycleActionsBean lifeCycleActionsBean = lifeCycleStateBean.getLifeCycleActionsBean();
                List<String> lcActionList = Arrays.asList(lifeCycleActionsBean.getActions());
                if (lcActionList.contains(approveItem.getName()) && ("true").equals(approveItem.getVisible())) {
                    lifeCycleApprovalBeanList.add(approveItem);
                }
                if (approveItem.getCurrentVote() < approveItem.getRequiredVote()) {
                    String[] newActions = (String[]) ArrayUtils.removeElement(lifeCycleActionsBean.getActions(),
                            approveItem.getName());
                    lifeCycleActionsBean.setActions(newActions);
                }
                lifeCycleStateBean.setLifeCycleActionsBean(lifeCycleActionsBean);
            }
        }

    }
    lifeCycleStateBean.setLifeCycleApprovalBeanList(lifeCycleApprovalBeanList);
    lifeCycleStateBean.setLifeCycleCheckListItemBeans(checkListItemList);
    lifeCycleStateBean.setLifeCycleInputBeanMap(lifeCycleInputBeanMap);

    return lifeCycleStateBean;
}

From source file:org.wso2.carbon.identity.application.common.processors.RandomPasswordProcessor.java

private Property[] removeUniqueIdProperty(Property[] properties) {

    if (ArrayUtils.isEmpty(properties)) {
        return new Property[0];
    }/*from  w  ww . ja  v  a 2  s  . c  om*/

    for (int i = 0; i < properties.length; i++) {
        if (properties[i] == null) {
            continue;
        }
        if (IdentityApplicationConstants.UNIQUE_ID_CONSTANT.equals(properties[i].getName())) {
            Property[] propertiesTemp = properties;

            if (log.isDebugEnabled()) {
                log.debug("Removing uniqueId property: " + properties[i].getName());
            }
            properties = (Property[]) ArrayUtils.removeElement(properties, properties[i]);
            //Removing uniqueId property from existing properties too
            propertiesTemp[i] = null;
        }
    }
    return properties;
}

From source file:org.wso2.carbon.identity.oauth2.internal.OAuthApplicationMgtListener.java

private void removeClientSecret(ServiceProvider serviceProvider) {
    InboundAuthenticationConfig inboundAuthenticationConfig = serviceProvider.getInboundAuthenticationConfig();
    if (inboundAuthenticationConfig != null) {
        InboundAuthenticationRequestConfig[] inboundRequestConfigs = inboundAuthenticationConfig
                .getInboundAuthenticationRequestConfigs();
        if (inboundRequestConfigs != null) {
            for (InboundAuthenticationRequestConfig inboundRequestConfig : inboundRequestConfigs) {
                if (inboundRequestConfig.getInboundAuthType().equals(OAUTH2)) {
                    Property[] props = inboundRequestConfig.getProperties();
                    for (Property prop : props) {
                        if (prop.getName().equalsIgnoreCase(OAUTH2_CONSUMER_SECRET)) {
                            props = (Property[]) ArrayUtils.removeElement(props, prop);
                            inboundRequestConfig.setProperties(props);
                            continue; //we are interested only on this property
                        } else {
                            //ignore
                        }/*from  ww w . java2  s .com*/
                    }
                    continue;// we are interested only on oauth2 config. Only one will be present.
                } else {
                    //ignore
                }
            }
        } else {
            //ignore
        }
    } else {
        //nothing to do
    }
}

From source file:org.wso2.carbon.identity.oauth2.validators.OIDCScopeHandler.java

@Override
public boolean validateScope(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception {

    Set<String> idTokenNotAllowedGrantTypesSet = OAuthServerConfiguration.getInstance()
            .getIdTokenNotAllowedGrantTypesSet();
    String grantType = tokReqMsgCtx.getOauth2AccessTokenReqDTO().getGrantType();
    // validating the authorization_code grant type with openid scope ignoring the IdTokenAllowed element defined
    // in the identity.xml
    if (GrantType.AUTHORIZATION_CODE.toString().equals(grantType)) {
        return true;
    } else if (!idTokenNotAllowedGrantTypesSet.contains(grantType)) {
        // if id_token is allowed for requested grant type.
        return true;
    } else {//from  www.j av a 2 s  .c om
        // Remove openid scope from the token message context.
        String[] scopes = (String[]) ArrayUtils.removeElement(tokReqMsgCtx.getScope(),
                OAuthConstants.Scope.OPENID);
        tokReqMsgCtx.setScope(scopes);
        if (log.isDebugEnabled()) {
            log.debug("id_token is not allowed for requested grant type: " + grantType + ". Removing 'openid' "
                    + "scope.");
        }
        // Returning 'true' since we are dropping openid scope and don't need to prevent issuing the token for
        // remaining scopes.
        return true;
    }
}

From source file:org.wso2.identity.integration.test.auth.AbstractAdaptiveAuthenticationTestCase.java

protected void updateResidentIDP(IdentityProvider residentIdentityProvider) throws Exception {

    FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = residentIdentityProvider
            .getFederatedAuthenticatorConfigs();
    for (FederatedAuthenticatorConfig authenticatorConfig : federatedAuthenticatorConfigs) {
        if (!authenticatorConfig.getName().equalsIgnoreCase("samlsso")) {
            federatedAuthenticatorConfigs = (FederatedAuthenticatorConfig[]) ArrayUtils
                    .removeElement(federatedAuthenticatorConfigs, authenticatorConfig);
        }/*from ww  w.j  av a2 s. c om*/
    }
    residentIdentityProvider.setFederatedAuthenticatorConfigs(federatedAuthenticatorConfigs);
    superTenantIDPMgtClient.updateResidentIdP(residentIdentityProvider);
}

From source file:org.wso2.identity.integration.test.consent.SelfSignUpConsentTest.java

private void updateResidentIDP(IdentityProvider residentIdentityProvider, boolean isSuperTenant)
        throws Exception {

    FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = residentIdentityProvider
            .getFederatedAuthenticatorConfigs();
    for (FederatedAuthenticatorConfig authenticatorConfig : federatedAuthenticatorConfigs) {
        if (!authenticatorConfig.getName().equalsIgnoreCase("samlsso")) {
            federatedAuthenticatorConfigs = (FederatedAuthenticatorConfig[]) ArrayUtils
                    .removeElement(federatedAuthenticatorConfigs, authenticatorConfig);
        }//from  w w w .ja  v a2s.  c  o m
    }
    residentIdentityProvider.setFederatedAuthenticatorConfigs(federatedAuthenticatorConfigs);
    if (isSuperTenant) {
        superTenantIDPMgtClient.updateResidentIdP(residentIdentityProvider);
    } else {
        tenantIDPMgtClient.updateResidentIdP(residentIdentityProvider);
    }
}

From source file:paulscode.android.mupen64plusae.profile.TouchscreenProfileActivity.java

private void setHoldable(int n64Index, boolean holdable) {
    String index = String.valueOf(n64Index);

    // Get the serialized list from the profile
    String serialized = mProfile.get(TOUCHSCREEN_AUTOHOLDABLES, "");
    String[] holdables = serialized.split(AUTOHOLDABLES_DELIMITER);

    // Modify the list as necessary
    if (!holdable) {
        holdables = (String[]) ArrayUtils.removeElement(holdables, index);
    } else if (!ArrayUtils.contains(holdables, index)) {
        holdables = (String[]) ArrayUtils.add(holdables, index);
    }//from   www. j  a  v  a 2s  .co  m

    // Put the serialized list back into the profile
    serialized = TextUtils.join(AUTOHOLDABLES_DELIMITER, holdables);
    mProfile.put(TOUCHSCREEN_AUTOHOLDABLES, serialized);
}

From source file:pcgen.core.facade.util.SortedListFacade.java

@Override
public void elementRemoved(ListEvent<E> e) {
    int index = ArrayUtils.indexOf(transform, e.getIndex());
    transform = (Integer[]) ArrayUtils.removeElement(transform, transform.length - 1);
    sanityCheck();/*w  w  w  . j av  a 2 s.c  o  m*/
    Arrays.sort(transform, indexComparator);
    fireElementRemoved(this, e.getElement(), index);
}