本文整理汇总了Java中org.apache.shiro.codec.Base64.decodeToString方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.decodeToString方法的具体用法?Java Base64.decodeToString怎么用?Java Base64.decodeToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.shiro.codec.Base64
的用法示例。
在下文中一共展示了Base64.decodeToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPreHandle
import org.apache.shiro.codec.Base64; //导入方法依赖的package包/类
@Override
protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
Subject subject = SecurityUtils.getSubject();
if (!subject.isAuthenticated()) {
HttpServletRequest httpRequest = WebUtils.toHttp(request);
String authzHeader = httpRequest.getHeader(AUTHORIZATION_HEADER);
if (authzHeader != null) {
if (authzHeader.toLowerCase(Locale.ENGLISH).startsWith("basic")
|| authzHeader.toLowerCase(Locale.ENGLISH).startsWith("token")) {
String authToken = StringUtils.substringAfter(authzHeader, " ");
String decoded = Base64.decodeToString(authToken);
String userName = StringUtils.substringBefore(decoded, ":").trim();
String password = StringUtils.substringAfter(decoded, ":").trim();
if (userName.length() != 0 && password.length() != 0) {
UsernamePasswordToken token = new UsernamePasswordToken(userName, password);
subject.login(token);
}
}
}
}
return true;
}
示例2: testBase64
import org.apache.shiro.codec.Base64; //导入方法依赖的package包/类
@Test
public void testBase64(){
String str = "hello";
String base64Encode = Base64.encodeToString(str.getBytes());
String str2 = Base64.decodeToString(base64Encode);
Assert.assertEquals(str, str2);
}
示例3: getPrincipalsAndCredentials
import org.apache.shiro.codec.Base64; //导入方法依赖的package包/类
/**
* <p>Returns the username obtained from the authorization header.</p>
* <p>
* Once the header is split per the RFC (based on the space character ' '), the resulting split tokens
* are translated into the username/password pair.</p>
*
* @param authorizationHeader the authorization header obtained from the request.
* @return the username (index 0)/password pair (index 1) submitted by the user for the given header value and request.
*/
protected String[] getPrincipalsAndCredentials(String authorizationHeader) {
String[] authTokens = authorizationHeader.split(" ", 2);
if (authTokens.length < 2) {
return null;
}
String decoded = Base64.decodeToString(authTokens[1]);
return decoded.split(":", 2);
}
示例4: decryptBase64
import org.apache.shiro.codec.Base64; //导入方法依赖的package包/类
/**
* base64进制解密
*
* @param content
* @return
*/
public static String decryptBase64(String content) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(content), "消息摘要不能为空");
return Base64.decodeToString(content);
}
示例5: decryptBase64
import org.apache.shiro.codec.Base64; //导入方法依赖的package包/类
/**
* base64进制解密
* @param cipherText
* @return
*/
public static String decryptBase64(String cipherText) {
return Base64.decodeToString(cipherText);
}
示例6: getPrincipalsAndCredentials
import org.apache.shiro.codec.Base64; //导入方法依赖的package包/类
/**
* Returns the username and password pair based on the specified <code>encoded</code> String obtained from
* the request's authorization header.
* <p/>
* Per RFC 2617, the default implementation first Base64 decodes the string and then splits the resulting decoded
* string into two based on the ":" character. That is:
* <p/>
* <code>String decoded = Base64.decodeToString(encoded);<br/>
* return decoded.split(":");</code>
*
* @param scheme the {@link #getAuthcScheme() authcScheme} found in the request
* {@link #getAuthzHeader(javax.servlet.ServletRequest) authzHeader}. It is ignored by this implementation,
* but available to overriding implementations should they find it useful.
* @param encoded the Base64-encoded username:password value found after the scheme in the header
* @return the username (index 0)/password (index 1) pair obtained from the encoded header data.
*/
protected String[] getPrincipalsAndCredentials(String scheme, String encoded) {
String decoded = Base64.decodeToString(encoded);
return decoded.split(":", 2);
}