List of usage examples for org.apache.commons.codec.digest DigestUtils shaHex
@Deprecated public static String shaHex(String data)
From source file:org.asimba.idp.profile.catalog.saml2.SAML2Catalog.java
/** * Create a proxied IDP EntityDescriptor<br/> * This EntityDescriptor contains the EntityID of the supplied IDP, but * the endpoints are rewritten, so they are routed through this Asimba SAML2 IDP<br/> * //www. j a va 2 s . c o m * Supports:<br/> * <ul> * <li>NameIDFormat from Asimba SAML2 IDP</li> * <li>SingleSignOnService, SingleLogoutService, ArtifactResolutionService from SAML2 IDP</li> * </ul> * * The reference that is added to the SSO/SLO/AR endpoints, is encoded like: * [endpoint]/i=[sha1-hash-of-entity-id||lowercase-hexstring-encoded] * Example (for EntityID = '12345' (without the quotes)): * https://www.asimba.org/profiles/saml2/sso/web/i=2672275fe0c456fb671e4f417fb2f9892c7573ba * * <b>note</b> Requires ShadowIDP support to be enabled in the SAML2 IDP Profile! * * @param oIDP * @param oTheAsimbaEntityDescriptor * @return * @throws OAException */ protected EntityDescriptor getProxiedIDPEntityDescriptor(IIDP oIDP, EntityDescriptor oTheAsimbaEntityDescriptor) throws OAException { // Prepare to build XMLObjectBuilderFactory oBuilder = Configuration.getBuilderFactory(); IDPSSODescriptor oTheAsimbaIDPSSODescriptor = oTheAsimbaEntityDescriptor .getIDPSSODescriptor(SAMLConstants.SAML20P_NS); // 1. Get EntityDescriptorBuilder (opensaml class!) org.opensaml.saml2.metadata.impl.EntityDescriptorBuilder oBuilder_ED = (org.opensaml.saml2.metadata.impl.EntityDescriptorBuilder) oBuilder .getBuilder(EntityDescriptor.DEFAULT_ELEMENT_NAME); EntityDescriptor oED_publish = oBuilder_ED.buildObject(); // Set main properties: oED_publish.setEntityID(oIDP.getID()); // 2. Get RoleDescriptorBuilder for IDPSSODescriptor: org.opensaml.saml2.metadata.impl.IDPSSODescriptorBuilder oBuilder_IDPSSO = (org.opensaml.saml2.metadata.impl.IDPSSODescriptorBuilder) oBuilder .getBuilder(IDPSSODescriptor.DEFAULT_ELEMENT_NAME); IDPSSODescriptor oIDPSSO_publish = oBuilder_IDPSSO.buildObject(); oIDPSSO_publish.addSupportedProtocol(SAMLConstants.SAML20P_NS); // 3. Copy some local properties: if (oTheAsimbaIDPSSODescriptor.getWantAuthnRequestsSigned()) { oIDPSSO_publish.setWantAuthnRequestsSigned(true); } // 3.1. Copy NameIDFormat from Asimba's config: try { List<NameIDFormat> l = oTheAsimbaIDPSSODescriptor.getNameIDFormats(); if (l != null) { for (NameIDFormat nf : l) { NameIDFormat oNF_new; // oNF_new = (NameIDFormat) cloneXMLObject_usingDOM(nf); // oNF_new = (NameIDFormat) cloneXMLObject(nf); oNF_new = (NameIDFormat) XMLObjectHelper.cloneXMLObject(nf, true); oIDPSSO_publish.getNameIDFormats().add(oNF_new); } } } catch (MarshallingException e) { _oLogger.warn( "Could not add IDP '" + oIDP.getID() + "'; due to marshalling problem with NameIDFormat."); return null; } catch (UnmarshallingException e) { _oLogger.warn( "Could not add IDP '" + oIDP.getID() + "'; due to unmarshalling problem with NameIDFormat."); return null; } String sShadowIDPAlias = DigestUtils.shaHex(oIDP.getID()); // 3.2. Copy (and remap?) SingleSignOnService, SingleLogoutService, ArtifactResolutionService endpoints try { List<SingleSignOnService> lsso = oTheAsimbaIDPSSODescriptor.getSingleSignOnServices(); if (lsso != null) { for (SingleSignOnService ssos : lsso) { SingleSignOnService oSSOS_new; // oSSOS_new = (SingleSignOnService) cloneXMLObject_usingDOM(ssos); oSSOS_new = (SingleSignOnService) XMLObjectHelper.cloneXMLObject(ssos, true); // Rewrite endpoint to include entityid-reference: String sEndpoint = ssos.getLocation(); sEndpoint = sEndpoint + "/i=" + sShadowIDPAlias; oSSOS_new.setLocation(sEndpoint); oIDPSSO_publish.getSingleSignOnServices().add(oSSOS_new); } } if (_bEnableProxiedLogoutService) { List<SingleLogoutService> lsl = oTheAsimbaIDPSSODescriptor.getSingleLogoutServices(); if (lsl != null) { for (SingleLogoutService sls : lsl) { SingleLogoutService oSLS_new; // oSLS_new = (SingleLogoutService) cloneXMLObject_usingDOM(sls); oSLS_new = (SingleLogoutService) XMLObjectHelper.cloneXMLObject(sls, true); // Rewrite endpoint to include entityid-reference: String sEndpoint = sls.getLocation(); sEndpoint = sEndpoint + "/i=" + sShadowIDPAlias; oSLS_new.setLocation(sEndpoint); oIDPSSO_publish.getSingleLogoutServices().add(oSLS_new); } } } if (_bEnableProxiedArtifactResolutionService) { List<ArtifactResolutionService> lars = oTheAsimbaIDPSSODescriptor.getArtifactResolutionServices(); if (lars != null) { for (ArtifactResolutionService ars : lars) { ArtifactResolutionService oARS_new; // oARS_new = (ArtifactResolutionService) cloneXMLObject_usingDOM(ars); oARS_new = (ArtifactResolutionService) XMLObjectHelper.cloneXMLObject(ars, true); // Rewrite endpoint to include entityid-reference: String sEndpoint = ars.getLocation(); sEndpoint = sEndpoint + "/i=" + sShadowIDPAlias; oARS_new.setLocation(sEndpoint); oIDPSSO_publish.getArtifactResolutionServices().add(oARS_new); } } } } catch (MarshallingException e) { _oLogger.warn("Could not add IDP '" + oIDP.getID() + "'; due to marshalling problem with Services."); return null; } catch (UnmarshallingException e) { _oLogger.warn("Could not add IDP '" + oIDP.getID() + "'; due to unmarshalling problem with Services."); return null; } // 3.3. Copy <extensions> when they exist try { Extensions ext = oTheAsimbaIDPSSODescriptor.getExtensions(); if (ext != null) { // Extensions oExt_new = (Extensions) cloneXMLObject_usingDOM(ext); Extensions oExt_new = (Extensions) XMLObjectHelper.cloneXMLObject(ext, true); oIDPSSO_publish.setExtensions(oExt_new); } } catch (MarshallingException e) { _oLogger.warn("Could not add IDP '" + oIDP.getID() + "'; due to marshalling problem with Extensions."); return null; } catch (UnmarshallingException e) { _oLogger.warn( "Could not add IDP '" + oIDP.getID() + "'; due to unmarshalling problem with Extensions."); return null; } // 3.4. Add our LOCAL signing key KeyDescriptor oKD = getSigningKeyDescriptor(oBuilder, Engine.getInstance().getCryptoManager(), oIDP.getID()); if (oKD != null) { oIDPSSO_publish.getKeyDescriptors().add(oKD); } // 3.5. Add results oED_publish.getRoleDescriptors().add(oIDPSSO_publish); // 3.6. Add to catalog return oED_publish; }
From source file:org.asimba.util.saml2.metadata.provider.MetadataProviderConfiguration.java
/** * Establish a fingerprint of the configuration * @return/*from ww w. j a va2 s. c om*/ */ public String getFingerprint() { StringBuilder oResult = new StringBuilder(); if (_sURL != null) { oResult.append(FINGERPRINT_PROVIDER_HTTP).append(",").append(_sURL).append(",").append(_iTimeout); } else if (_sFilename != null) { oResult.append(FINGERPRINT_PROVIDER_FILE).append(",").append(_sFilename); } else if (_sMetadata != null) { oResult.append(FINGERPRINT_PROVIDER_STRING).append(",").append(DigestUtils.shaHex(_sMetadata)); } else oResult.append(FINGERPRINT_PROVIDER_UNKNOWN); return oResult.toString(); }
From source file:org.asimba.util.saml2.nameid.handler.MSO365PersistentFormatHandler.java
/** * Generate the ImmutableId value as://from w ww.j a va 2 s . c om * uppercase( hexstring( sha1( UserAttributes[ _sUIDAttributeName ] ) ) ) * @param oUser Authenticated user, must have an attribute _sUIDAttributeName in its IAttributes collection * @return generated ImmutableId */ protected String generateMSO365ImmutableId(IUser oUser) { String sUid = getUserAttributeValue(oUser, _sUIDAttributeName, false); // just take the value if (sUid == null) { _oLogger.warn("No attribute '" + _sUIDAttributeName + "' available; could not generate ImmutableId! (available: " + oUser.getAttributes().toString() + ")"); return null; } // Do the sha1 thing: String sResult = DigestUtils.shaHex(sUid); return sResult.toUpperCase(Locale.ENGLISH); }
From source file:org.bigbluebutton.api.ParamsProcessorUtil.java
public String convertToInternalMeetingId(String extMeetingId) { return DigestUtils.shaHex(extMeetingId); }
From source file:org.bigbluebutton.api.ParamsProcessorUtil.java
public boolean isConfigXMLChecksumSame(String meetingID, String configXML, String checksum) { if (StringUtils.isEmpty(securitySalt)) { log.warn("Security is disabled in this service. Make sure this is intentional."); return true; }/*from w w w . j av a 2 s. c om*/ String cs = DigestUtils.shaHex(meetingID + configXML + securitySalt); log.debug("our checksum: [{}], client: [{}]", cs, checksum); System.out.println("our checksum: [" + cs + "] client: [" + checksum + "]"); if (cs == null || cs.equals(checksum) == false) { log.info("checksumError: request did not pass the checksum security check"); return false; } log.debug("checksum ok: request passed the checksum security check"); return true; }
From source file:org.bigbluebutton.api.ParamsProcessorUtil.java
public boolean isChecksumSame(String apiCall, String checksum, String queryString) { log.debug("checksum: [{}] ; query string: [{}]", checksum, queryString); if (StringUtils.isEmpty(securitySalt)) { log.warn("Security is disabled in this service. Make sure this is intentional."); return true; }//from ww w .j ava 2 s . c o m // handle either checksum as first or middle / end parameter // TODO: this is hackish - should be done better queryString = queryString.replace("&checksum=" + checksum, ""); queryString = queryString.replace("checksum=" + checksum + "&", ""); queryString = queryString.replace("checksum=" + checksum, ""); log.debug("query string after checksum removed: [{}]", queryString); String cs = DigestUtils.shaHex(apiCall + queryString + securitySalt); log.debug("our checksum: [{}], client: [{}]", cs, checksum); if (cs == null || cs.equals(checksum) == false) { log.info("checksumError: request did not pass the checksum security check"); return false; } log.debug("checksum ok: request passed the checksum security check"); return true; }
From source file:org.bigbluebutton.api.ParamsProcessorUtil.java
public boolean isPostChecksumSame(String apiCall, HashMap<String, String[]> params) { if (StringUtils.isEmpty(securitySalt)) { log.warn("Security is disabled in this service. Make sure this is intentional."); return true; }/*from ww w. j ava 2s . co m*/ StringBuffer csbuf = new StringBuffer(); csbuf.append(apiCall); SortedSet<String> keys = new TreeSet<String>(params.keySet()); boolean first = true; String checksum = null; for (String key : keys) { if (key.equals("checksum")) { // Don't include the "checksum" parameter in the checksum checksum = params.get(key)[0]; continue; } for (String value : params.get(key)) { if (first) { first = false; } else { csbuf.append("&"); } csbuf.append(key); csbuf.append("="); String encResult; try { // we need to re-encode the values because Grails unencoded it // when it received the 'POST'ed data. Might not need to do in a GET request. encResult = URLEncoder.encode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { encResult = value; } csbuf.append(encResult); } } csbuf.append(securitySalt); String baseString = csbuf.toString(); // System.out.println( "POST basestring = [" + baseString + "]"); String cs = DigestUtils.shaHex(baseString); //System.out.println("our checksum: [" + cs + "], client: [" + checksum + "]"); //log.debug("our checksum: [{}], client: [{}]", cs, checksum); if (cs == null || cs.equals(checksum) == false) { log.info("checksumError: request did not pass the checksum security check"); return false; } log.debug("checksum ok: request passed the checksum security check"); return true; }
From source file:org.bigbluebutton.api.Proxy.java
/** Creates the checksum parameter to be included as part of the url */ private String getCheckSumParameterForQuery(String apiCall, String queryString) { if (this.salt != null) return "&checksum=" + DigestUtils.shaHex(apiCall + queryString + this.salt); else//from w ww.ja v a 2s.c om return ""; }
From source file:org.bigbluebutton.impl.BBBProxyImpl.java
/** Creates the checksum parameter to be included as part of the endpoint */ protected String getCheckSumParameterForQuery(String apiCall, String queryString) { if (this.secret != null) return "&checksum=" + DigestUtils.shaHex(apiCall + queryString + this.secret); else//from w w w . ja v a 2s . c o m return ""; }
From source file:org.boaboa.utils.SecurityUtils.java
public static String sha1(String texto) { String resultado = ""; try {// w ww . j a v a 2 s. c o m if (!StringUtils.isEmpty(texto)) { resultado = DigestUtils.shaHex(texto); } } catch (Exception e) { logger.error(e.toString()); } return resultado; }