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);
}
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);
}
}
}
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);
}
}
Aggregations