本文整理汇总了Java中org.glassfish.jersey.internal.util.Base64.decode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.decode方法的具体用法?Java Base64.decode怎么用?Java Base64.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.jersey.internal.util.Base64
的用法示例。
在下文中一共展示了Base64.decode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBasicAuthEncodedBA
import org.glassfish.jersey.internal.util.Base64; //导入方法依赖的package包/类
private byte[] getBasicAuthEncodedBA(final String basicAuthEncoded) {
byte[] basicAuthDecodedBA;
try {
basicAuthDecodedBA = Base64.decode(basicAuthEncoded.getBytes(IOUtil.CHARSET_NAME_UTF_8));
} catch (final UnsupportedEncodingException e1) {
throw new RuntimeException(e1);
}
return basicAuthDecodedBA;
}
示例2: filter
import org.glassfish.jersey.internal.util.Base64; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) {
Method method = resourceInfo.getResourceMethod();
if (!method.isAnnotationPresent(PermitAll.class)) {
if (method.isAnnotationPresent(DenyAll.class)) {
requestContext.abortWith(ACCESS_FORBIDDEN);
return;
}
//Get request headers
final MultivaluedMap<String, String> headers = requestContext.getHeaders();
//Fetch authorization header
final List<String> authorization = headers.get(AUTHORIZATION_PROPERTY);
//If no authorization information present; block access
if (authorization == null || authorization.isEmpty()) {
requestContext.abortWith(ACCESS_DENIED);
return;
}
//Get encoded username and password
final String encodedUserPassword = authorization.get(0).replaceFirst(AUTHENTICATION_SCHEME + " ", "");
//Decode username and password
String usernameAndPassword = new String(Base64.decode(encodedUserPassword.getBytes()));
;
//Split username and password tokens
final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
final String username = tokenizer.nextToken();
final String password = tokenizer.nextToken();
//Verify user access
if (method.isAnnotationPresent(RolesAllowed.class)) {
RolesAllowed rolesAnnotation = method.getAnnotation(RolesAllowed.class);
Set<String> rolesSet = new HashSet<String>(Arrays.asList(rolesAnnotation.value()));
//Is user valid?
if (!isUserAllowed(username, password, rolesSet)) {
requestContext.abortWith(ACCESS_DENIED);
return;
}
}
}
}
示例3: filter
import org.glassfish.jersey.internal.util.Base64; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) {
Method method = resourceInfo.getResourceMethod();
//Access allowed for all
if (!method.isAnnotationPresent(PermitAll.class)) {
//Access denied for all
if (method.isAnnotationPresent(DenyAll.class)) {
requestContext.abortWith(ACCESS_FORBIDDEN);
return;
}
//Get request headers
final MultivaluedMap<String, String> headers = requestContext
.getHeaders();
//Fetch authorization header
final List<String> authorization = headers.get(
AUTHORIZATION_PROPERTY);
//If no authorization information present; block access
if (authorization == null || authorization.isEmpty()) {
requestContext.abortWith(ACCESS_DENIED);
return;
}
//Get encoded username and password
final String encodedUserPassword = authorization.get(0)
.replaceFirst(AUTHENTICATION_SCHEME + " ", "");
//Decode username and password
String usernameAndPassword = new String(Base64.decode(
encodedUserPassword.getBytes()));
//Split username and password tokens
final StringTokenizer tokenizer = new StringTokenizer(
usernameAndPassword, ":");
final String username = tokenizer.nextToken();
final String password = tokenizer.nextToken();
//Verifying Username and password
//System.out.println(username);
//System.out.println(password);
//Verify user access
if (method.isAnnotationPresent(RolesAllowed.class)) {
RolesAllowed rolesAnnotation = method.getAnnotation(
RolesAllowed.class);
Set<String> rolesSet = new HashSet<String>(Arrays.asList(
rolesAnnotation.value()));
//Is user valid?
if (!isUserAllowed(username, password, rolesSet)) {
requestContext.abortWith(ACCESS_DENIED);
return;
}
}
}
}
示例4: filter
import org.glassfish.jersey.internal.util.Base64; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
//Get request headers
final Map<String, Cookie> cookies = requestContext.getCookies();
//Fetch authorization header
final Cookie authorization = cookies.get(AUTHORIZATION_PROPERTY);
LOG.trace("URI : {}", requestContext.getUriInfo().getPath());
//If no authorization information present; block access
if( !(authorization == null) && ! requestContext.getUriInfo().getPath().equalsIgnoreCase(AuthenticateResource.PATH))
{
//Get encoded username and password
final String bearerCookie = authorization.getValue().replaceFirst(AUTHENTICATION_SCHEME + " ", "");
//Decode username and password
byte[] bearer = Base64.decode(bearerCookie.getBytes());
User user = UsersDao.getByBearer(bearer).orElseThrow(() -> new WebApplicationException(Response.Status.UNAUTHORIZED));
user.setRoles(RolesDao.getUserRoles(user));
LOG.trace("User accessing resource : {}", user);
requestContext.setSecurityContext(new ApiSecurityContext(user));
}
}
示例5: verifyDistributorAccount
import org.glassfish.jersey.internal.util.Base64; //导入方法依赖的package包/类
private boolean verifyDistributorAccount(HttpHeaders header, int distributorID)
{
boolean result = true;
//Get request headers
final MultivaluedMap<String, String> headers = header.getRequestHeaders();
//Fetch authorization header
final List<String> authorization = headers.get(AUTHORIZATION_PROPERTY);
//If no authorization information present; block access
if (authorization == null || authorization.isEmpty()) {
// requestContext.abortWith(ACCESS_DENIED);
return false;
}
//Get encoded username and password
final String encodedUserPassword = authorization.get(0).replaceFirst(AUTHENTICATION_SCHEME + " ", "");
//Decode username and password
String usernameAndPassword = new String(Base64.decode(encodedUserPassword.getBytes()));
System.out.println("Username:Password" + usernameAndPassword);
//Split username and password tokens
final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
final String username = tokenizer.nextToken();
final String password = tokenizer.nextToken();
DistributorStaff distributor = daoPrepared.checkDistributor(null,username,password);
// Distributor account exist and is enabled
if(distributor!=null && distributor.getEnabled())
{
// If code enters here implies that distributor account is used for update. So we need to check if
// the distributor is same as the one authorized.
if(distributor.getDistributorStaffID()!=distributorID)
{
// the user doing an update is not the same as the user whose profile is being updated so has to
// stop this operation, and should throw an unauthorized exception in this situation.
return false;
}
}
return true;
}
示例6: verifyEndUserAccount
import org.glassfish.jersey.internal.util.Base64; //导入方法依赖的package包/类
private boolean verifyEndUserAccount(HttpHeaders header, int endUserID)
{
boolean result = true;
//Get request headers
final MultivaluedMap<String, String> headers = header.getRequestHeaders();
//Fetch authorization header
final List<String> authorization = headers.get(AUTHORIZATION_PROPERTY);
//If no authorization information present; block access
if (authorization == null || authorization.isEmpty()) {
// requestContext.abortWith(ACCESS_DENIED);
return false;
}
//Get encoded username and password
final String encodedUserPassword = authorization.get(0).replaceFirst(AUTHENTICATION_SCHEME + " ", "");
//Decode username and password
String usernameAndPassword = new String(Base64.decode(encodedUserPassword.getBytes()));
System.out.println("Username:Password" + usernameAndPassword);
//Split username and password tokens
final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
final String username = tokenizer.nextToken();
final String password = tokenizer.nextToken();
EndUser endUser = endUserDAOPrepared.checkEndUser(null,username,password);
// Distributor account exist and is enabled
// if(endUser!=null && endUser.getEnabled())
{
// If code enters here implies that distributor account is used for update. So we need to check if
// the distributor is same as the one authorized.
if(endUser.getEndUserID()!=endUserID)
{
// the user doing an update is not the same as the user whose profile is being updated so has to
// stop this operation, and should throw an unauthorized exception in this situation.
return false;
}
}
return true;
}