protected ApplicationLinkRequestFactory createRequest(ApplicationLink applicationLink) { return applicationLink.createAuthenticatedRequestFactory(ImpersonatingAuthenticationProvider.class); } }
/** * Getter for the {@link com.atlassian.applinks.api.ApplicationLinkRequestFactory} * * @return the {@link com.atlassian.applinks.api.ApplicationLinkRequestFactory} */ private ApplicationLinkRequestFactory getAuthenticatedRequestFactory() { return applicationLink.createAuthenticatedRequestFactory(); }
protected ApplicationLinkRequestFactory createRequest(ApplicationLink applicationLink) { return applicationLink.createAuthenticatedRequestFactory(NonImpersonatingAuthenticationProvider.class); } }
public ApplinkHttpExecutor(@Nonnull ApplicationLink applicationLink) { this.applicationLink = applicationLink; this.anonymousRequestFactory = applicationLink.createAuthenticatedRequestFactory(Anonymous.class); this.authenticatedRequestFactory = applicationLink.createAuthenticatedRequestFactory(); }
public Iterable<EntityReference> getEntitiesForAnonymousAccess(final ApplicationLink link) throws ResponseException { try { return getEntities(link.createAuthenticatedRequestFactory(Anonymous.class)); } catch (CredentialsRequiredException e) { throw new RuntimeException(CredentialsRequiredException.class.getName() + " should never be thrown on anonymous access.", e); } } }
@Override public String generateAuthenticationUrl(String issueId) { final ApplicationLinkRequestFactory requestFactory = applicationLink.createAuthenticatedRequestFactory(); return RemotesResource.generateAuthorizationUrl(hostApplication, requestFactory, issueId); }
public Iterable<EntityReference> getEntities(final ApplicationLink link) throws ResponseException, CredentialsRequiredException { return getEntities(link.createAuthenticatedRequestFactory()); }
@GET @Path("getRequestType") public Response getRequestType(@QueryParam("rpc-url") String rpcurl) { ApplicationLink applicationLink = getApplicationLinkByRpcUrl(rpcurl); ApplicationLinkRequestFactory factory = applicationLink.createAuthenticatedRequestFactory(); return ok(getRequestType(factory)).build(); }
/** * Build the request assuming it requires authentication. In case the supplied * {@link #authentication(Class)} authentication provider} requires credentials that are missing, an appropriate * error will be raised. * * @return the request * @throws CredentialsRequiredException if there is no local credentials necessary to create an authenticated * request * @see #buildAnonymous() if the request is {@link #anonymous() not authenticated} */ @Nonnull public AuthorisationUriAwareRequest build() throws CredentialsRequiredException { return buildRequest(link.createAuthenticatedRequestFactory(authentication)); }
/** * This is a convenience method for creating anonymous (unauthenticated) requests without having to catch the * {@link CredentialsRequiredException} declared on the {@link ApplicationLinkRequestFactory} interface * * @param link the {@link ApplicationLink} that is the target of the request * @param methodType The HTTP method type * @param url The url to request * @return the (unauthenticated) request object * @see ApplicationLinkRequestFactory#createRequest */ public static Request createAnonymousRequest(final ApplicationLink link, final Request.MethodType methodType, final String url) { try { return link.createAuthenticatedRequestFactory(Anonymous.class).createRequest(methodType, url); } catch (CredentialsRequiredException e) { throw new RuntimeException("Unexpected CredentialsRequiredException encountered for Anonymous AuthenticationProvider", e); } }
private Map<String, Object> getRenderContextForConfig() { Map<String, Object> context = new HashMap<>(); boolean hasStashApplinkConfiguredProperly = false; for (ApplicationLink stashApplicationLink : applicationLinkService.get().getApplicationLinks(typeAccessor.get().getApplicationType(BitbucketApplicationType.class).getClass())) { ApplicationLinkRequestFactory requestFactory = stashApplicationLink.createAuthenticatedRequestFactory(TwoLeggedOAuthAuthenticationProvider.class); if (requestFactory != null) { hasStashApplinkConfiguredProperly = true; break; } } if (!hasStashApplinkConfiguredProperly) { context.put("noStashApplinkConfigured", true); } return context; }
public void createEntityLinkFrom(final EntityLink entityLink, final EntityType localType, final String localKey) throws ReciprocalActionException, CredentialsRequiredException { createEntityLinkFrom(entityLink, localType, localKey, entityLink.getApplicationLink().createAuthenticatedRequestFactory()); }
private static ApplicationLinkRequest createRequest(final ApplicationLink applicationLink, final String bodyXml) throws CredentialsRequiredException { final ApplicationLinkRequestFactory requestFactory = applicationLink.createAuthenticatedRequestFactory(); final ApplicationLinkRequest request = requestFactory.createRequest(Request.MethodType.POST, XMLRPC_URL); request.setRequestBody(bodyXml, MediaType.APPLICATION_XML); return request; }
private static ApplicationLinkRequest createGetURLRequest(final ApplicationLink applicationLink, final String url, final Map<String, String> params) throws CredentialsRequiredException { final UrlBuilder urlBuilder = new UrlBuilder(url); if (params != null) { for (final Map.Entry<String, String> param : params.entrySet()) { urlBuilder.addParameter(param.getKey(), param.getValue()); } } final String restUrl = urlBuilder.asUrlString(); final ApplicationLinkRequestFactory requestFactory = applicationLink.createAuthenticatedRequestFactory(); return requestFactory.createRequest(Request.MethodType.GET, restUrl); }
@Override public RemoteResponse<String> getPageId(final ApplicationLink applicationLink, String pageUrl) throws CredentialsRequiredException, ResponseException { final ApplicationLinkRequestFactory requestFactory = applicationLink.createAuthenticatedRequestFactory(); // Strip fragment identifier final int hash = pageUrl.indexOf('#'); if (hash >= 0) { pageUrl = pageUrl.substring(0, hash); } final ApplicationLinkRequest request = requestFactory.createRequest(Request.MethodType.GET, pageUrl); request.setFollowRedirects(false); return request.execute(new PageResponseHandler(requestFactory)); }
private Collection<RemoteProject> getRemoteProjects(final ApplicationLink applicationLink) throws CredentialsRequiredException, ResponseException { ApplicationLinkRequestFactory requestFactory = applicationLink.createAuthenticatedRequestFactory(); ApplicationLinkRequest req = requestFactory.createRequest(Request.MethodType.GET, "/rest/api/2/project"); return parseProjects(req.execute(), applicationLink); }
private static ApplicationLinkRequest createCreateRemoteIssueLinkRequest(final ApplicationLink applicationLink, final String issueKey) throws CredentialsRequiredException { final UrlBuilder urlBuilder = new UrlBuilder(REST_BASE_URL) .addPath(issueKey) .addPathUnsafe(REMOTE_LINK_RESOURCE); final String restUrl = urlBuilder.asUrlString(); final ApplicationLinkRequestFactory requestFactory = applicationLink.createAuthenticatedRequestFactory(); return requestFactory.createRequest(Request.MethodType.POST, restUrl); }
private <T> Either<NegativeResponseStatus, T> callRestService(Request.MethodType method, final String path, final AbstractJsonResponseHandler<T> handler) { final ApplicationLinkRequestFactory requestFactory = applicationLink.createAuthenticatedRequestFactory(); try { ApplicationLinkRequest request = requestFactory.createRequest(method, path); handler.modifyRequest(request); return request.execute(handler); } catch (CredentialsRequiredException ex) { return Either.left(NegativeResponseStatus.authorizationRequired(jiraLocation)); } catch (ResponseException e) { log.error(String.format("Failed to transform response from Application Link: %s (%s)", jiraLocation.getId(), e.getMessage())); return Either.left(NegativeResponseStatus.communicationFailed(jiraLocation)); } }
private static ApplicationLinkRequest createGetIssueRequest(final ApplicationLink applicationLink, final String issueKey, final RestVersion restVersion) throws CredentialsRequiredException { final String restUrl = new UrlBuilder(REST_BASE_URL) .addPathUnsafe(restVersion.toString()) .addPathUnsafe(ISSUE_RESOURCE) .addPath(issueKey) .asUrlString(); final ApplicationLinkRequestFactory requestFactory = applicationLink.createAuthenticatedRequestFactory(); return requestFactory.createRequest(Request.MethodType.GET, restUrl); }
private static ApplicationLinkRequest createCreateRemoteIssueLinkRequest(final ApplicationLink applicationLink, final String issueKey, final RestVersion restVersion) throws CredentialsRequiredException { final UrlBuilder urlBuilder = new UrlBuilder(REST_BASE_URL) .addPathUnsafe(restVersion.toString()) .addPathUnsafe(ISSUE_RESOURCE) .addPath(issueKey) .addPathUnsafe(REMOTE_LINK_RESOURCE); final String restUrl = urlBuilder.asUrlString(); final ApplicationLinkRequestFactory requestFactory = applicationLink.createAuthenticatedRequestFactory(); return requestFactory.createRequest(Request.MethodType.POST, restUrl); }