set custom response for profile's default client

@param profileName profileName to modify
@param pathName friendly name of path
@param customData custom request data
@return true if success, false otherwise
198304
public static boolean setCustomResponseForDefaultClient(String profileName, String pathName, String customData) {
        try {
            return setCustomForDefaultClient(profileName, pathName, true, customData);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
1093286
public void handleSsoPostProfileRequest(final HttpServletResponse response,
                                            final HttpServletRequest request,
                                            final BaseHttpServletRequestXMLMessageDecoder decoder) throws Exception {
        val authnRequest = getSamlProfileHandlerConfigurationContext().getSamlHttpRequestExtractor()
            .extract(request, decoder, AuthnRequest.class);
        initiateAuthenticationRequest(authnRequest, response, request);
    }
1171208
@RequestMapping(value = "/pathname/{profileId}/{pathId}", method = RequestMethod.GET)
    public String editPathname(Model model,
                               @PathVariable int pathId, @PathVariable int profileId) throws Exception {
        model.addAttribute("profile_id", profileId);
        model.addAttribute("profile_name", ProfileService.getInstance().getNamefromId(profileId));
        model.addAttribute("endpoint", pathOverrideService.getPath(pathId));
        model.addAttribute("groups_in_path", pathOverrideService.getGroupsInPathProfile(profileId, pathId));
        model.addAttribute("groups_not_in_path", pathOverrideService.getGroupsNotInPathProfile(profileId, pathId));
        return "editPathname";
    }
1239391
public void verifySamlProfileRequestIfNeeded(final RequestAbstractType profileRequest,
                                                 final SamlRegisteredServiceServiceProviderMetadataFacade adaptor,
                                                 final HttpServletRequest request,
                                                 final MessageContext context) throws Exception {

        verifySamlProfileRequestIfNeeded(profileRequest, adaptor.getMetadataResolver(), request, context);
    }
1102882
public boolean addMethodToResponseOverride(String pathName, String methodName) {
        // need to find out the ID for the method
        // TODO: change api for adding methods to take the name instead of ID
        try {
            Integer overrideId = getOverrideIdForMethodName(methodName);

            // now post to path api to add this is a selected override
            BasicNameValuePair[] params = {
                new BasicNameValuePair("addOverride", overrideId.toString()),
                new BasicNameValuePair("profileIdentifier", this._profileName)
            };
            JSONObject response = new JSONObject(doPost(BASE_PATH + uriEncode(pathName), params));
            // check enabled endpoints array to see if this overrideID exists
            JSONArray enabled = response.getJSONArray("enabledEndpoints");
            for (int x = 0; x < enabled.length(); x++) {
                if (enabled.getJSONObject(x).getInt("overrideId") == overrideId) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return false;
    }
559767
public int addPathnameToProfile(int id, String pathname, String actualPath) throws Exception {
        int pathOrder = getPathOrder(id).size() + 1;
        int pathId = -1;
        PreparedStatement statement = null;
        ResultSet results = null;

        try (Connection sqlConnection = sqlService.getConnection()) {
            statement = sqlConnection.prepareStatement(
                "INSERT INTO " + Constants.DB_TABLE_PATH
                    + "(" + Constants.PATH_PROFILE_PATHNAME + ","
                    + Constants.PATH_PROFILE_ACTUAL_PATH + ","
                    + Constants.PATH_PROFILE_GROUP_IDS + ","
                    + Constants.PATH_PROFILE_PROFILE_ID + ","
                    + Constants.PATH_PROFILE_PATH_ORDER + ","
                    + Constants.PATH_PROFILE_CONTENT_TYPE + ","
                    + Constants.PATH_PROFILE_REQUEST_TYPE + ","
                    + Constants.PATH_PROFILE_GLOBAL + ")"
                    + " VALUES (?, ?, ?, ?, ?, ?, ?, ?);",
                PreparedStatement.RETURN_GENERATED_KEYS
            );
            statement.setString(1, pathname);
            statement.setString(2, actualPath);
            statement.setString(3, "");
            statement.setInt(4, id);
            statement.setInt(5, pathOrder);
            statement.setString(6, Constants.PATH_PROFILE_DEFAULT_CONTENT_TYPE); // should be set by UI/API
            statement.setInt(7, Constants.REQUEST_TYPE_GET); // should be set by UI/API
            statement.setBoolean(8, false);
            statement.executeUpdate();

            // execute statement and get resultSet which will have the generated path ID as the first field
            results = statement.getGeneratedKeys();

            if (results.next()) {
                pathId = results.getInt(1);
            } else {
                // something went wrong
                throw new Exception("Could not add path");
            }
        } catch (SQLException e) {
            throw e;
        } finally {
            try {
                if (results != null) {
                    results.close();
                }
            } catch (Exception e) {
            }
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }

        // need to add to request response table for all clients
        for (Client client : ClientService.getInstance().findAllClients(id)) {
            this.addPathToRequestResponseTable(id, client.getUUID(), pathId);
        }

        return pathId;
    }
1039137
@GetMapping(path = SamlIdPConstants.ENDPOINT_SAML2_SSO_PROFILE_POST_CALLBACK)
    protected void handleCallbackProfileRequest(final HttpServletResponse response, final HttpServletRequest request) throws Exception {
        LOGGER.info("Received SAML callback profile request [{}]", request.getRequestURI());
        val authnRequest = retrieveSamlAuthenticationRequestFromHttpRequest(request);
        if (authnRequest == null) {
            LOGGER.error("Can not validate the request because the original Authn request can not be found.");
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
            return;
        }

        val ticket = CommonUtils.safeGetParameter(request, CasProtocolConstants.PARAMETER_TICKET);
        if (StringUtils.isBlank(ticket)) {
            LOGGER.error("Can not validate the request because no [{}] is provided via the request", CasProtocolConstants.PARAMETER_TICKET);
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
            return;
        }

        val authenticationContext = buildAuthenticationContextPair(request, authnRequest);
        val assertion = validateRequestAndBuildCasAssertion(response, request, authenticationContext);
        val binding = determineProfileBinding(authenticationContext, assertion);
        buildSamlResponse(response, request, authenticationContext, assertion, binding);
    }
1200559
public boolean uploadConfigurationAndProfile(String fileName, String odoImport) {
        File file = new File(fileName);
        MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
        FileBody fileBody = new FileBody(file, ContentType.MULTIPART_FORM_DATA);
        multipartEntityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        multipartEntityBuilder.addPart("fileData", fileBody);
        multipartEntityBuilder.addTextBody("odoImport", odoImport);
        try {
            JSONObject response = new JSONObject(doMultipartPost(BASE_BACKUP_PROFILE + "/" + uriEncode(this._profileName) + "/" + this._clientId, multipartEntityBuilder));
            if (response.length() == 0) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            return false;
        }
    }
186686
public void setData(final String path, byte data[], int version,
            StatCallback cb, Object ctx) {
        verbotenThreadCheck();
        final String clientPath = path;
        PathUtils.validatePath(clientPath);

        final String serverPath = prependChroot(clientPath);

        RequestHeader h = new RequestHeader();
        h.setType(ZooDefs.OpCode.setData);
        SetDataRequest request = new SetDataRequest();
        request.setPath(serverPath);
        request.setData(data);
        request.setVersion(version);
        SetDataResponse response = new SetDataResponse();
        cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
                clientPath, serverPath, ctx, null);
    }
119403
public ProfilePolicyMetadata[] queryPolicyMetadata(String[] policyName, Profile profile) throws RuntimeFault, RemoteException {
        return getVimService().queryPolicyMetadata(getMOR(), policyName, profile == null ? null : profile.getMOR());
    }
1224911
public static String getClientIdFromAuthenticatedProfile(final CommonProfile profile) {
        if (profile.containsAttribute(OAuth20Constants.CLIENT_ID)) {
            val attribute = profile.getAttribute(OAuth20Constants.CLIENT_ID);
            return CollectionUtils.toCollection(attribute, ArrayList.class).get(0).toString();
        }
        return null;
    }
538350
public void getProfile(@NonNull final String profileId, @Nullable Callback<ComapiResult<Map<String, Object>>> callback) {
        adapter.adapt(getProfile(profileId), callback);
    }
724864
public static <U extends UserProfile> Optional<U> flatIntoOneProfile(final Collection<U> profiles) {
        final Optional<U> profile = profiles.stream().filter(p -> p != null && !(p instanceof AnonymousProfile)).findFirst();
        if (profile.isPresent()) {
            return profile;
        } else {
            return profiles.stream().filter(p -> p != null).findFirst();
        }
    }
1196967
public void setCustomRequest(int pathId, String customRequest, String clientUUID) {
        PreparedStatement statement = null;

        try (Connection sqlConnection = sqlService.getConnection()) {
            int profileId = EditService.getProfileIdFromPathID(pathId);
            statement = sqlConnection.prepareStatement(
                "UPDATE " + Constants.DB_TABLE_REQUEST_RESPONSE +
                    " SET " + Constants.REQUEST_RESPONSE_CUSTOM_REQUEST + "= ?" +
                    " WHERE " + Constants.GENERIC_PROFILE_ID + "= ?" +
                    " AND " + Constants.GENERIC_CLIENT_UUID + "= ?" +
                    " AND " + Constants.REQUEST_RESPONSE_PATH_ID + "= ?"
            );
            statement.setString(1, customRequest);
            statement.setInt(2, profileId);
            statement.setString(3, clientUUID);
            statement.setInt(4, pathId);
            statement.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
    }
695633
public void removeCustomOverride(int path_id, String client_uuid) throws Exception {
        updateRequestResponseTables("custom_response", "", getProfileIdFromPathID(path_id), client_uuid, path_id);
    }
977521
public void updatePathOrder(int profileId, int[] pathOrder) {
        for (int i = 0; i < pathOrder.length; i++) {
            EditService.updatePathTable(Constants.PATH_PROFILE_PATH_ORDER, (i + 1), pathOrder[i]);
        }
    }
622796
@SuppressWarnings({"unused", "WeakerAccess"})
    public void pushProfile(final Map<String, Object> profile) {
        if (profile == null || profile.isEmpty())
            return;

        postAsyncSafely("profilePush", new Runnable() {
            @Override
            public void run() {
                _push(profile);
            }
        });
    }