public static boolean putOAuthApplicationData(OAuthApp oAuthApp) throws DynamicClientRegistrationException { boolean status = false; try { if (log.isDebugEnabled()) { log.debug("Persisting OAuth application data in Registry"); } StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(OAuthApp.class); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(oAuthApp, writer); Resource resource = DynamicClientWebAppRegistrationUtil.getGovernanceRegistry().newResource(); resource.setContent(writer.toString()); resource.setMediaType(DynamicClientRegistrationConstants.ContentTypes.MEDIA_TYPE_XML); String resourcePath = DynamicClientRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" + oAuthApp.getWebAppName(); status = DynamicClientWebAppRegistrationUtil.putRegistryResource(resourcePath, resource); } catch (RegistryException e) { throw new DynamicClientRegistrationException( "Error occurred while persisting OAuth application data : " + oAuthApp.getClientName(), e); } catch (JAXBException e) { e.printStackTrace(); } return status; }
public static OAuthApp getOAuthApplicationData(String appName) throws DynamicClientRegistrationException { Resource resource; String resourcePath = DynamicClientRegistrationConstants.OAUTH_APP_DATA_REGISTRY_PATH + "/" + appName; try { resource = DynamicClientWebAppRegistrationUtil.getRegistryResource(resourcePath); if (resource != null) { JAXBContext context = JAXBContext.newInstance(OAuthApp.class); Unmarshaller unmarshaller = context.createUnmarshaller(); return (OAuthApp) unmarshaller.unmarshal( new StringReader( new String( (byte[]) resource.getContent(), Charset.forName( DynamicClientRegistrationConstants.CharSets.CHARSET_UTF8)))); } return new OAuthApp(); } catch (JAXBException e) { throw new DynamicClientRegistrationException( "Error occurred while parsing the OAuth application data : " + appName, e); } catch (RegistryException e) { throw new DynamicClientRegistrationException( "Error occurred while retrieving the Registry resource of OAuth application : " + appName, e); } }
public static Resource getRegistryResource(String path) throws DynamicClientRegistrationException { try { Registry governanceRegistry = DynamicClientWebAppRegistrationUtil.getGovernanceRegistry(); if (governanceRegistry.resourceExists(path)) { return governanceRegistry.get(path); } return null; } catch (RegistryException e) { throw new DynamicClientRegistrationException( "Error in retrieving registry resource : " + e.getMessage(), e); } }
public static boolean putRegistryResource(String path, Resource resource) throws DynamicClientRegistrationException { boolean status; try { Registry governanceRegistry = DynamicClientWebAppRegistrationUtil.getGovernanceRegistry(); governanceRegistry.beginTransaction(); governanceRegistry.put(path, resource); governanceRegistry.commitTransaction(); status = true; } catch (RegistryException e) { throw new DynamicClientRegistrationException( "Error occurred while persisting registry resource : " + e.getMessage(), e); } return status; }
public static RegistrationProfile constructRegistrationProfile( ServletContext servletContext, String webAppName) { RegistrationProfile registrationProfile = new RegistrationProfile(); registrationProfile.setGrantType( servletContext.getInitParameter( DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_GRANT_TYPE)); registrationProfile.setTokenScope( servletContext.getInitParameter( DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_TOKEN_SCOPE)); registrationProfile.setOwner(DynamicClientWebAppRegistrationUtil.getUserName()); // TODO : Need to get the hostname properly registrationProfile.setCallbackUrl("http://localhost:9763/" + webAppName); registrationProfile.setClientName(webAppName); registrationProfile.setSaasApp( Boolean.parseBoolean( servletContext.getInitParameter( DynamicClientWebAppRegistrationUtil.SP_PARAM_SAAS_APP))); return registrationProfile; }