本文整理汇总了Java中org.apache.axiom.util.base64.Base64Utils类的典型用法代码示例。如果您正苦于以下问题:Java Base64Utils类的具体用法?Java Base64Utils怎么用?Java Base64Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Base64Utils类属于org.apache.axiom.util.base64包,在下文中一共展示了Base64Utils类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateHmacSha1
import org.apache.axiom.util.base64.Base64Utils; //导入依赖的package包/类
/**
* @param key
* @param value
* @return
* @throws SignatureException
*/
public static String calculateHmacSha1(String key, String value) throws SignatureException {
String result;
try {
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(signingKey);
byte[] rawHmac = mac.doFinal(value.getBytes());
result = Base64Utils.encode(rawHmac);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("Failed to create the HMAC Signature", e);
}
throw new SignatureException("Failed to calculate HMAC : " + e.getMessage());
}
return result;
}
示例2: setBasicAccessSecurityHeaders
import org.apache.axiom.util.base64.Base64Utils; //导入依赖的package包/类
public static void setBasicAccessSecurityHeaders(String userName, String password, boolean rememberMe,
Options options) throws AxisFault {
String userNamePassword = userName + ":" + password;
String encodedString = Base64Utils.encode(userNamePassword.getBytes());
String authorizationHeader = "Basic " + encodedString;
List<Header> headers = new ArrayList<Header>();
Header authHeader = new Header("Authorization", authorizationHeader);
headers.add(authHeader);
if (rememberMe) {
Header rememberMeHeader = new Header("RememberMe", "true");
headers.add(rememberMeHeader);
}
options.setProperty(HTTPConstants.HTTP_HEADERS, headers);
}
示例3: init
import org.apache.axiom.util.base64.Base64Utils; //导入依赖的package包/类
@Override
/**
*
*/
public void init(Property[] provisioningProperties) throws IdentityProvisioningException {
Properties configs = new Properties();
if (provisioningProperties != null && provisioningProperties.length > 0) {
for (Property property : provisioningProperties) {
if (GoogleConnectorConstants.PRIVATE_KEY.equals(property.getName())) {
FileOutputStream fos = null;
try {
byte[] decodedBytes = Base64Utils.decode(property.getValue());
googlePrvKey = new File("googlePrvKey");
fos = new FileOutputStream(googlePrvKey);
fos.write(decodedBytes);
} catch (IOException e) {
log.error("Error while generating private key file object", e);
}finally {
IdentityIOStreamUtils.flushOutputStream(fos);
IdentityIOStreamUtils.closeOutputStream(fos);
}
}
configs.put(property.getName(), property.getValue());
if (IdentityProvisioningConstants.JIT_PROVISIONING_ENABLED.equals(property
.getName()) && "1".equals(property.getValue())) {
jitProvisioningEnabled = true;
}
}
}
configHolder = new GoogleProvisioningConnectorConfig(configs);
}
示例4: decodeAuthorizationHeader
import org.apache.axiom.util.base64.Base64Utils; //导入依赖的package包/类
private String decodeAuthorizationHeader(String authorizationHeader) {
String[] splitValues = authorizationHeader.trim().split(" ");
byte[] decodedBytes = Base64Utils.decode(splitValues[1].trim());
if (decodedBytes != null) {
return new String(decodedBytes);
} else {
if (log.isDebugEnabled()) {
log.debug("Error decoding authorization header.");
}
return null;
}
}
示例5: extractCredentialsFromAuthzHeader
import org.apache.axiom.util.base64.Base64Utils; //导入依赖的package包/类
/**
* Extracts the username and password info from the HTTP Authorization Header
*
* @param authorizationHeader "Basic " + base64encode(username + ":" + password)
* @return String array with client id and client secret.
* @throws org.wso2.carbon.identity.base.IdentityException If the decoded data is null.
*/
public static String[] extractCredentialsFromAuthzHeader(String authorizationHeader)
throws OAuthClientException {
String[] splitValues = authorizationHeader.trim().split(" ");
if(splitValues.length == 2) {
byte[] decodedBytes = Base64Utils.decode(splitValues[1].trim());
if (decodedBytes != null) {
String userNamePassword = new String(decodedBytes, Charsets.UTF_8);
return userNamePassword.split(":");
}
}
String errMsg = "Error decoding authorization header. Space delimited \"<authMethod> <base64Hash>\" format violated.";
throw new OAuthClientException(errMsg);
}
示例6: decodeAuthorizationHeader
import org.apache.axiom.util.base64.Base64Utils; //导入依赖的package包/类
private String decodeAuthorizationHeader(String authorizationHeader) {
String[] splitValues = authorizationHeader.trim().split(" ");
byte[] decodedBytes = Base64Utils.decode(splitValues[1].trim());
if (decodedBytes != null) {
return new String(decodedBytes);
} else {
log.debug(
"Error decoding authorization header. Could not retrieve user name and password.");
return null;
}
}
示例7: getSignedJWT
import org.apache.axiom.util.base64.Base64Utils; //导入依赖的package包/类
/**
* @param jsonObj
* @return Base64 encoded JWT
*/
public static String getSignedJWT(String jsonObj, ServiceProvider serviceProvider) {
String oauthConsumerSecret = null;
if (serviceProvider.getInboundAuthenticationConfig() != null
&& serviceProvider.getInboundAuthenticationConfig()
.getInboundAuthenticationRequestConfigs() != null
&& serviceProvider.getInboundAuthenticationConfig()
.getInboundAuthenticationRequestConfigs().length > 0) {
InboundAuthenticationRequestConfig[] authReqConfigs = serviceProvider
.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs();
for (InboundAuthenticationRequestConfig authReqConfig : authReqConfigs) {
if ((IdentityApplicationConstants.OAuth2.NAME).equals(authReqConfig.getInboundAuthType())) {
if (authReqConfig.getProperties() != null) {
for (Property property : authReqConfig.getProperties()) {
if ((IdentityApplicationConstants.OAuth2.OAUTH_CONSUMER_SECRET)
.equalsIgnoreCase(property.getName())) {
oauthConsumerSecret = property.getValue();
break;
}
}
}
}
}
}
String jwtBody = "{\"iss\":\"wso2\",\"exp\":" + new Date().getTime() + 3000 + ",\"iat\":"
+ new Date().getTime() + "," + jsonObj + "}";
String jwtHeader = "{\"typ\":\"JWT\", \"alg\":\"HS256\"}";
if (oauthConsumerSecret == null) {
jwtHeader = "{\"typ\":\"JWT\", \"alg\":\"none\"}";
}
String base64EncodedHeader = Base64Utils.encode(jwtHeader.getBytes());
String base64EncodedBody = Base64Utils.encode(jwtBody.getBytes());
if (log.isDebugEnabled()) {
log.debug("JWT Header :" + jwtHeader);
log.debug("JWT Body :" + jwtBody);
}
String assertion = base64EncodedHeader + "." + base64EncodedBody;
if (oauthConsumerSecret == null) {
return assertion + ".";
} else {
String signedAssertion;
try {
signedAssertion = calculateHmacSha1(oauthConsumerSecret, assertion);
return assertion + "." + signedAssertion;
} catch (SignatureException e) {
log.error("Error while siging the assertion", e);
return assertion + ".";
}
}
}
示例8: base64Encode
import org.apache.axiom.util.base64.Base64Utils; //导入依赖的package包/类
public static String base64Encode(byte[] bytes) {
return Base64Utils.encode(bytes);
}
示例9: doAuthentication
import org.apache.axiom.util.base64.Base64Utils; //导入依赖的package包/类
private void doAuthentication(HttpServletRequest req, HttpServletResponse resp) throws EntitlementCacheUpdateServletException {
String username = req.getParameter(USERNAME_STRING);
String password = req.getParameter(PSWD_STRING);
String remoteIp = req.getServerName();
if (authenticate(username, password, remoteIp)) {
RequestDispatcher requestDispatcher = req.getRequestDispatcher(UPDATE_CACHE);
String subjectScope = EntitlementCacheUpdateServletDataHolder.getInstance().getServletConfig().getServletContext()
.getInitParameter(SUBJECT_SCOPE);
String subjectAttributeName = EntitlementCacheUpdateServletDataHolder.getInstance().getServletConfig().getServletContext()
.getInitParameter("subjectAttributeName");
if (subjectScope.equals(EntitlementConstants.REQUEST_PARAM)) {
requestDispatcher = req.getRequestDispatcher(UPDATE_CACHE + "?" + subjectAttributeName + "=" + username);
} else if (subjectScope.equals(EntitlementConstants.REQUEST_ATTIBUTE)) {
req.setAttribute(subjectAttributeName, username);
} else if (subjectScope.equals(EntitlementConstants.SESSION)) {
req.getSession().setAttribute(subjectAttributeName, username);
} else {
resp.setHeader("Authorization", Base64Utils.encode((username + ":" + password).getBytes(Charset.forName("UTF-8"))));
}
try {
requestDispatcher.forward(req, resp);
} catch (Exception e) {
log.error("Error occurred while dispatching request to /updateCacheAuth.do", e);
throw new EntitlementCacheUpdateServletException("Error occurred while dispatching request to /updateCacheAuth.do", e);
}
} else {
showAuthPage(req, resp);
}
}
示例10: readObject
import org.apache.axiom.util.base64.Base64Utils; //导入依赖的package包/类
private Object readObject(ParameterType paramType, OMElement node, boolean client) throws Exception {
switch (paramType.getType()) {
case BOOLEAN:
case DOUBLE:
case FLOAT:
case INT:
case LONG:
case STRING:
case ENUM:
case DATE:
case BYTE:
return node == null ? null : readSimpleObject(paramType, node.getLocalName(), node.getText(), client);
case OBJECT:
//descend - note possibly two levels if inside a collection recursion
OMElement _copy = this.currentNode;
currentNode = node;
Transcribable t = (Transcribable)paramType.getImplementationClass().newInstance();
t.transcribe(this, TranscribableParams.getAll(), client);
//ascend
this.currentNode = _copy;
return t;
case MAP:
Map map = new HashMap();
for (Iterator i = node.getChildElements(); i.hasNext();) {
OMElement element = (OMElement)i.next();
Object key = readSimpleObject(paramType.getComponentTypes()[0], node.getLocalName(), element.getAttributeValue(keyAttName), client);
map.put(key, readObject(paramType.getComponentTypes()[1], (OMElement)element.getChildElements().next(), client));
}
return map;
case LIST:
if (paramType.getComponentTypes()[0].getType() == ParameterType.Type.BYTE) {
try {
return Base64Utils.decode(node.getText());
} catch (Exception e) {
String message = "Unable to parse " + node.getText() + " as type " + paramType;
LOGGER.debug(message, e);
throw CougarMarshallingException.unmarshallingException("soap",message,e,client);
}
} else {
List list = new ArrayList();
for (Iterator i = node.getChildElements(); i.hasNext();) {
list.add(readObject(paramType.getComponentTypes()[0], (OMElement)i.next(),client));
}
return list;
}
case SET:
Set set = new HashSet();
for (Iterator i = node.getChildElements(); i.hasNext();) {
set.add(readObject(paramType.getComponentTypes()[0], (OMElement)i.next(),client));
}
return set;
}
return null;
}