Search in sources :

Example 6 with INVALID_REQUEST

use of org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.Error.INVALID_REQUEST in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method doPreAddApplicationChecks.

private void doPreAddApplicationChecks(ServiceProvider serviceProvider, String tenantDomain, String username) throws IdentityApplicationManagementException {
    String appName = serviceProvider.getApplicationName();
    if (StringUtils.isBlank(appName)) {
        // check for required attributes.
        throw buildClientException(INVALID_REQUEST, "Application name cannot be empty.");
    }
    ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
    if (appDAO.isApplicationExists(appName, tenantDomain)) {
        String msg = "An application with name: '" + appName + "' already exists in tenantDomain: " + tenantDomain;
        throw new IdentityApplicationRegistrationFailureException(APPLICATION_ALREADY_EXISTS.getCode(), msg);
    }
    if (ApplicationManagementServiceComponent.getFileBasedSPs().containsKey(appName)) {
        String msg = "Application with name: '" + appName + "' already loaded from the file system.";
        throw buildClientException(APPLICATION_ALREADY_EXISTS, msg);
    }
    if (!isRegexValidated(appName)) {
        String message = "The Application name: '" + appName + "' is not valid! It is not adhering to the regex: " + ApplicationMgtUtil.getSPValidatorRegex();
        throw buildClientException(INVALID_REQUEST, message);
    }
    addUserIdAsDefaultSubject(serviceProvider);
    validateApplicationConfigurations(serviceProvider, tenantDomain, username);
}
Also used : PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO) IdentityApplicationRegistrationFailureException(org.wso2.carbon.identity.application.common.IdentityApplicationRegistrationFailureException)

Example 7 with INVALID_REQUEST

use of org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.Error.INVALID_REQUEST in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuthAdminServiceImpl method validateGrantTypes.

private void validateGrantTypes(OAuthConsumerAppDTO application) throws IdentityOAuthClientException {
    String[] requestGrants = application.getGrantTypes().split("\\s");
    List<String> allowedGrantTypes = new ArrayList<>(Arrays.asList(getAllowedGrantTypes()));
    for (String requestedGrant : requestGrants) {
        if (StringUtils.isBlank(requestedGrant)) {
            continue;
        }
        if (!allowedGrantTypes.contains(requestedGrant)) {
            String msg = String.format("'%s' grant type is not allowed.", requestedGrant);
            throw handleClientError(INVALID_REQUEST, msg);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) OAuth2Util.buildScopeString(org.wso2.carbon.identity.oauth2.util.OAuth2Util.buildScopeString)

Example 8 with INVALID_REQUEST

use of org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.Error.INVALID_REQUEST in project identity-inbound-auth-oauth by wso2-extensions.

the class CibaGrantHandler method validateGrant.

@Override
public boolean validateGrant(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception {
    if (!super.validateGrant(tokReqMsgCtx)) {
        if (log.isDebugEnabled()) {
            log.debug("Successful in validating grant.Validation failed for the token request made by client: " + tokReqMsgCtx.getOauth2AccessTokenReqDTO().getClientId());
        }
        return false;
    }
    // Obtain authentication request identifier from request.
    String authReqId = getAuthReqId(tokReqMsgCtx);
    try {
        // Check whether provided authReqId is a valid and retrieve AuthCode if exists.
        CibaAuthCodeDO cibaAuthCodeDO = retrieveCibaAuthCode(authReqId);
        // Validate if auth_req_id belongs to the same client
        validateAuthReqIdOwner(cibaAuthCodeDO.getConsumerKey(), tokReqMsgCtx.getOauth2AccessTokenReqDTO().getClientId());
        // Check whether auth_req_id is not expired.
        validateAuthReqId(cibaAuthCodeDO);
        // Check whether token is issued for the authReqId.
        if (isTokenAlreadyIssued(cibaAuthCodeDO)) {
            throw new IdentityOAuth2Exception(INVALID_REQUEST);
        }
        // Validate whether authentication  is provided with affirmative consent.
        if (!isAuthorized(cibaAuthCodeDO)) {
            throw new IdentityOAuth2Exception(ACCESS_DENIED, "User denied authentication");
        }
        // Validate whether polling is under proper rate limiting.
        validatePollingFrequency(cibaAuthCodeDO);
        // Validate whether user is authenticated.
        if (isAuthorizationPending(cibaAuthCodeDO)) {
            updateLastPolledTime(cibaAuthCodeDO);
            throw new IdentityOAuth2Exception(AUTHORIZATION_PENDING, "Authorization pending");
        }
        setPropertiesForTokenGeneration(tokReqMsgCtx, cibaAuthCodeDO);
        return true;
    } catch (CibaCoreException e) {
        throw new IdentityOAuth2Exception(INVALID_PARAMETERS, e);
    }
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) CibaAuthCodeDO(org.wso2.carbon.identity.oauth.ciba.model.CibaAuthCodeDO) CibaCoreException(org.wso2.carbon.identity.oauth.ciba.exceptions.CibaCoreException)

Aggregations

OAuth2Util.buildScopeString (org.wso2.carbon.identity.oauth2.util.OAuth2Util.buildScopeString)6 ArrayList (java.util.ArrayList)2 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)2 OAuthAppDAO (org.wso2.carbon.identity.oauth.dao.OAuthAppDAO)2 OAuthAppDO (org.wso2.carbon.identity.oauth.dao.OAuthAppDO)2 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)2 IdentityApplicationRegistrationFailureException (org.wso2.carbon.identity.application.common.IdentityApplicationRegistrationFailureException)1 ApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO)1 PaginatableFilterableApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO)1 FileBasedApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)1 CibaCoreException (org.wso2.carbon.identity.oauth.ciba.exceptions.CibaCoreException)1 CibaAuthCodeDO (org.wso2.carbon.identity.oauth.ciba.model.CibaAuthCodeDO)1 InvalidOAuthClientException (org.wso2.carbon.identity.oauth.common.exception.InvalidOAuthClientException)1 OAuthApplicationMgtListener (org.wso2.carbon.identity.oauth.listener.OAuthApplicationMgtListener)1