@Override public Collection<? extends GrantedAuthority> getAuthorities() { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (String roleType : permissions.getRoleTypes()) { if (StringUtils.isNotBlank(roleType)) { SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(roleType); authorities.add(grantedAuthority); } } return Collections.unmodifiableCollection(authorities); }
public static String parseUserFromAuth(String authentication) { if (StringUtils.isBlank(authentication)) { return null; } int pos = authentication.indexOf(":"); if (pos < 0) return authentication; String name = authentication.substring(0, pos); return StringUtils.isNotBlank(name) ? name : null; } public static String parsePassFromAuth(String authentication) {
public static void requireInteger(RequestErrors errors, String value, String message) { if (StringUtils.isNotBlank(value)) { try { // noinspection ResultOfMethodCallIgnored Integer.valueOf(value); } catch (NumberFormatException e) { errors.add(message); } } } }
@Override public Collection<? extends GrantedAuthority> getAuthorities() { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (String roleType : permissions.getRoleTypes()) { if (StringUtils.isNotBlank(roleType)) { SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(roleType); authorities.add(grantedAuthority); } } return Collections.unmodifiableCollection(authorities); }
public static String parsePassFromAuth(String authentication) { if (StringUtils.isBlank(authentication)) { return null; } int pos = authentication.indexOf(":"); if (pos < 0) return null; String pass = authentication.substring(pos+1); return StringUtils.isNotBlank(pass) ? pass : null; }
protected EmailPush(@JsonProperty("toAddress") String toAddress, @JsonProperty("fromAddress") String fromAddress, @JsonProperty("emailSubject") String emailSubject, @JsonProperty("htmlContent") String htmlContent, @JsonProperty("callbackUrl") String callbackUrl, @JsonProperty("remoteHost") String remoteHost, @JsonProperty("remoteAddress") String remoteAddress, @JsonProperty("traits") Map<String, String> traits) { this.toAddress = toAddress; this.fromAddress = fromAddress; this.emailSubject = emailSubject; String content = StringUtils.getTagContents(htmlContent, "body", 0); this.htmlContent = StringUtils.isNotBlank(content) ? content : htmlContent; this.callbackUrl = callbackUrl; this.remoteHost = remoteHost; this.remoteAddress = remoteAddress; // Get a list of all the keys so that we can loop on the map // and remove anything without an actual value (purge nulls). if (traits != null) { this.traits.putAll(traits); } String[] keys = ReflectUtils.toArray(String.class, this.traits.keySet()); for (String key : keys) { if (StringUtils.isBlank(this.traits.get(key))) { this.traits.remove(key); } } }
private SesEmailPush(@JsonProperty("toAddress") String toAddress, @JsonProperty("fromAddress") String fromAddress, @JsonProperty("emailSubject") String emailSubject, @JsonProperty("htmlContent") String htmlContent, @JsonProperty("callbackUrl") String callbackUrl, @JsonProperty("remoteHost") String remoteHost, @JsonProperty("remoteAddress") String remoteAddress, @JsonProperty("traits") Map<String, String> traits) { this.toAddress = toAddress; this.fromAddress = fromAddress; this.emailSubject = emailSubject; String content = StringUtils.getTagContents(htmlContent, "body", 0); this.htmlContent = StringUtils.isNotBlank(content) ? content : htmlContent; this.callbackUrl = callbackUrl; this.remoteHost = remoteHost; this.remoteAddress = remoteAddress; // Get a list of all the keys so that we can loop on the map // and remove anything without an actual value (purge nulls). if (traits != null) { this.traits.putAll(traits); } String[] keys = ReflectUtils.toArray(String.class, this.traits.keySet()); for (String key : keys) { if (StringUtils.isBlank(this.traits.get(key))) { this.traits.remove(key); } } }
private SmtpEmailPush(@JsonProperty("toAddress") String toAddress, @JsonProperty("fromAddress") String fromAddress, @JsonProperty("emailSubject") String emailSubject, @JsonProperty("htmlContent") String htmlContent, @JsonProperty("callbackUrl") String callbackUrl, @JsonProperty("remoteHost") String remoteHost, @JsonProperty("remoteAddress") String remoteAddress, @JsonProperty("traits") Map<String, String> traits) { this.toAddress = toAddress; this.fromAddress = fromAddress; this.emailSubject = emailSubject; String content = StringUtils.getTagContents(htmlContent, "body", 0); this.htmlContent = StringUtils.isNotBlank(content) ? content : htmlContent; this.callbackUrl = callbackUrl; this.remoteHost = remoteHost; this.remoteAddress = remoteAddress; // Get a list of all the keys so that we can loop on the map // and remove anything without an actual value (purge nulls). if (traits != null) { this.traits.putAll(traits); } String[] keys = ReflectUtils.toArray(String.class, this.traits.keySet()); for (String key : keys) { if (StringUtils.isBlank(this.traits.get(key))) { this.traits.remove(key); } } }
protected Invocation.Builder builder(String url, Map<String, Object> queryMap, String...acceptedResponseTypes) { Client client = ClientBuilder.newBuilder().build(); UriBuilder uriBuilder = UriBuilder.fromUri(getApiUrl()).path(url); for (Map.Entry<String,Object> queryParam : queryMap.entrySet()) { uriBuilder.queryParam(queryParam.getKey(), queryParam.getValue()); } WebTarget target = client.target(uriBuilder); Invocation.Builder builder = target.request(acceptedResponseTypes); if (StringUtils.isNotBlank(getUsername())) { builder.header("Authorization", getBasicAuthentication(getUsername(), getPassword())); } return builder; }
public static void requireNull(RequestErrors errors, Object value, String errorMessage) { if (value instanceof Integer) { if (((Integer)value) != 0) { errors.add(errorMessage); } } else if (value instanceof Long) { if (((Long)value) != 0) { errors.add(errorMessage); } } else if (StringUtils.isNotBlank(value)) { errors.add(errorMessage); } }
if (StringUtils.isNotBlank(googleAuth.getError())) { String msg = String.format("Authentication Error: %s", googleAuth.getError()); throw ApiException.internalServerError(msg);
protected WebApplicationContext createWebApplicationContext(ServletContext servletContext) { Class<?>[] configClasses = getSpringConfigClasses(servletContext); String configLocation = getSpringConfigLocation(servletContext); // We can only use one or the other... AbstractRefreshableWebApplicationContext appContext; if (StringUtils.isNotBlank(configLocation) && configClasses != null) { String msg = String.format("Only XML or Annotation configuration can be used but not both."); throw new IllegalArgumentException(msg); } else if (configClasses != null) { appContext = new AnnotationConfigWebApplicationContext(); ((AnnotationConfigWebApplicationContext)appContext).register(configClasses); } else if (StringUtils.isNotBlank(configLocation)) { appContext = new XmlWebApplicationContext(); appContext.setConfigLocation(configLocation); } else { String msg = String.format("Either an XML or Annotation configuration can be specified."); throw new IllegalArgumentException(msg); } String[] profiles = getSpringProfiles(servletContext, appContext); if (profiles != null && profiles.length > 0) { appContext.getEnvironment().setActiveProfiles(profiles); } // Refresh the spring context -- important, Jersey 2.x // Spring integration will not work with out it. appContext.setServletContext(servletContext); appContext.refresh(); return appContext; }
@Override public void doTag() throws JspException, IOException { try { Object path = getJspContext().findAttribute(languageTagResourcePath); if (path == null) { getJspContext().getOut().print("missing attribute "+languageTagResourcePath); return; } URL url = getClass().getResource(path.toString()); if (url == null) { getJspContext().getOut().print("missing resource "+path); return; } Properties properties = new Properties(); properties.load(new FileInputStream(new File(url.toURI()))); String propertyName = getLang()+"."+key; String value = properties.getProperty(propertyName); if (StringUtils.isNotBlank(value)) { getJspContext().getOut().print(value); } else { getJspContext().getOut().print("missing key "+propertyName); } } catch (URISyntaxException e) { getJspContext().getOut().print(e.getMessage()); } }
public static GoogleAuthentication getAuthResponse(String code, String clientId, String clientSecret) throws IOException { Client client = ClientBuilder.newBuilder().build(); Form form = new Form(); form.param("code", code); form.param("client_id", clientId); form.param("client_secret", clientSecret); form.param("grant_type", "authorization_code"); form.param("redirect_uri", "postmessage"); UriBuilder uriBuilder = new JerseyUriBuilder().uri("https://accounts.google.com/o/oauth2/token"); Response jerseyResponse = client.target(uriBuilder) .request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(form,MediaType.APPLICATION_FORM_URLENCODED_TYPE)); int status = jerseyResponse.getStatus(); String json = jerseyResponse.readEntity(String.class); YakJacksonObjectMapper objectMapper = new YakJacksonObjectMapper(); GoogleAuthentication googleAuth = objectMapper.readValue(json, GoogleAuthentication.class); // If there was an error in the token info, abort. if (StringUtils.isNotBlank(googleAuth.getError())) { String msg = String.format("Authentication Error: %s", googleAuth.getError()); throw ApiException.internalServerError(msg); } return googleAuth; }
private Connector createSslConnector(EmbeddedArgs args) { System.out.println("Creating SSL connector on port " + args.getSecurePort()); Connector connector = new Connector(Http11NioProtocol.class.getName()); Http11NioProtocol protocol = (Http11NioProtocol)connector.getProtocolHandler(); connector.setScheme("https"); connector.setSecure(true); connector.setPort(args.getSecurePort()); protocol.setSSLEnabled(true); if (StringUtils.isNotBlank(args.getKeystoreFile())) { protocol.setKeystoreFile(args.getKeystoreFile()); } if (StringUtils.isNotBlank(args.getKeystorePass())) { protocol.setKeystorePass(args.getKeystorePass()); } if (StringUtils.isNotBlank(args.getTruststoreFile())) { protocol.setTruststoreFile(args.getTruststoreFile()); } if (StringUtils.isNotBlank(args.getTruststorePass())) { protocol.setTruststorePass(args.getTruststorePass()); } if (StringUtils.isNotBlank(args.getKeyAlias())) { protocol.setKeyAlias(args.getKeyAlias()); } return connector; }
public String sendMessage() throws XMPPException { JabberFactory factory = new JabberFactory(config.getUserName(), config.getPassword()); String message = push.getMessage(); message = appContext.getBitlyApi().parseAndShorten(message); if (StringUtils.isNotBlank(config.getRecipientOverride())) { // This is NOT a "production" request. factory.sendTo(config.getRecipientOverride(), message); return String.format("Request sent to recipient override, %s.", config.getRecipientOverride()); } else { // This IS a "production" request. factory.sendTo(push.getRecipient(), message); return null; } } }
@Override public void test(PluginContext pluginContext, Domain domain) throws Exception { GoogleTalkConfig config = getConfig(pluginContext.getCouchServer(), domain); if (config == null) { String msg = "The Google Talk config has not been specified."; pluginContext.setLastMessage(msg); return; } String recipient = config.getTestAddress(); if (isBlank((recipient))) { String msg = "Test message cannot be sent with out specifying the test address."; pluginContext.setLastMessage(msg); return; } String override = config.getRecipientOverride(); if (isNotBlank(override)) { recipient = override; } String when = Formats.defaultStamp(new java.util.Date()); String msg = String.format("This is a test message from Cosmic Push sent at %s.", when); GoogleTalkPush push = GoogleTalkPush.newPush(recipient, msg, null, "gtalk-test:true"); PushRequest pushRequest = new PushRequest(AppContext.CURRENT_API_VERSION, domain, push); pluginContext.getPushRequestStore().create(pushRequest); new GoogleTalkDelegate(pluginContext, domain, pushRequest, push, config).run(); msg = String.format("Test message sent to %s:\n%s", recipient, msg); pluginContext.setLastMessage(msg); }
if (StringUtils.isNotBlank(override)) { toAddress = override;
sendEmailRequest.withReplyToAddresses(push.getFromAddress()); if (StringUtils.isNotBlank(config.getRecipientOverride())) {