List of usage examples for org.apache.commons.codec.binary StringUtils newStringUtf8
public static String newStringUtf8(final byte[] bytes)
String
by decoding the specified array of bytes using the UTF-8 charset. From source file:com.smartitengineering.cms.spi.impl.content.template.PythonContentCoProcessorGenerator.java
public ContentCoProcessor getGenerator(ContentCoProcessorTemplate template) throws InvalidTemplateException { try {//from w w w . j ava 2 s .c o m final ContentCoProcessor coProc = new JythonObjectFactory<ContentCoProcessor>(ContentCoProcessor.class, StringUtils.newStringUtf8(template.getTemplate())).createObject(); return new SynchronizedContentCoProcessorGeneratorDecorator(coProc); } catch (Exception ex) { logger.warn("Could not create Python based content co processor", ex); throw new InvalidTemplateException(ex); } }
From source file:hws.core.JobMaster.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("app-id").withDescription("String of the Application Id ") .hasArg().withArgName("AppId").create("aid")); options.addOption(OptionBuilder.withLongOpt("load").withDescription("load module pipeline").hasArg() .withArgName("Json-Base64").create()); options.addOption(OptionBuilder.withLongOpt("remove").withDescription("remove modules").hasArgs() .withArgName("ModuleNames").create("rm")); options.addOption(OptionBuilder.withLongOpt("zk-servers").withDescription("List of the ZooKeeper servers") .hasArgs().withArgName("zkAddrs").create("zks")); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); String appIdStr = null;/* w ww .j a va 2 s . co m*/ String modulePipelineBase64 = null; String modulePipelineJson = null; ModulePipeline modulePipeline = null; String[] moduleNames = null; if (cmd.hasOption("aid")) { appIdStr = cmd.getOptionValue("aid"); } String zksArgs = ""; String[] zkServers = null; if (cmd.hasOption("zks")) { zksArgs = "-zks"; zkServers = cmd.getOptionValues("zks"); for (String zks : zkServers) { zksArgs += " " + zks; } } if (cmd.hasOption("load")) { modulePipelineBase64 = cmd.getOptionValue("load"); modulePipelineJson = StringUtils.newStringUtf8(Base64.decodeBase64(modulePipelineBase64)); modulePipeline = Json.loads(modulePipelineJson, ModulePipeline.class); } else if (cmd.hasOption("rm")) { moduleNames = cmd.getOptionValues("rm"); } JobMaster master = new JobMaster(modulePipeline, appIdStr, zksArgs, zkServers); if (modulePipelineJson != null) { Logger.info("Module Pipeline: " + modulePipelineJson); Logger.info("Instances: " + Json.dumps(modulePipeline.instances())); } master.runMainLoop(); }
From source file:io.apiman.common.auth.AuthTokenUtil.java
/** * Produce a token suitable for transmission. This will generate the auth token, * then serialize it to a JSON string, then Base64 encode the JSON. * @param principal/* w ww . j a v a 2 s . c o m*/ * @param roles * @param expiresInMillis */ public static final String produceToken(String principal, Set<String> roles, int expiresInMillis) { AuthToken authToken = createAuthToken(principal, roles, expiresInMillis); String json = toJSON(authToken); return StringUtils.newStringUtf8(Base64.encodeBase64(StringUtils.getBytesUtf8(json))); }
From source file:net.dv8tion.jda.core.entities.Icon.java
/** * Creates an {@link Icon Icon} with the specified image data. * * @param data//from www . j ava2s . co m * not-null image data bytes. * @return * An Icon instance representing the specified image data * @throws IllegalArgumentException * if the provided data is null */ public static Icon from(byte[] data) { Args.notNull(data, "Provided byte[]"); String encoding = StringUtils.newStringUtf8(Base64.getEncoder().encode(data)); return new Icon(encoding); }
From source file:io.apiman.common.auth.AuthTokenUtil.java
/** * Consumes an auth token, validating it during the process. If successful, the * {@link AuthToken} is returned. If the token is invalid (expired or bad * signature) then an {@link IllegalArgumentException} is thrown. Any other * error will result in a runtime exception. * @param encodedJson// w w w .j a v a 2 s . c o m */ public static final AuthToken consumeToken(String encodedJson) throws IllegalArgumentException { String json = StringUtils.newStringUtf8(Base64.decodeBase64(encodedJson)); AuthToken token = fromJSON(json); validateToken(token); return token; }
From source file:com.ericsson.eiffel.remrem.generate.config.SecurityConfig.java
private String decode(String password) { return StringUtils.newStringUtf8(Base64.decodeBase64(password)); }
From source file:au.edu.apsr.pids.security.SSLHostAuthenticator.java
/** * run the authentication checking//w w w . ja v a2 s .c o m * * @return boolean * <code>true</code> if authenticates successfully otherwise <code>false</code> * * @param request * a HTTP Servlet request * * @throws ProcessingException */ public boolean authenticate(HttpServletRequest request) throws ProcessingException { // username String appId = null; // password String sharedSecret = null; // identifier####authDomain will be the value of the owner handle of this Handle String authDomain = null; String identifier = null; String ipAddress = null; final String authorization = request.getHeader("Authorization"); if (authorization != null && authorization.startsWith("Basic")) { // Authorization: Basic base64credentials String base64Credentials = authorization.substring("Basic".length()).trim(); String credentials = StringUtils.newStringUtf8(Base64.decodeBase64(base64Credentials)); ; // credentials = username:password final String[] values = credentials.split(":", 2); appId = values[0]; sharedSecret = values[1]; } if (appId == null) { if ((appId = (String) properties.get("appId")) == null) { log.error("appId is null"); return false; } ; } if ((authDomain = (String) properties.get("authDomain")) == null) { log.error("authDomain is null"); return false; } if ((identifier = (String) properties.get("identifier")) == null) { log.error("identifier is null"); return false; } // shared secret is optional if trusted client has valid IPs registered if (sharedSecret == null) { sharedSecret = (String) properties.get("sharedSecret"); } if ((ipAddress = request.getHeader("X-FORWARDED-FOR")) == null) { ipAddress = request.getRemoteAddr(); } TrustedClient tc = TrustedClient.retrieve(ipAddress, sharedSecret, appId); if (tc == null) { log.error("Request Denied - unregistered client: " + appId + ". Client must be registered in order to use service"); return false; } if (!isRegisteredIdentifier(identifier, authDomain)) { try { Handle.createAdmin(identifier, authDomain, appId); log.info("Identifier " + identifier + "," + authDomain + " is not a registered user of this service, added"); } catch (DAOException daoe) { log.error("Caught DAO Exception:", daoe); throw new ProcessingException(daoe); } catch (HandleException daoe) { log.error("Caught Handle Exception:", daoe); throw new ProcessingException(daoe); } } try { Identifier identifierObj = Identifier.retrieve(identifier, authDomain); if (identifierObj.getAppid() == null) { String handleString = identifierObj.getHandle(); Handle iHandle = Handle.find(handleString); HandleValue[] values = new HandleValue[1]; values[0] = new HandleValue(); values[0].setIndex(Constants.AGENT_DESC_APPIDX); values[0].setType(Constants.XT_APPID); values[0].setAnyoneCanRead(false); values[0].setData(Util.encodeString(appId)); values[0].setTTL(Constants.DEFAULT_TTL); iHandle.addValue(values); } else if (!identifierObj.getAppid().equals(appId)) { log.info("APPID MISMATCH: " + identifier + "#####" + authDomain + "'s AppID: " + identifierObj.getAppid() + " is different from provided appID:" + appId); } } catch (HandleException | DAOException daoe) { log.error("Caught Handle Exception during add appId to existing Identifier:", daoe); throw new ProcessingException(daoe); } return true; }
From source file:com.twosigma.beaker.chart.serializer.RastersSerializer.java
private String Bytes2Base64(byte[] bytes, String format) { StringBuilder sb = new StringBuilder(); if (format != null) sb.append("data:image/" + format + ";base64,"); else/*from w w w . j a va 2 s.com*/ sb.append("data:image/png;base64,"); sb.append(StringUtils.newStringUtf8(Base64.encodeBase64(bytes, false))); return sb.toString(); }
From source file:de.onyxbits.raccoon.gui.Traits.java
protected static String[] interpret(String inp, String mix) { byte[] dec = Base64.decodeBase64(inp); byte[] key = mix.getBytes(); int idx = 0;/*from www.j a va2s . c o m*/ for (int i = 0; i < dec.length; i++) { dec[i] = (byte) (dec[i] ^ key[idx]); idx = (idx + 1) % key.length; } return StringUtils.newStringUtf8(dec).split(SEP); }
From source file:de.onyxbits.raccoon.gui.Traits.java
protected static String smoke(String inp, String mix) { byte[] dec = inp.getBytes(); byte[] key = mix.getBytes(); int idx = 0;//from w w w . j a v a 2 s.c o m for (int i = 0; i < dec.length; i++) { dec[i] = (byte) (dec[i] ^ key[idx]); idx = (idx + 1) % key.length; } return StringUtils.newStringUtf8(Base64.encodeBase64(dec)); }