use of org.apache.amber.oauth2.common.exception.OAuthSystemException in project lusid-sdk-java by finbourne.
the class OAuthOkHttpClient method execute.
@Override
public <T extends OAuthClientResponse> T execute(OAuthClientRequest request, Map<String, String> headers, String requestMethod, Class<T> responseClass) throws OAuthSystemException, OAuthProblemException {
MediaType mediaType = MediaType.parse("application/json");
Request.Builder requestBuilder = new Request.Builder().url(request.getLocationUri());
if (headers != null) {
for (Entry<String, String> entry : headers.entrySet()) {
if (entry.getKey().equalsIgnoreCase("Content-Type")) {
mediaType = MediaType.parse(entry.getValue());
} else {
requestBuilder.addHeader(entry.getKey(), entry.getValue());
}
}
}
RequestBody body = request.getBody() != null ? RequestBody.create(request.getBody(), mediaType) : null;
requestBuilder.method(requestMethod, body);
try {
Response response = client.newCall(requestBuilder.build()).execute();
return OAuthClientResponseFactory.createCustomResponse(response.body().string(), response.body().contentType().toString(), response.code(), responseClass);
} catch (IOException e) {
throw new OAuthSystemException(e);
}
}
use of org.apache.amber.oauth2.common.exception.OAuthSystemException in project aos-Video by nova-video-player.
the class TraktSigninDialogPreference method onClick.
@Override
public void onClick() {
try {
OAuthClientRequest t = Trakt.getAuthorizationRequest(getSharedPreferences());
final OAuthData oa = new OAuthData();
OAuthCallback codeCallBack = new OAuthCallback() {
@Override
public void onFinished(final OAuthData data) {
// TODO Auto-generated method stub
if (data.code != null) {
final ProgressDialog mProgress = new ProgressDialog(getContext());
AsyncTask t = new AsyncTask() {
@Override
protected void onPreExecute() {
mProgress.show();
}
@Override
protected Object doInBackground(Object... params) {
OAuthAccessTokenResponse res = Trakt.getAccessToken(oa.code);
return res;
}
@Override
protected void onPostExecute(Object result) {
mProgress.dismiss();
if (result != null && result instanceof OAuthAccessTokenResponse) {
OAuthAccessTokenResponse res = (OAuthAccessTokenResponse) result;
if (res.getAccessToken() != null) {
Trakt.setAccessToken(getSharedPreferences(), res.getAccessToken());
Trakt.setRefreshToken(getSharedPreferences(), res.getRefreshToken());
TraktSigninDialogPreference.this.notifyChanged();
}
}
}
};
t.execute();
} else {
new AlertDialog.Builder(getContext()).setNegativeButton(android.R.string.ok, null).setMessage(R.string.dialog_subloader_nonetwork_title).setIcon(android.R.drawable.ic_dialog_alert).show();
}
}
};
od = new OAuthDialog(getContext(), codeCallBack, oa, t);
od.show();
od.setOnDismissListener(mOnDismissListener);
od.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
mOnDismissListener.onDismiss(dialogInterface);
}
});
} catch (OAuthSystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.apache.amber.oauth2.common.exception.OAuthSystemException in project pyramus by otavanopisto.
the class SecurityFilter method hasOAuthApiAccess.
private boolean hasOAuthApiAccess() {
try {
OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(request, ParameterStyle.HEADER);
String accessToken = oauthRequest.getAccessToken();
ClientApplicationAccessToken clientApplicationAccessToken = oauthController.findByAccessToken(accessToken);
if (clientApplicationAccessToken == null) {
return false;
} else {
Long currentTime = System.currentTimeMillis() / 1000L;
if (currentTime > clientApplicationAccessToken.getExpires()) {
return false;
} else {
return true;
}
}
} catch (OAuthProblemException e) {
return false;
} catch (OAuthSystemException e) {
return false;
}
}
use of org.apache.amber.oauth2.common.exception.OAuthSystemException in project pyramus by otavanopisto.
the class AbstractRESTPermissionsTest method createAccessTokens.
@Before
public void createAccessTokens() {
OAuthClientRequest tokenRequest = null;
if (!Role.EVERYONE.name().equals(role)) {
try {
tokenRequest = OAuthClientRequest.tokenLocation("https://dev.pyramus.fi:8443/1/oauth/token").setGrantType(GrantType.AUTHORIZATION_CODE).setClientId(fi.otavanopisto.pyramus.Common.CLIENT_ID).setClientSecret(fi.otavanopisto.pyramus.Common.CLIENT_SECRET).setRedirectURI(fi.otavanopisto.pyramus.Common.REDIRECT_URL).setCode(fi.otavanopisto.pyramus.Common.getRoleAuth(Common.strToRole(role))).buildBodyMessage();
} catch (OAuthSystemException e) {
e.printStackTrace();
}
Response response = given().contentType("application/x-www-form-urlencoded").body(tokenRequest.getBody()).post("/oauth/token");
String accessToken = response.body().jsonPath().getString("access_token");
setAccessToken(accessToken);
} else {
setAccessToken("");
}
/**
* AdminAccessToken
*/
if (!Role.ADMINISTRATOR.name().equals(role)) {
tokenRequest = null;
try {
tokenRequest = OAuthClientRequest.tokenLocation("https://dev.pyramus.fi:8443/1/oauth/token").setGrantType(GrantType.AUTHORIZATION_CODE).setClientId(fi.otavanopisto.pyramus.Common.CLIENT_ID).setClientSecret(fi.otavanopisto.pyramus.Common.CLIENT_SECRET).setRedirectURI(fi.otavanopisto.pyramus.Common.REDIRECT_URL).setCode(fi.otavanopisto.pyramus.Common.getRoleAuth(Role.ADMINISTRATOR)).buildBodyMessage();
} catch (OAuthSystemException e) {
e.printStackTrace();
}
Response response = given().contentType("application/x-www-form-urlencoded").body(tokenRequest.getBody()).post("/oauth/token");
String adminAccessToken = response.body().jsonPath().getString("access_token");
setAdminAccessToken(adminAccessToken);
} else {
setAdminAccessToken(accessToken);
}
}
use of org.apache.amber.oauth2.common.exception.OAuthSystemException in project pyramus by otavanopisto.
the class AbstractRESTPermissionsTestJUnit5 method getOauthToken.
protected String getOauthToken(Role role) {
if (!Role.EVERYONE.equals(role)) {
OAuthClientRequest tokenRequest = null;
try {
tokenRequest = OAuthClientRequest.tokenLocation("https://dev.pyramus.fi:8443/1/oauth/token").setGrantType(GrantType.AUTHORIZATION_CODE).setClientId(fi.otavanopisto.pyramus.Common.CLIENT_ID).setClientSecret(fi.otavanopisto.pyramus.Common.CLIENT_SECRET).setRedirectURI(fi.otavanopisto.pyramus.Common.REDIRECT_URL).setCode(fi.otavanopisto.pyramus.Common.getRoleAuth(role)).buildBodyMessage();
} catch (OAuthSystemException e) {
e.printStackTrace();
}
Response response = given().contentType("application/x-www-form-urlencoded").body(tokenRequest.getBody()).post("/oauth/token");
return response.body().jsonPath().getString("access_token");
}
return "";
}
Aggregations