import io.netty.channel.ChannelFuture;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
+import io.netty.util.internal.PlatformDependent;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
+import java.security.AccessControlException;
import org.opendaylight.controller.config.api.JmxAttributeValidationException;
import org.opendaylight.protocol.bgp.rib.impl.BGPServerSessionValidator;
/**
-* BGP peer acceptor that handles incomming bgp connections.
+* BGP peer acceptor that handles incoming bgp connections.
*/
public class BGPPeerAcceptorModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractBGPPeerAcceptorModule {
public BGPPeerAcceptorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
@Override
public void customValidation() {
+ // check if unix root user
+ if (!PlatformDependent.isWindows() && !PlatformDependent.isRoot() && getBindingPort().getValue() < 1024) {
+ throw new AccessControlException("Unable to bind port " + getBindingPort().getValue() + " while running as non-root user.");
+ }
// Try to parse address
try {
getAddress();
*/
package org.opendaylight.controller.config.yang.bgp.rib.impl;
+import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Mockito.doNothing;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.util.concurrent.GenericFutureListener;
+import io.netty.util.internal.PlatformDependent;
import java.net.InetSocketAddress;
import java.util.List;
import javax.management.InstanceAlreadyExistsException;
import javax.management.ObjectName;
+import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
}
@Test
- public void testCreateBeanDefaultAddress() throws Exception {
- final CommitStatus status = createRegistryInstance(Optional.<String>absent(), Optional.<Integer>absent(), true, true);
- assertBeanCount(1, FACTORY_NAME);
- assertStatus(status, 3, 0, 0);
- verify(dispatcher).createServer(any(BGPPeerRegistry.class), any(InetSocketAddress.class), any(BGPSessionValidator.class));
+ public void testCreateBeanDefaultAddress() throws InstanceAlreadyExistsException, ConflictingVersionException, ValidationException {
+ try {
+ final CommitStatus status = createRegistryInstance(Optional.<String>absent(), Optional.<Integer>absent(), true, true);
+ assertBeanCount(1, FACTORY_NAME);
+ assertStatus(status, 3, 0, 0);
+ verify(dispatcher).createServer(any(BGPPeerRegistry.class), any(InetSocketAddress.class), any(BGPSessionValidator.class));
+ } catch (ValidationException e) {
+ if(!PlatformDependent.isWindows() && !PlatformDependent.isRoot()) {
+ Assert.assertTrue(e.getMessage().contains("Unable to bind port"));
+ } else {
+ fail();
+ }
+ }
}
@Test