Skip to content

Commit

Permalink
Fix NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ committed Feb 26, 2023
1 parent bab0e18 commit 60460d3
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,35 @@
*/
package org.apache.dubbo.qos.permission;

import java.net.InetAddress;
import java.net.InetSocketAddress;

import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.common.QosConfiguration;

import io.netty.channel.Channel;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Optional;

public class DefaultAnonymousAccessPermissionChecker implements PermissionChecker {
public static final DefaultAnonymousAccessPermissionChecker INSTANCE = new DefaultAnonymousAccessPermissionChecker();

@Override
public boolean access(CommandContext commandContext, PermissionLevel defaultCmdRequiredPermissionLevel) {
final InetAddress inetAddress = ((InetSocketAddress) commandContext.getRemote().remoteAddress()).getAddress();
final InetAddress inetAddress = Optional.ofNullable(commandContext.getRemote())
.map(Channel::remoteAddress)
.map(InetSocketAddress.class::cast)
.map(InetSocketAddress::getAddress)
.orElse(null);

QosConfiguration qosConfiguration = commandContext.getQosConfiguration();
PermissionLevel currentLevel = qosConfiguration.getAnonymousAccessPermissionLevel();

// Local has private permission
if (inetAddress.isLoopbackAddress()) {
if (inetAddress != null && inetAddress.isLoopbackAddress()) {
currentLevel = PermissionLevel.PRIVATE;
} else if (qosConfiguration.getAcceptForeignIpWhitelistPredicate()
.test(inetAddress.getHostAddress())) {
} else if (inetAddress != null &&
qosConfiguration.getAcceptForeignIpWhitelistPredicate()
.test(inetAddress.getHostAddress())) {
currentLevel = PermissionLevel.PROTECTED;
}

Expand Down

0 comments on commit 60460d3

Please sign in to comment.