Search in sources :

Example 91 with OAuthSystemException

use of org.apache.oltu.oauth2.common.exception.OAuthSystemException in project tesla by linking12.

the class CodeAuthorizeHandler method handleResponse.

@Override
protected void handleResponse() throws OAuthSystemException, IOException {
    final ClientDetails clientDetails = clientDetails();
    final String authCode = oauthService.retrieveAuthCode(clientDetails);
    final OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(oauthRequest.request(), HttpServletResponse.SC_OK).location(clientDetails.getRedirectUri()).setCode(authCode).buildQueryMessage();
    LOG.debug(" 'code' response: {}", oAuthResponse);
    WebUtils.writeOAuthQueryResponse(response, oAuthResponse);
}
Also used : ClientDetails(io.github.tesla.authz.domain.ClientDetails) OAuthResponse(org.apache.oltu.oauth2.common.message.OAuthResponse)

Example 92 with OAuthSystemException

use of org.apache.oltu.oauth2.common.exception.OAuthSystemException in project tesla by linking12.

the class AbstractOAuthTokenHandler method validateFailed.

protected boolean validateFailed() throws OAuthSystemException {
    AbstractClientDetailsValidator validator = getValidator();
    LOG.debug("Use [{}] validate client: {}", validator, tokenRequest.getClientId());
    final OAuthResponse oAuthResponse = validator.validate();
    return checkAndResponseValidateFailed(oAuthResponse);
}
Also used : AbstractClientDetailsValidator(io.github.tesla.authz.controller.oauth2.validator.AbstractClientDetailsValidator) OAuthResponse(org.apache.oltu.oauth2.common.message.OAuthResponse)

Example 93 with OAuthSystemException

use of org.apache.oltu.oauth2.common.exception.OAuthSystemException in project tesla by linking12.

the class ClientCredentialsTokenHandler method handleAfterValidation.

@Override
public void handleAfterValidation() throws OAuthProblemException, OAuthSystemException {
    AccessToken accessToken = oauthService.retrieveClientCredentialsAccessToken(clientDetails(), tokenRequest.getScopes());
    final OAuthResponse tokenResponse = createTokenResponse(accessToken, false);
    LOG.debug("'client_credentials' response: {}", tokenResponse);
    WebUtils.writeOAuthJsonResponse(response, tokenResponse);
}
Also used : AccessToken(io.github.tesla.authz.domain.AccessToken) OAuthResponse(org.apache.oltu.oauth2.common.message.OAuthResponse)

Example 94 with OAuthSystemException

use of org.apache.oltu.oauth2.common.exception.OAuthSystemException in project tesla by linking12.

the class PasswordTokenHandler method handleAfterValidation.

@Override
public void handleAfterValidation() throws OAuthProblemException, OAuthSystemException {
    AccessToken accessToken = oauthService.retrievePasswordAccessToken(clientDetails(), tokenRequest.getScopes(), tokenRequest.getUsername());
    final OAuthResponse tokenResponse = createTokenResponse(accessToken, false);
    LOG.debug("'password' response: {}", tokenResponse);
    WebUtils.writeOAuthJsonResponse(response, tokenResponse);
}
Also used : AccessToken(io.github.tesla.authz.domain.AccessToken) OAuthResponse(org.apache.oltu.oauth2.common.message.OAuthResponse)

Example 95 with OAuthSystemException

use of org.apache.oltu.oauth2.common.exception.OAuthSystemException in project irida by phac-nml.

the class OltuAuthorizationController method authenticate.

/**
 * Begin authentication procedure by redirecting to remote authorization
 * location
 *
 * @param remoteAPI
 *            The API we need to authenticate with
 * @param redirect
 *            The location to redirect back to after authentication is
 *            complete
 * @return A ModelAndView beginning the authentication procedure
 * @throws OAuthSystemException
 */
/**
 * Begin authentication procedure by redirecting to remote authorization
 * location
 *
 * @param serviceURI
 *            The base URI of the rest api service
 * @param clientID
 *            The Client ID to connect with
 * @param clientSecret
 *            The client secret to connect with
 * @param redirect
 *            Page to redirect to after auth is complete
 * @return ModelAndView redirecting to the authorization location
 * @throws OAuthSystemException
 */
public ModelAndView authenticate(String serviceURI, String clientID, String clientSecret, String redirect) throws OAuthSystemException {
    // save the client credentials and information
    this.clientId = clientID;
    this.clientSecret = clientSecret;
    this.serviceURI = serviceURI;
    // build the authorization path
    URI serviceAuthLocation = UriBuilder.fromUri(serviceURI).path("oauth").path("authorize").build();
    logger.debug("redirect: " + redirect);
    // build a redirect URI to redirect to after auth flow is completed
    String tokenRedirect = buildRedirectURI(redirect);
    // build the redirect query to request an authorization code from the
    // remote API
    OAuthClientRequest request = OAuthClientRequest.authorizationLocation(serviceAuthLocation.toString()).setClientId(clientID).setRedirectURI(tokenRedirect).setResponseType(ResponseType.CODE.toString()).setScope("read").buildQueryMessage();
    String locURI = request.getLocationUri();
    logger.debug("authorization request location:" + locURI);
    // create the redirection
    ModelAndView modelAndView = new ModelAndView(new RedirectView(locURI));
    return modelAndView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest) URI(java.net.URI)

Aggregations

OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)103 OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)57 OAuthProblemException (org.apache.oltu.oauth2.common.exception.OAuthProblemException)51 OAuthResponse (org.apache.oltu.oauth2.common.message.OAuthResponse)49 IOException (java.io.IOException)41 Request (okhttp3.Request)29 Response (okhttp3.Response)29 OAuthJSONAccessTokenResponse (org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse)23 Builder (okhttp3.Request.Builder)19 OAuthBearerClientRequest (org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest)18 URI (java.net.URI)17 Map (java.util.Map)16 TokenRequestBuilder (org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder)15 OAuthClientResponse (org.apache.oltu.oauth2.client.response.OAuthClientResponse)15 MediaType (okhttp3.MediaType)14 RequestBody (okhttp3.RequestBody)14 OAuthClient (org.apache.oltu.oauth2.client.OAuthClient)13 MD5Generator (org.apache.oltu.oauth2.as.issuer.MD5Generator)12 AuthenticationRequestBuilder (org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12