Adds a redirect URL to the specified profile ID

@param model
@param profileId
@param srcUrl
@param destUrl
@param hostHeader
@return
@throws Exception
499361
@RequestMapping(value = "api/edit/server", method = RequestMethod.POST)
    public
    @ResponseBody
    ServerRedirect addRedirectToProfile(Model model,
                                        @RequestParam(value = "profileId", required = false) Integer profileId,
                                        @RequestParam(value = "profileIdentifier", required = false) String profileIdentifier,
                                        @RequestParam(value = "srcUrl", required = true) String srcUrl,
                                        @RequestParam(value = "destUrl", required = true) String destUrl,
                                        @RequestParam(value = "clientUUID", required = true) String clientUUID,
                                        @RequestParam(value = "hostHeader", required = false) String hostHeader) throws Exception {
        if (profileId == null && profileIdentifier == null) {
            throw new Exception("profileId required");
        }
        if (profileId == null) {
            profileId = ProfileService.getInstance().getIdFromName(profileIdentifier);
        }

        int clientId = ClientService.getInstance().findClient(clientUUID, profileId).getId();

        int redirectId = ServerRedirectService.getInstance().addServerRedirectToProfile("", srcUrl, destUrl, hostHeader,
                profileId, clientId);
        return ServerRedirectService.getInstance().getRedirect(redirectId);
    }
996893
@Override
    public Result call(final Route route, final RequestContext context) throws Exception {
        URI redirectedURI = rewriteURI(context.request());
        logger.debug("Redirecting request - rewriting {} to {}", context.request().uri(), redirectedURI);
        if (redirectedURI == null) {
            return onRewriteFailed(context);
        }
        return Results.redirect(redirectedURI.toString());
    }
109315
protected HttpBuilder redirect(URL url) {
        RedirectResponse resp = new RedirectResponse(url);
        RequestContext.setControllerResponse(resp);
        return new HttpBuilder(resp);
    }
1121334
@RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(Locale locale, Model model) {
        return "redirect:profiles";
    }
894873
@RequestMapping(value = "/api/profile/{profileIdentifier}", method = RequestMethod.GET)
    public
    @ResponseBody
    HashMap<String, Object> getProfile(Model model, @PathVariable String profileIdentifier) throws Exception {
        Integer profileId = ControllerUtils.convertProfileIdentifier(profileIdentifier);
        return Utils.getJQGridJSON(profileService.findProfile(profileId), "profile");
    }
1044008
@Override
  public void doFilter(ServletRequest sReq, ServletResponse sRes, FilterChain chain) throws IOException, ServletException
  {
    HttpServletRequest req = (HttpServletRequest) sReq;
    HttpServletResponse res = (HttpServletResponse) sRes;
    if (shouldProfile(req.getRequestURI()))
    {
      String queryString = req.getQueryString();
      String requestId = String.valueOf(counter.incrementAndGet());

      String redirectRequestIds = null;
      if (!isEmpty(queryString))
      {
        String[] parts = queryString.split("&");
        for (String part : parts)
        {
          String[] nameValue = part.split("=");
          if (REQUEST_ID_PARAM_REDIRECT.equals(nameValue[0]))
          {
            redirectRequestIds = nameValue[1];
            break;
          }
        }
      }

      req.setAttribute(REQUEST_ID_ATTRIBUTE, requestId);
      res.addHeader(REQUEST_ID_HEADER, redirectRequestIds != null ? redirectRequestIds + "," + requestId : requestId);

      addIncludes(req);

      ResponseWrapper resWrapper = new ResponseWrapper(res, requestId, redirectRequestIds);
      MiniProfiler.Profile profile = null;
      long startTime = System.currentTimeMillis();
      MiniProfiler.start();
      try
      {
        chain.doFilter(sReq, resWrapper);
      } finally
      {
        profile = MiniProfiler.stop();
      }

      Map<String, Object> requestData = new HashMap<String, Object>();
      requestData.put("requestURL", req.getRequestURI() + ((req.getQueryString() != null) ? "?" + req.getQueryString() : ""));
      requestData.put("timestamp", startTime);
      requestData.put("redirect", resWrapper.getDidRedirect());
      String appstatsId = resWrapper.getAppstatsId();
      if (appstatsId != null)
      {
        requestData.put("appstatsId", appstatsId);
      }
      requestData.put("profile", profile);
      ms.put(String.format(MEMCACHE_KEY_FORMAT_STRING, requestId), requestData, Expiration.byDeltaSeconds(dataExpiry));
    } else
    {
      chain.doFilter(sReq, sRes);
    }
  }
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);
    }
735546
@Override
  public void doPushProfileRequest(ClientCxDxSession appSession, JPushProfileRequest request) throws InternalException,
  IllegalDiameterStateException, RouteException, OverloadException {
    logger.info("Diameter Cx/Dx Session Factory :: doPushProfileRequest :: appSession[{}], Request[{}]", appSession, request);
  }
538350
public void getProfile(@NonNull final String profileId, @Nullable Callback<ComapiResult<Map<String, Object>>> callback) {
        adapter.adapt(getProfile(profileId), callback);
    }
254030
public static void putUnauthorizedRedirectUrlIntoFlowScope(final RequestContext context, final URI url) {
        context.getFlowScope().put(PARAMETER_UNAUTHORIZED_REDIRECT_URL, url);
    }
1169066
@RequestMapping(path = SamlIdPConstants.ENDPOINT_SAML2_SSO_PROFILE_REDIRECT, method = {RequestMethod.HEAD})
    public void handleSaml2ProfileSsoRedirectHeadRequest(final HttpServletResponse response,
                                                         final HttpServletRequest request) {
        LOGGER.info("Endpoint [{}] called with HTTP HEAD returning 400 Bad Request", SamlIdPConstants.ENDPOINT_SAML2_SSO_PROFILE_REDIRECT);
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    }
49920
public function it_throws_circular_redirection_exception_on_redirect_that_does_not_change_url(
        UriInterface $redirectUri,
        RequestInterface $request,
        ResponseInterface $redirectResponse
    ) {
        $redirectResponse->getStatusCode()->willReturn(302);
        $redirectResponse->hasHeader('Location')->willReturn(true);
        $redirectResponse->getHeaderLine('Location')->willReturn('/redirect');

        $next = function () use ($redirectResponse): Promise {
            return new HttpFulfilledPromise($redirectResponse->getWrappedObject());
        };

        $first = function () {
            throw new \Exception('First should never be called');
        };

        $request->getUri()->willReturn($redirectUri);
        $redirectUri->__toString()->willReturn('/redirect');

        $redirectUri->withPath('/redirect')->willReturn($redirectUri);
        $redirectUri->withFragment('')->willReturn($redirectUri);
        $redirectUri->withQuery('')->willReturn($redirectUri);

        $request->withUri($redirectUri)->willReturn($request);
        $redirectUri->__toString()->willReturn('/redirect');
        $request->getMethod()->willReturn('GET');

        $promise = $this->handleRequest($request, $next, $first);
        $promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class);
        $promise->shouldThrow(CircularRedirectionException::class)->duringWait();
    }
1096336
public void configure() throws Exception {

        final String hostname = host.startsWith("http") ? host : "http://" + host;

        /**
         * A generic error handler (specific to this RouteBuilder)
         */
        onException(Exception.class)
            .maximumRedeliveries("{{error.maxRedeliveries}}")
            .log("Index Routing Error: ${routeId}");

        /**
         * Expose a RESTful endpoint for re-indexing
         */
        from("jetty:" + hostname + ":" + port + "{{rest.prefix}}?matchOnUriPrefix=true&httpMethodRestrict=GET,POST")
            .routeId("FcrepoReindexingRest")
            .routeDescription("Expose the reindexing endpoint over HTTP")
            .setHeader(FCREPO_URI).simple("{{fcrepo.baseUrl}}${headers.CamelHttpPath}")
            .choice()
                .when(header(HTTP_METHOD).isEqualTo("GET")).to("direct:usage")
                .otherwise().to("direct:reindex");

        from("direct:usage").routeId("FcrepoReindexingUsage")
            .setHeader(REINDEXING_PREFIX).simple("{{rest.prefix}}")
            .setHeader(REINDEXING_PORT).simple(port)
            .setHeader(FCREPO_BASE_URL).simple("{{fcrepo.baseUrl}}")
            .process(exchange -> {
                exchange.getIn().setHeader(REINDEXING_HOST, getLocalHost().getHostName());
            })
            .to("mustache:org/fcrepo/camel/reindexing/usage.mustache");

        /**
         * A Re-indexing endpoint, setting where in the fcrepo hierarchy
         * a re-indexing operation should begin.
         */
        from("direct:reindex").routeId("FcrepoReindexingReindex")
            .process(new RestProcessor())
            .removeHeaders("CamelHttp*")
            .removeHeader("JMSCorrelationID")
            .setBody(constant(null))
            .choice()
                .when(header(HTTP_RESPONSE_CODE).isGreaterThanOrEqualTo(BAD_REQUEST))
                    .endChoice()
                .when(header(REINDEXING_RECIPIENTS).isEqualTo(""))
                    .transform().simple("No endpoints configured for indexing")
                    .endChoice()
                .otherwise()
                    .log(INFO, LOGGER, "Initial indexing path: ${headers[CamelFcrepoUri]}")
                    .inOnly("{{reindexing.stream}}?disableTimeToLive=true")
                    .setHeader(CONTENT_TYPE).constant("text/plain")
                    .transform().simple("Indexing started at ${headers[CamelFcrepoUri]}");

        /**
         *  A route that traverses through a fedora heirarchy
         *  indexing nodes, as appropriate.
         */
        from("{{reindexing.stream}}?asyncConsumer=true").routeId("FcrepoReindexingTraverse")
            .inOnly("direct:recipients")
            .removeHeaders("CamelHttp*")
            .setHeader(HTTP_METHOD).constant(GET)
            .to("fcrepo:{{fcrepo.baseUrl}}?preferInclude=PreferContainment" +
                    "&preferOmit=ServerManaged&accept=application/n-triples")
            // split the n-triples stream on line breaks so that each triple is split into a separate message
            .split(body().tokenize("\\n")).streaming()
                .removeHeader(FCREPO_URI)
                .removeHeader("JMSCorrelationID")
                .process(exchange -> {
                    // This is a simple n-triples parser, spliting nodes on whitespace according to
                    // https://www.w3.org/TR/n-triples/#n-triples-grammar
                    // If the body is not null and the predicate is ldp:contains and the object is a URI,
                    // then set the CamelFcrepoUri header (if that header is not set, the processing stops
                    // at the filter() line below.
                    final String body = exchange.getIn().getBody(String.class);
                    if (body != null) {
                        final String parts[] = body.split("\\s+");
                        if (parts.length > 2 && parts[1].equals(LDP_CONTAINS) && parts[2].startsWith("<")) {
                            exchange.getIn().setHeader(FCREPO_URI, parts[2].substring(1, parts[2].length() - 1));
                        }
                        exchange.getIn().setBody(null);
                    }
                })
                .filter(header(FCREPO_URI).isNotNull())
                    .inOnly("{{reindexing.stream}}?disableTimeToLive=true");

        /**
         *  Send the message to all of the pre-determined endpoints
         */
        from("direct:recipients").routeId("FcrepoReindexingRecipients")
            .recipientList(header(REINDEXING_RECIPIENTS))
            .ignoreInvalidEndpoints();
    }
1313804
public int addServerRedirect(String region, String srcUrl, String destUrl, String hostHeader, int profileId, int groupId) throws Exception {
        int serverId = -1;
        PreparedStatement statement = null;
        ResultSet results = null;

        try (Connection sqlConnection = sqlService.getConnection()) {
            statement = sqlConnection.prepareStatement("INSERT INTO " + Constants.DB_TABLE_SERVERS
                                                           + "(" + Constants.SERVER_REDIRECT_REGION + "," +
                                                           Constants.SERVER_REDIRECT_SRC_URL + "," +
                                                           Constants.SERVER_REDIRECT_DEST_URL + "," +
                                                           Constants.SERVER_REDIRECT_HOST_HEADER + "," +
                                                           Constants.SERVER_REDIRECT_PROFILE_ID + "," +
                                                           Constants.SERVER_REDIRECT_GROUP_ID + ")"
                                                           + " VALUES (?, ?, ?, ?, ?, ?);", PreparedStatement.RETURN_GENERATED_KEYS);
            statement.setString(1, region);
            statement.setString(2, srcUrl);
            statement.setString(3, destUrl);
            statement.setString(4, hostHeader);
            statement.setInt(5, profileId);
            statement.setInt(6, groupId);
            statement.executeUpdate();

            results = statement.getGeneratedKeys();

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

        return serverId;
    }
132680
@RequestMapping(value = "api/servergroup/{id}", method = RequestMethod.GET)
    public
    @ResponseBody
    ServerGroup getServerGroup(Model model,
                               @PathVariable int id,
                               @RequestParam(value = "profileId", required = false) Integer profileId,
                               @RequestParam(value = "profileIdentifier", required = false) String profileIdentifier) throws Exception {
        if (profileId == null && profileIdentifier == null) {
            throw new Exception("profileId required");
        }
        if (profileId == null) {
            profileId = ProfileService.getInstance().getIdFromName(profileIdentifier);
        }

        return ServerRedirectService.getInstance().getServerGroup(id, profileId);
    }
68946
@RequestMapping(value = "/api/path/{pathIdentifier}", method = RequestMethod.GET)
    @ResponseBody
    public EndpointOverride getPath(Model model,
                                    @PathVariable String pathIdentifier,
                                    @RequestParam(required = false) String profileIdentifier,
                                    @RequestParam(value = "typeFilter[]", required = false) String[] typeFilter,
                                    @RequestParam(value = "clientUUID", defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) throws Exception {
        Identifiers identifiers = ControllerUtils.convertProfileAndPathIdentifier(profileIdentifier, pathIdentifier);

        return PathOverrideService.getInstance().getPath(identifiers.getPathId(), clientUUID, typeFilter);
    }
1332416
public static void addProviderProfileInfo(Profile profile, UserProfile providerProfile) {
        String email = providerProfile.getEmail();
        if (StringUtils.isEmpty(email)) {
            throw new IllegalStateException("No email included in provider profile");
        }

        String username = providerProfile.getUsername();
        if (StringUtils.isEmpty(username)) {
            username = email;
        }

        String firstName = providerProfile.getFirstName();
        String lastName = providerProfile.getLastName();

        profile.setUsername(username);
        profile.setEmail(email);
        profile.setAttribute(FIRST_NAME_ATTRIBUTE_NAME, firstName);
        profile.setAttribute(LAST_NAME_ATTRIBUTE_NAME, lastName);
    }