use of org.apache.amber.oauth2.common.exception.OAuthProblemException in project SeriesGuide by UweTrottmann.
the class AnalyticsTree method log.
@Override
protected void log(int priority, String tag, String message, Throwable t) {
if (priority == Log.ERROR) {
// remove any stack trace attached by Timber
if (message != null) {
int newLine = message.indexOf('\n');
if (newLine > 0) {
message = message.substring(0, newLine);
}
}
// special treatment for some exceptions
if (t instanceof TvdbException) {
TvdbException e = (TvdbException) t;
Utils.trackCustomEvent(context, CATEGORY_THETVDB_ERROR, tag + ": " + message, e.getMessage());
return;
} else if (t instanceof OAuthProblemException) {
// log trakt OAuth failures
OAuthProblemException e = (OAuthProblemException) t;
StringBuilder exceptionMessage = new StringBuilder();
if (!TextUtils.isEmpty(e.getError())) {
exceptionMessage.append(e.getError());
}
if (!TextUtils.isEmpty(e.getDescription())) {
exceptionMessage.append(", ").append(e.getDescription());
}
if (!TextUtils.isEmpty(e.getUri())) {
exceptionMessage.append(", ").append(e.getUri());
}
Utils.trackCustomEvent(context, "OAuth Error", tag + ": " + message, exceptionMessage.toString());
return;
} else if (t instanceof OAuthSystemException) {
// log trakt OAuth failures
OAuthSystemException e = (OAuthSystemException) t;
Utils.trackCustomEvent(context, "OAuth Error", tag + ": " + message, e.getMessage());
return;
}
}
// drop empty messages
if (message == null) {
return;
}
// drop debug and verbose logs
if (priority == Log.DEBUG || priority == Log.VERBOSE) {
return;
}
// transform priority into string
String level = null;
switch(priority) {
case Log.INFO:
level = "INFO";
break;
case Log.WARN:
level = "WARN";
break;
case Log.ERROR:
level = "ERROR";
break;
}
// finally log to crashlytics
Crashlytics.log(level + "/" + tag + ": " + message);
// track some non-fatal exceptions with crashlytics
if (priority == Log.ERROR) {
if (t instanceof SQLiteException) {
Crashlytics.logException(t);
}
}
}
use of org.apache.amber.oauth2.common.exception.OAuthProblemException in project BIMserver by opensourceBIM.
the class JsonHandler method getServiceInterface.
private <T extends PublicInterface> T getServiceInterface(HttpServletRequest httpRequest, BimServer bimServer, Class<T> interfaceClass, String methodName, String token, String oAuthCode) throws UserException, ServerException {
if (methodName.equals("login") || methodName.equals("autologin")) {
return bimServer.getServiceFactory().get(AccessMethod.JSON).get(interfaceClass);
}
OAuthAccessResourceRequest oauthRequest;
try {
oauthRequest = new OAuthAccessResourceRequest(httpRequest, ParameterStyle.HEADER);
token = oauthRequest.getAccessToken();
} catch (OAuthSystemException e) {
} catch (OAuthProblemException e) {
}
if (token == null) {
token = httpRequest == null ? null : (String) httpRequest.getSession().getAttribute("token");
}
if (token == null) {
token = oAuthCode;
}
if (token == null) {
return bimServer.getServiceFactory().get(AccessMethod.JSON).get(interfaceClass);
}
T service = bimServer.getServiceFactory().get(token, AccessMethod.JSON).get(interfaceClass);
if (service == null) {
service = bimServer.getServiceFactory().get(AccessMethod.JSON).get(interfaceClass);
if (httpRequest != null) {
httpRequest.getSession().setAttribute("token", token);
}
}
return service;
}
use of org.apache.amber.oauth2.common.exception.OAuthProblemException in project entando-core by entando.
the class EntandoOauth2Interceptor method extractOAuthParameters.
protected void extractOAuthParameters(HttpServletRequest request, String permission) {
try {
logger.info("Permission required: {}", permission);
OAuthAccessResourceRequest requestMessage = new OAuthAccessResourceRequest(request, ParameterStyle.HEADER);
String accessToken = requestMessage.getAccessToken();
if (StringUtils.isBlank(accessToken)) {
throw new EntandoTokenException("no access token found", request, null);
}
final OAuth2Token token = oAuth2TokenManager.getApiOAuth2Token(accessToken);
this.validateToken(request, accessToken, token);
String username = token.getClientId();
this.checkAuthorization(username, permission, request);
} catch (OAuthSystemException | ApsSystemException | OAuthProblemException ex) {
logger.error("System exception {}", ex.getMessage());
throw new EntandoTokenException("error parsing OAuth parameters", request, "guest");
}
}
use of org.apache.amber.oauth2.common.exception.OAuthProblemException in project entando-core by entando.
the class TokenEndpointServlet method validateClientWithAuthorizationCode.
private OAuthResponse validateClientWithAuthorizationCode(HttpServletRequest request) throws Throwable {
try {
final OAuthTokenRequest oauthRequest = new OAuthTokenRequest(request);
IOAuthConsumerManager consumerManager = (IOAuthConsumerManager) ApsWebApplicationUtils.getBean(SystemConstants.OAUTH_CONSUMER_MANAGER, request);
IApiOAuthorizationCodeManager codeManager = (IApiOAuthorizationCodeManager) ApsWebApplicationUtils.getBean(SystemConstants.OAUTH2_AUTHORIZATION_CODE_MANAGER, request);
if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.AUTHORIZATION_CODE.toString()) || oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.REFRESH_TOKEN.toString())) {
final String clientId = oauthRequest.getClientId();
final String oauthType = GrantType.AUTHORIZATION_CODE.toString();
final String authCode = oauthRequest.getParam(OAuth.OAUTH_CODE);
final String clientSecret = oauthRequest.getClientSecret();
boolean checkVerifyAccess = codeManager.verifyAccess(clientId, clientSecret, consumerManager);
if (!checkVerifyAccess) {
_logger.error(ERROR_AUTHENTICATION_FAILED);
return null;
} else if (!codeManager.verifyCode(authCode, request.getRemoteAddr())) {
_logger.error("OAuth2 authcode does not match or the source of client is different");
return null;
}
return this.registerToken(request, clientId, oauthType, null);
} else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.PASSWORD.toString())) {
final String username = oauthRequest.getUsername();
final String password = oauthRequest.getPassword();
final String oauthType = GrantType.PASSWORD.toString();
IUserManager userManager = (IUserManager) ApsWebApplicationUtils.getBean(SystemConstants.USER_MANAGER, request);
UserDetails user = userManager.getUser(username, password);
if (user == null) {
_logger.error(ERROR_AUTHENTICATION_FAILED);
return null;
}
return this.registerToken(request, username, oauthType, null);
} else {
return null;
}
} catch (OAuthSystemException e) {
_logger.error("OAuthSystemException - {} ", e);
return null;
} catch (OAuthProblemException e) {
_logger.error("OAuthProblemException - {} ", e.getError().concat(" ").concat(e.getDescription()));
_logger.debug("OAuthProblemException - {} ", e);
return null;
}
}
use of org.apache.amber.oauth2.common.exception.OAuthProblemException in project tesla by linking12.
the class OauthAuthorizeController method authorize.
@RequestMapping("authorize")
public void authorize(HttpServletRequest request, HttpServletResponse response) throws OAuthSystemException, ServletException, IOException {
try {
OAuthAuthxRequest oauthRequest = new OAuthAuthxRequest(request);
if (oauthRequest.isCode()) {
CodeAuthorizeHandler codeAuthorizeHandler = new CodeAuthorizeHandler(oauthRequest, response);
LOG.debug("Go to response_type = 'code' handler: {}", codeAuthorizeHandler);
codeAuthorizeHandler.handle();
} else if (oauthRequest.isToken()) {
TokenAuthorizeHandler tokenAuthorizeHandler = new TokenAuthorizeHandler(oauthRequest, response);
LOG.debug("Go to response_type = 'token' handler: {}", tokenAuthorizeHandler);
tokenAuthorizeHandler.handle();
} else {
unsupportResponseType(oauthRequest, response);
}
} catch (OAuthProblemException e) {
LOG.debug(e.getMessage(), e);
OAuthResponse oAuthResponse = OAuthASResponse.errorResponse(HttpServletResponse.SC_FOUND).location(e.getRedirectUri()).error(e).buildJSONMessage();
WebUtils.writeOAuthJsonResponse(response, oAuthResponse);
}
}
Aggregations