Search in sources :

Example 1 with OAuthProblemException

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);
        }
    }
}
Also used : OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException) TvdbException(com.battlelancer.seriesguide.thetvdbapi.TvdbException) SQLiteException(android.database.sqlite.SQLiteException)

Example 2 with OAuthProblemException

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;
}
Also used : OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) OAuthAccessResourceRequest(org.apache.oltu.oauth2.rs.request.OAuthAccessResourceRequest) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException)

Example 3 with OAuthProblemException

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");
    }
}
Also used : OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) EntandoTokenException(org.entando.entando.web.common.exceptions.EntandoTokenException) OAuthAccessResourceRequest(org.apache.oltu.oauth2.rs.request.OAuthAccessResourceRequest) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException) OAuth2Token(org.entando.entando.aps.system.services.oauth2.model.OAuth2Token) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 4 with OAuthProblemException

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;
    }
}
Also used : OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) UserDetails(com.agiletec.aps.system.services.user.UserDetails) IOAuthConsumerManager(org.entando.entando.aps.system.services.oauth2.IOAuthConsumerManager) IUserManager(com.agiletec.aps.system.services.user.IUserManager) IApiOAuthorizationCodeManager(org.entando.entando.aps.system.services.oauth2.IApiOAuthorizationCodeManager) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException) OAuthTokenRequest(org.apache.oltu.oauth2.as.request.OAuthTokenRequest)

Example 5 with OAuthProblemException

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);
    }
}
Also used : OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) CodeAuthorizeHandler(io.github.tesla.authz.controller.oauth2.authorize.CodeAuthorizeHandler) TokenAuthorizeHandler(io.github.tesla.authz.controller.oauth2.authorize.TokenAuthorizeHandler) OAuthAuthxRequest(io.github.tesla.authz.controller.oauth2.OAuthAuthxRequest) OAuthResponse(org.apache.oltu.oauth2.common.message.OAuthResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

OAuthProblemException (org.apache.oltu.oauth2.common.exception.OAuthProblemException)20 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)14 OAuthResponse (org.apache.oltu.oauth2.common.message.OAuthResponse)9 IOException (java.io.IOException)5 MD5Generator (org.apache.oltu.oauth2.as.issuer.MD5Generator)5 OAuthAccessResourceRequest (org.apache.oltu.oauth2.rs.request.OAuthAccessResourceRequest)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 URI (java.net.URI)4 OAuthIssuerImpl (org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl)4 OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)4 ServletException (javax.servlet.ServletException)3 OAuthTokenRequest (org.apache.oltu.oauth2.as.request.OAuthTokenRequest)3 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)3 DatabaseSession (org.bimserver.database.DatabaseSession)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 IUserManager (com.agiletec.aps.system.services.user.IUserManager)2 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 URISyntaxException (java.net.URISyntaxException)2 OAuthIssuer (org.apache.oltu.oauth2.as.issuer.OAuthIssuer)2 OAuthAuthzRequest (org.apache.oltu.oauth2.as.request.OAuthAuthzRequest)2