List of usage examples for java.util Base64 getDecoder
public static Decoder getDecoder()
From source file:com.mobileman.moments.core.security.UserSecurityService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { final UserDetail userDetail; if (username.equalsIgnoreCase(this.adminUsername)) { userDetail = new UserDetail(this.adminUsername, this.adminPassword, UserRole.ADMIN, null); } else {//from w ww . j a v a 2s .c om User sysUser = getUserDetail(username); if (sysUser == null) { throw new UsernameNotFoundException("User with email " + username + " not found"); } // check for user exists HttpServletRequest request = getHttpServletRequest(); String tokenB64 = request.getHeader("AuthorizationToken"); if (tokenB64 != null && !"".equals(tokenB64)) { String token = null; try { token = new String(Base64.getDecoder().decode(tokenB64), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } UserCacheInfo userCacheInfo = cache.get(username); if (userCacheInfo != null) { synchronized (userCacheInfo) { sanitizeUserCacheInfo(userCacheInfo); // try to find token Date lastAccess = userCacheInfo.getTokens().get(token); if (lastAccess != null) { userCacheInfo.getTokens().put(token, new Date()); userDetail = getUserDetailsAuthenticated(sysUser); } else { // new device... userDetail = getUserDetailsPasswordCheck(sysUser, username, token); } } } else { userDetail = getUserDetailsPasswordCheck(sysUser, username, token); } } else { userDetail = getUserDetails(sysUser); } } return userDetail; }
From source file:halive.shootinoutside.common.core.game.map.GameMap.java
public static GameMap loadGameMapFromJSONString(String s) throws ParseException { JSONParser parser = new JSONParser(); Object obj = parser.parse(s); if (obj instanceof JSONObject) { JSONObject in = (JSONObject) obj; GameMap map = new GameMap(); //Verify Validity if (!in.get("type").equals("soTileMap")) return null; //TODO Implement Determination of the Deserializer depending on the version //Load Width/Height and Mapname map.mapName = in.get("mapName").toString(); map.width = (int) (long) in.get("width"); map.height = (int) (long) in.get("height"); //Load the Map Data byte[] mapData = Base64.getDecoder().decode((String) in.get("mapDataB64")); map.loadTilesFromByteArray(mapData); //Load the Spawnpositions int amtTeams = (int) (long) in.get("amtTeams"); if (amtTeams != Teams.values().length) { return null; }/*w w w. j a v a 2s . c o m*/ for (int i = 0; i < amtTeams; i++) { JSONObject o = (JSONObject) in.get("spawn_team_" + i); int len = (int) (long) o.get("length"); for (int j = 0; j < len; j++) { JSONObject oj = (JSONObject) o.get("" + j); map.spawnPositions[i].add(Vector2D.fromJSONObject(oj)); } } //Load the ItemLayer map.itemLayer = ItemLayer.fromJSONObject((JSONObject) in.get("itemLayer")); //Read the Image map.textureSheet = Base64.getDecoder().decode(in.get("tileImageB64").toString()); return map; } else { return null; } }
From source file:org.hawkular.openshift.auth.BasicAuthenticator.java
@Override public void handleRequest(HttpServerExchange serverExchange) throws Exception { if (users.isEmpty()) { endExchange(serverExchange, FORBIDDEN); return;/*from w ww . j ava 2s. co m*/ } String authorizationHeader = serverExchange.getRequestHeaders().getFirst(AUTHORIZATION); String usernamePasswordEncoded = authorizationHeader.substring(BASIC_PREFIX.length()); String usernamePassword = new String(Base64.getDecoder().decode(usernamePasswordEncoded)); String[] entries = usernamePassword.split(":", 2); if (entries.length != 2) { endExchange(serverExchange, FORBIDDEN); return; } String username = entries[0]; String password = entries[1]; if (users.containsKey(username) && isAuthorized(username, password)) { containerHandler.handleRequest(serverExchange); } else { endExchange(serverExchange, FORBIDDEN); } }
From source file:com.web.mavenproject6.controller.CameraController.java
@ResponseBody @RequestMapping(value = "/camera", method = RequestMethod.POST) public String upload(@RequestParam(value = "imgdata", required = false) String imgdata, HttpServletRequest request)//w w w .ja va2s.com throws FileNotFoundException, IOException, GeneralSecurityException, JSONException { if (StringUtils.isEmpty(imgdata)) { //return (new Date()).toString(); } JSONObject o = new JSONObject(imgdata); imgdata = new String(Base64.getDecoder().decode(o.getString("qr"))); JSONArray ar = new JSONArray(); JSONObject resultJson = new JSONObject(); JSONObject obj = new JSONObject(); obj.put("propNumber", "0000001"); obj.put("propDate", (new Date()).toString()); obj.put("fname", "?"); obj.put("sname", "");// obj.put("tname", "?");// obj.put("pasport", "898999");// obj.put("level", "10"); obj.put("userId", "10"); ar.add(obj); resultJson.put("user", ar); simpleLog.add(obj); return resultJson.toString(); }
From source file:de.mpg.mpdl.inge.util.AdminHelper.java
/** * Logs in the given user with the given password. * /*from w w w .ja va 2 s . co m*/ * @param userid The id of the user to log in. * @param password The password of the user to log in. * @return The handle for the logged in user. * @throws HttpException * @throws IOException * @throws ServiceException * @throws URISyntaxException */ public static String loginUser(String userid, String password) throws HttpException, IOException, ServiceException, URISyntaxException { String frameworkUrl = PropertyReader.getLoginUrl(); int delim1 = frameworkUrl.indexOf("//"); int delim2 = frameworkUrl.indexOf(":", delim1); String host; int port; if (delim2 > 0) { host = frameworkUrl.substring(delim1 + 2, delim2); port = Integer.parseInt(frameworkUrl.substring(delim2 + 1)); } else { host = frameworkUrl.substring(delim1 + 2); port = 80; } HttpClient client = new HttpClient(); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); PostMethod login = new PostMethod(frameworkUrl + "/aa/j_spring_security_check"); login.addParameter("j_username", userid); login.addParameter("j_password", password); ProxyHelper.executeMethod(client, login); login.releaseConnection(); CookieSpec cookiespec = CookiePolicy.getDefaultSpec(); Cookie[] logoncookies = cookiespec.match(host, port, "/", false, client.getState().getCookies()); Cookie sessionCookie = logoncookies[0]; PostMethod postMethod = new PostMethod(frameworkUrl + "/aa/login"); postMethod.addParameter("target", frameworkUrl); client.getState().addCookie(sessionCookie); ProxyHelper.executeMethod(client, postMethod); if (HttpServletResponse.SC_SEE_OTHER != postMethod.getStatusCode()) { throw new HttpException("Wrong status code: " + login.getStatusCode()); } String userHandle = null; Header headers[] = postMethod.getResponseHeaders(); for (int i = 0; i < headers.length; ++i) { if ("Location".equals(headers[i].getName())) { String location = headers[i].getValue(); int index = location.indexOf('='); userHandle = new String( Base64.getDecoder().decode(location.substring(index + 1, location.length()))); // System.out.println("location: "+location); // System.out.println("handle: "+userHandle); } } if (userHandle == null) { throw new ServiceException("User not logged in."); } return userHandle; }
From source file:de.micromata.genome.gwiki.page.impl.wiki.rte.els.RteImageDomElementListener.java
protected String handleDataImage(DomElementEvent event, String pageId) { if (StringUtils.isBlank(pageId) == true) { return pageId; }/*w w w . jav a2 s. co m*/ String src = event.getAttr("src"); // handle data:image/png;base64,iVBORw... if (StringUtils.startsWith(src, "data:image") == false) { return pageId; } int edix = src.indexOf(';'); if (edix == -1) { return pageId; } String mime = src.substring(5, edix); int suffixidx = mime.indexOf('/'); String suffix = null; if (suffixidx != -1) { suffix = mime.substring(suffixidx + 1); } String rest = src.substring(edix + 1); if (rest.startsWith("base64,") == false) { return pageId; } rest = rest.substring("base64,".length()); byte[] data; try { data = Base64.getDecoder().decode(rest); } catch (IllegalArgumentException ex) { GLog.warn(GWikiLogCategory.Wiki, "Cannot decode image base64"); return pageId; } String cpid = event.getParseContext().getCurrentPageId(); if (src.equals(pageId) == true) { if (cpid == null) { GLog.warn(GWikiLogCategory.Wiki, "Non editPageId set. Cannot convert base64 image"); return pageId; } pageId = getAutoImgPageId(event, cpid, suffix); if (pageId == null) { GLog.warn(GWikiLogCategory.Wiki, "Cannot create new image page id for base64image"); return pageId; } } GWikiElement imageElement = event.getWikiContext().getWikiWeb().findElement(pageId); if ((imageElement instanceof GWikiFileAttachment) == false) { if (imageElement != null) { GLog.warn(GWikiLogCategory.Wiki, "Cannot overwrite non attachment with image: " + pageId); return pageId; } String metaTemplateId = "admin/templates/FileWikiPageMetaTemplate"; imageElement = GWikiWebUtils.createNewElement(event.getWikiContext(), pageId, metaTemplateId, null); imageElement.getElementInfo().getProps().setStringValue(GWikiPropKeys.PARENTPAGE, cpid); } GWikiFileAttachment fat = (GWikiFileAttachment) imageElement; GWikiBinaryAttachmentArtefakt mpart = (GWikiBinaryAttachmentArtefakt) imageElement.getMainPart(); mpart.setStorageData(data); event.getWikiContext().getWikiWeb().saveElement(event.getWikiContext(), fat, false); return pageId; }
From source file:com.thoughtworks.go.server.util.EncryptionHelper.java
public static String decryptUsingAES(SecretKey secretKey, String dataToDecrypt) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { Cipher aesCipher = Cipher.getInstance("AES"); aesCipher.init(Cipher.DECRYPT_MODE, secretKey); byte[] bytePlainText = aesCipher.doFinal(Base64.getDecoder().decode(dataToDecrypt)); return new String(bytePlainText); }
From source file:org.xsystem.utils.Auxilary.java
public static byte[] decodeBase64(String src) { byte[] ret = Base64.getDecoder().decode(src); return ret; }
From source file:ai.susi.tools.JsonSignature.java
public static boolean verify(Map<String, byte[]> obj, PublicKey key) throws SignatureException, InvalidKeyException { if (!obj.containsKey(signatureString)) throw new SignatureException("No signature supplied"); Signature signature;//w w w.j a v a2s . c om try { signature = Signature.getInstance("SHA256withRSA"); } catch (NoSuchAlgorithmException e) { return false; //does not happen } byte[] sigString = obj.get(signatureString); byte[] sig = Base64.getDecoder().decode(sigString); obj.remove(signatureString); signature.initVerify(key); signature.update(obj.toString().getBytes(StandardCharsets.UTF_8)); boolean res = signature.verify(sig); obj.put(signatureString, sigString); return res; }
From source file:org.wso2.identity.iml.dsl.mediators.SAMLRequestProcessor.java
@Override public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback) throws Exception { if (log.isDebugEnabled()) { log.debug("Message received at " + getName()); }//from ww w . j a v a 2s . c o m CarbonMessage newReq; byte[] bytes; String contentLength = carbonMessage.getHeader(Constants.HTTP_CONTENT_LENGTH); if (contentLength != null) { newReq = new DefaultCarbonMessage(); bytes = new byte[Integer.parseInt(contentLength)]; newReq.setHeaders(carbonMessage.getHeaders()); carbonMessage.getProperties().forEach(newReq::setProperty); List<ByteBuffer> fullMessageBody = carbonMessage.getFullMessageBody(); int offset = 0; for (ByteBuffer byteBuffer : fullMessageBody) { newReq.addMessageBody(byteBuffer); ByteBuffer duplicate = byteBuffer.duplicate(); duplicate.get(bytes, offset, byteBuffer.capacity()); offset = offset + duplicate.capacity(); } newReq.setEndOfMsgAdded(true); String encodedRequest = new String(bytes); String urlDecodedRequest = URLDecoder.decode(encodedRequest.split("=", 2)[1], StandardCharsets.UTF_8.name()); String decodedRequest = new String(Base64.getDecoder().decode(urlDecodedRequest)); if (log.isDebugEnabled()) { log.debug("Decoded SAML request: " + decodedRequest); } AuthnRequest samlAuthnRequest = SAMLRequestParser(decodedRequest); RequestContext samlRequestContext = new RequestContext(); samlRequestContext.setHeaders(carbonMessage.getHeaders()); samlRequestContext.addContent("samlRequest", samlAuthnRequest); AuthenticationContext authenticationContext = new AuthenticationContext(); authenticationContext.getRequestContextMap().put("saml", samlRequestContext); newReq.setProperty("authenticationContext", authenticationContext); } else { newReq = carbonMessage; } return next(newReq, carbonCallback); }