/** * Unmarshal oauth application to string. * * @param authApplication oauth application to be marshaled * @return string * @throws IdentityApplicationManagementException Identity Application Management Exception */ private String unmarshelOAuthDO(OAuthAppDO authApplication) throws IdentityApplicationManagementException { try { JAXBContext jaxbContext = JAXBContext.newInstance(OAuthAppDO.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter sw = new StringWriter(); jaxbMarshaller.marshal(authApplication, sw); return sw.toString(); } catch (JAXBException e) { throw new IdentityApplicationManagementException(String.format("Error in exporting OAuth application " + "%s@%s", authApplication.getApplicationName(), authApplication.getUser().getTenantDomain()), e); } }
prepStmt.setString(4, consumerAppDTO.getApplicationName());
prepStmt.setString(4, consumerAppDTO.getApplicationName());
prepStmt.setString(1, oauthAppDO.getApplicationName()); prepStmt.setString(2, oauthAppDO.getCallbackUrl()); prepStmt.setString(3, oauthAppDO.getGrantTypes());
log.debug(String.format("There is no scope validator registered for %s@%s", oAuthAppDO.getApplicationName(), OAuth2Util.getTenantDomainOfOauthApp(oAuthAppDO))); throw new IdentityOAuth2Exception(String.format("The scope validators %s registered for application %s@%s" + " are not found in the server configuration ", StringUtils.join(appScopeValidators, ", "), oAuthAppDO.getApplicationName(), OAuth2Util.getTenantDomainOfOauthApp(oAuthAppDO)));
log.debug(String.format("There is no scope validator registered for %s@%s", app.getApplicationName(), OAuth2Util.getTenantDomainOfOauthApp(app))); throw new IdentityOAuth2Exception(String.format("The scope validators %s registered for application %s@%s" + " are not found in the server configuration ", StringUtils.join(appScopeValidators, ", "), app.getApplicationName(), OAuth2Util.getTenantDomainOfOauthApp(app)));
private boolean validateUserForOwnerUpdate(OAuthAppDO oAuthAppDO) throws IdentityOAuthAdminException { try { String userName = null; String usernameWithDomain = null; if (oAuthAppDO.getAppOwner() != null) { userName = oAuthAppDO.getAppOwner().getUserName(); if (StringUtils.isEmpty(userName) || CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(userName)) { return false; } String domainName = oAuthAppDO.getAppOwner().getUserStoreDomain(); usernameWithDomain = UserCoreUtil.addDomainToName(userName, domainName); } UserRealm realm = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm(); if (realm == null || StringUtils.isEmpty(usernameWithDomain)) { return false; } boolean isUserExist = realm.getUserStoreManager().isExistingUser(usernameWithDomain); if (!isUserExist) { throw new IdentityOAuthAdminException("User validation failed for owner update in the application: " + oAuthAppDO.getApplicationName() + " as user is not existing."); } } catch (UserStoreException e) { throw handleError("User validation failed for owner update in the application: " + oAuthAppDO.getApplicationName(), e); } return true; }
prepStmt.setInt(4, spTenantId); prepStmt.setString(5, userStoreDomain); prepStmt.setString(6, consumerAppDO.getApplicationName()); prepStmt.setString(7, consumerAppDO.getOauthVersion()); prepStmt.setString(8, consumerAppDO.getCallbackUrl()); prepStmt.setInt(4, spTenantId); prepStmt.setString(5, userStoreDomain); prepStmt.setString(6, consumerAppDO.getApplicationName()); prepStmt.setString(7, consumerAppDO.getOauthVersion()); prepStmt.setString(8, consumerAppDO.getCallbackUrl()); if (log.isDebugEnabled()) { log.debug("JDBC Driver did not returning the app id of the newly created app " + consumerAppDO.getApplicationName() + ". So executing select operation to get the id"); consumerAppDO.getApplicationName(), consumerAppDO.getUser().getTenantDomain()), e); } catch (IdentityOAuth2Exception e) { throw handleError("Error occurred while processing the client id and client secret by " +
prepStmt.setInt(4, IdentityTenantUtil.getTenantId(consumerAppDO.getUser().getTenantDomain())); prepStmt.setString(5, consumerAppDO.getUser().getUserStoreDomain()); prepStmt.setString(6, consumerAppDO.getApplicationName()); prepStmt.setString(7, consumerAppDO.getOauthVersion()); prepStmt.setString(8, consumerAppDO.getCallbackUrl()); prepStmt.setInt(4, IdentityTenantUtil.getTenantId(consumerAppDO.getUser().getTenantDomain())); prepStmt.setString(5, consumerAppDO.getUser().getUserStoreDomain()); prepStmt.setString(6, consumerAppDO.getApplicationName()); prepStmt.setString(7, consumerAppDO.getOauthVersion()); prepStmt.setString(8, consumerAppDO.getCallbackUrl());
String sqlQuery = getSqlQuery(isUserValidForOwnerUpdate); try (PreparedStatement prepStmt = connection.prepareStatement(sqlQuery)) { prepStmt.setString(1, oauthAppDO.getApplicationName()); prepStmt.setString(2, oauthAppDO.getCallbackUrl()); prepStmt.setString(3, oauthAppDO.getGrantTypes());
try { OAuthAppDO appInformation = dao.getAppInformation(inboundAuthKey); if (!appInformation.getApplicationName().equals( serviceProvider.getApplicationName())) { appInformation.getApplicationName(), inboundAuthKey)); break; IdentityTenantUtil.getTenantId(tenantDomain), tenantDomain, oAuthAppDO)) { validationMsg.add(String.format("There is already an oauth application available with" + " %s as application name", oAuthAppDO.getApplicationName())); break;
if (log.isDebugEnabled()) { log.debug("Registered App found for the given Client Id : " + clientId + " ,App Name : " + appDO .getApplicationName() + ", does not support the requested grant type."); validationResponseDTO.setValidClient(true); validationResponseDTO.setCallbackURL(appDO.getCallbackUrl()); validationResponseDTO.setApplicationName(appDO.getApplicationName()); validationResponseDTO.setPkceMandatory(appDO.isPkceMandatory()); validationResponseDTO.setPkceSupportPlain(appDO.isPkceSupportPlain()); .getApplicationName() + ", Callback URL : " + appDO.getCallbackUrl()); validationResponseDTO.setApplicationName(appDO.getApplicationName()); validationResponseDTO.setCallbackURL(callbackURI); return validationResponseDTO; } else if (appDO.getCallbackUrl().equals(callbackURI)) { validationResponseDTO.setValidClient(true); validationResponseDTO.setApplicationName(appDO.getApplicationName()); validationResponseDTO.setCallbackURL(callbackURI); validationResponseDTO.setPkceMandatory(appDO.isPkceMandatory());
if (log.isDebugEnabled()) { log.debug("Registered App found for the given Client Id : " + clientId + " ,App Name : " + appDO .getApplicationName() + ", does not support the requested grant type."); validationResponseDTO.setValidClient(true); validationResponseDTO.setCallbackURL(appDO.getCallbackUrl()); validationResponseDTO.setApplicationName(appDO.getApplicationName()); validationResponseDTO.setPkceMandatory(appDO.isPkceMandatory()); validationResponseDTO.setPkceSupportPlain(appDO.isPkceSupportPlain()); .getApplicationName() + ", Callback URL : " + appDO.getCallbackUrl()); validationResponseDTO.setApplicationName(appDO.getApplicationName()); validationResponseDTO.setCallbackURL(callbackURI); return validationResponseDTO; } else if (appDO.getCallbackUrl().equals(callbackURI)) { validationResponseDTO.setValidClient(true); validationResponseDTO.setApplicationName(appDO.getApplicationName()); validationResponseDTO.setCallbackURL(callbackURI); validationResponseDTO.setPkceMandatory(appDO.isPkceMandatory());
/** * Returns the scope and the web application this particular token been issued to. * * @param oauthToken OAuth request token. * @return * @throws Exception */ public Parameters getScopeAndAppName(String oauthToken) throws Exception { OAuthConsumerDAO consumerDAO = new OAuthConsumerDAO(); Parameters params = consumerDAO.getRequestToken(oauthToken); OAuthAppDAO appDAO = new OAuthAppDAO(); OAuthAppDO oauthAppDO = appDAO.getAppInformation(params.getOauthConsumerKey()); Parameters resp = new Parameters(); resp.setScope(params.getScope()); resp.setAppName(oauthAppDO.getApplicationName()); return resp; }
/** * Returns the scope and the web application this particular token been issued to. * * @param oauthToken OAuth request token. * @return * @throws Exception */ public Parameters getScopeAndAppName(String oauthToken) throws Exception { OAuthConsumerDAO consumerDAO = new OAuthConsumerDAO(); Parameters params = consumerDAO.getRequestToken(oauthToken); OAuthAppDAO appDAO = new OAuthAppDAO(); OAuthAppDO oauthAppDO = appDAO.getAppInformation(params.getOauthConsumerKey()); Parameters resp = new Parameters(); resp.setScope(params.getScope()); resp.setAppName(oauthAppDO.getApplicationName()); return resp; }
appDTOs.add(buildConsumerAppDTO(appDO)); if (log.isDebugEnabled()) { log.debug("Found App: " + appDO.getApplicationName() + " for user: " + username);
app = apps[i]; dto = new OAuthConsumerAppDTO(); dto.setApplicationName(app.getApplicationName()); dto.setCallbackUrl(app.getCallbackUrl()); dto.setOauthConsumerKey(app.getOauthConsumerKey());
/** * Get OAuth application data by the application name. * * @param appName OAuth application name * @return <code>OAuthConsumerAppDTO</code> with application information * @throws Exception Error when reading application information from persistence store. */ public OAuthConsumerAppDTO getOAuthApplicationDataByAppName(String appName) throws IdentityOAuthAdminException { OAuthConsumerAppDTO dto = new OAuthConsumerAppDTO(); OAuthAppDAO dao = new OAuthAppDAO(); try { OAuthAppDO app = dao.getAppInformationByAppName(appName); if (app != null) { dto.setApplicationName(app.getApplicationName()); dto.setCallbackUrl(app.getCallbackUrl()); dto.setOauthConsumerKey(app.getOauthConsumerKey()); dto.setOauthConsumerSecret(app.getOauthConsumerSecret()); dto.setOAuthVersion(app.getOauthVersion()); dto.setGrantTypes(app.getGrantTypes()); dto.setPkceMandatory(app.isPkceMandatory()); dto.setPkceSupportPlain(app.isPkceSupportPlain()); } return dto; } catch (InvalidOAuthClientException | IdentityOAuth2Exception e) { throw new IdentityOAuthAdminException("Error while retrieving the app information by app name", e); } }
/** * Get OAuth application data by the consumer key. * * @param consumerKey Consumer Key * @return <code>OAuthConsumerAppDTO</code> with application information * @throws Exception Error when reading application information from persistence store. */ public OAuthConsumerAppDTO getOAuthApplicationData(String consumerKey) throws IdentityOAuthAdminException { OAuthConsumerAppDTO dto = new OAuthConsumerAppDTO(); OAuthAppDAO dao = new OAuthAppDAO(); try { OAuthAppDO app = dao.getAppInformation(consumerKey); if (app != null) { dto.setApplicationName(app.getApplicationName()); dto.setCallbackUrl(app.getCallbackUrl()); dto.setOauthConsumerKey(app.getOauthConsumerKey()); dto.setOauthConsumerSecret(app.getOauthConsumerSecret()); dto.setOAuthVersion(app.getOauthVersion()); dto.setGrantTypes(app.getGrantTypes()); dto.setPkceMandatory(app.isPkceMandatory()); dto.setPkceSupportPlain(app.isPkceSupportPlain()); } return dto; } catch (InvalidOAuthClientException | IdentityOAuth2Exception e) { throw new IdentityOAuthAdminException("Error while retrieving the app information using consumer key", e); } }
dto.setApplicationName(appDO.getApplicationName()); dto.setCallbackUrl(appDO.getCallbackUrl()); dto.setOauthConsumerKey(appDO.getOauthConsumerKey());