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:it.vige.greenarea.gtg.webservice.auth.LDAPauth.java
public static String doAuthentication(WebServiceContext wsContext) throws LDAPException { String result;//from ww w . j a va2 s . c om MessageContext mctx = wsContext.getMessageContext(); Map<String, Object> http_headers = (Map) mctx.get(MessageContext.HTTP_REQUEST_HEADERS); List<Object> list = (List) http_headers.get("Authorization"); if (list == null || list.isEmpty()) { result = "Authentication failed! This WS needs BASIC Authentication!"; throw new LDAPException(ResultCode.AUTH_METHOD_NOT_SUPPORTED, result); } String userpass = (String) list.get(0); userpass = userpass.substring(5); byte[] buf = Base64.decodeBase64(userpass.getBytes());// decodeBase64(userpass.getBytes()); String credentials = StringUtils.newStringUtf8(buf); String username; String password; int p = credentials.indexOf(":"); if (p > -1) { username = credentials.substring(0, p); password = credentials.substring(p + 1); } else { result = "There was an error while decoding the Authentication!"; throw new LDAPException(ResultCode.DECODING_ERROR, result); } /* * Creazione di una "Identity" Se non mi serve un sottodominio, posso * anche usare il costruttore Identity(usr,pwd) */ logger.debug("*** LOG *** username: " + username + " pwd: " + password); logger.debug("*** LOG *** username: " + username + " AUTHORIZED!"); return username; }
From source file:net.dv8tion.jda.utils.AvatarUtil.java
public static Avatar getAvatar(BufferedImage img) { try {//from w ww .j a v a 2 s . c o m //resizing img = resize(img); //writing + converting to jpg if necessary ByteArrayOutputStream bout = new ByteArrayOutputStream(); ImageIO.write(img, "jpg", bout); bout.close(); return new Avatar("data:image/jpeg;base64," + StringUtils.newStringUtf8(Base64.getEncoder().encode(bout.toByteArray()))); } catch (IOException e) { JDAImpl.LOG.log(e); } return null; }
From source file:com.smartitengineering.cms.spi.impl.content.template.PythonValidatorGenerator.java
@Override public FieldValidator getValidator(ValidatorTemplate template) throws InvalidTemplateException { try {// w w w. j a va2s. c o m final FieldValidator fieldVal = new JythonObjectFactory<FieldValidator>(FieldValidator.class, StringUtils.newStringUtf8(template.getTemplate())).createObject(); return new SynchronizedValidatorGeneratorDecorator(fieldVal); } catch (Exception ex) { logger.warn("Could not create Python based validator", ex); throw new InvalidTemplateException(ex); } }
From source file:com.smartitengineering.cms.spi.impl.content.template.PythonVariationGenerator.java
@Override public VariationGenerator getGenerator(VariationTemplate template) throws InvalidTemplateException { try {/*from w w w .j av a2s . co m*/ final VariationGenerator varGen = new JythonObjectFactory<VariationGenerator>(VariationGenerator.class, StringUtils.newStringUtf8(template.getTemplate())).createObject(); return new SynchronizedVariationGeneratorDecorator(varGen); } catch (Exception ex) { logger.warn("Could not create Python based variation generator", ex); throw new InvalidTemplateException(ex); } }
From source file:br.com.bob.dashboard.model.Team.java
@Override public String getJQueryName() { return StringUtils.newStringUtf8(name.getBytes()).replaceAll(" ", "_").toLowerCase(); }
From source file:com.smartitengineering.cms.spi.impl.content.template.PythonRepresentationGenerator.java
@Override public RepresentationGenerator getGenerator(RepresentationTemplate template) throws InvalidTemplateException { try {//from w ww .ja va2 s. c om final RepresentationGenerator repGen = new JythonObjectFactory<RepresentationGenerator>( RepresentationGenerator.class, StringUtils.newStringUtf8(template.getTemplate())) .createObject(); return new SynchronizedRepresentationGeneratorDecorator(repGen); } catch (Exception ex) { ex.printStackTrace(); throw new InvalidTemplateException(ex); } }
From source file:com.smartitengineering.cms.spi.impl.content.template.GroovyObjectFactory.java
public synchronized <T> T getObjectFromScript(byte[] script, Class<? extends T> clazz) throws InvalidTemplateException { try {//w w w . j a va2s .c o m clazz = groovyClassLoader.parseClass(StringUtils.newStringUtf8(script)); } catch (Exception ex) { throw new InvalidTemplateException(ex); } try { return clazz.newInstance(); } catch (Exception ex) { throw new InvalidTemplateException(ex); } }
From source file:com.smartitengineering.cms.spi.impl.content.template.JavascriptObjectFactory.java
public synchronized <T> T getObjectFromScript(byte[] data, Class<? extends T> clazz) throws InvalidTemplateException { try {//from ww w. j a v a2 s .c o m String script = StringUtils.newStringUtf8(data); final Context context = Context.enter(); final Scriptable scriptable = context.initStandardObjects(); Script myScript = context.compileString(script, "source", 0, null); Object object = myScript.exec(context, scriptable); T generator = (T) Context.jsToJava(object, clazz); return generator; } catch (Exception ex) { ex.printStackTrace(); throw new InvalidTemplateException(ex); } }
From source file:com.josue.eap.jboss.custom.loginmodule.rest.NewJaxRsFilter.java
@Override public void filter(ContainerRequestContext requestContext) { String apiKey = requestContext.getHeaderString("ApiKey"); if (apiKey != null) { //apikey based request } else {/*from w w w. java 2 s. co m*/ String authType = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION).split(" ")[0]; String credential = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION).split(" ")[1]; if (authType == null || credential == null) { requestContext.abortWith(Response.status(Response.Status.FORBIDDEN).build()); } final String decoded = StringUtils.newStringUtf8(Base64.decodeBase64(credential)); // requestContext.setSecurityContext(new SecurityContextImpl(new UserPasswordPrincipal("josue2", "admin"))); } }
From source file:com.smartitengineering.generator.engine.service.impl.scripting.JavascriptObjectFactory.java
public synchronized <T> T getObjectFromScript(byte[] data, Class<? extends T> clazz) throws InvalidTemplateException { try {//w w w . ja v a 2 s . co m String script = StringUtils.newStringUtf8(data); Script myScript = context.compileString(script, "source", 0, null); Object object = myScript.exec(context, scriptable); T generator = (T) Context.jsToJava(object, clazz); return generator; } catch (Exception ex) { throw new InvalidTemplateException(ex); } }