use of io.envoyproxy.envoy.config.rbac.v3.Permission in project RxPermissions by tbruyelle.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RxPermissions rxPermissions = new RxPermissions(this);
rxPermissions.setLogging(true);
setContentView(R.layout.act_main);
surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
RxJavaInterop.toV2Observable(RxView.clicks(findViewById(R.id.enableCamera)).map(new Func1<Void, Object>() {
@Override
public Object call(final Void aVoid) {
return new Object();
}
})).compose(rxPermissions.ensureEach(permission.CAMERA)).subscribe(new Consumer<Permission>() {
@Override
public void accept(Permission permission) {
Log.i(TAG, "Permission result " + permission);
if (permission.granted) {
releaseCamera();
camera = Camera.open(0);
try {
camera.setPreviewDisplay(surfaceView.getHolder());
camera.startPreview();
} catch (IOException e) {
Log.e(TAG, "Error while trying to display the camera preview", e);
}
} else if (permission.shouldShowRequestPermissionRationale) {
// Denied permission without ask never again
Toast.makeText(MainActivity.this, "Denied permission without ask never again", Toast.LENGTH_SHORT).show();
} else {
// Denied permission with ask never again
// Need to go to the settings
Toast.makeText(MainActivity.this, "Permission denied, can't enable the camera", Toast.LENGTH_SHORT).show();
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable t) {
Log.e(TAG, "onError", t);
}
}, new Action() {
@Override
public void run() {
Log.i(TAG, "OnComplete");
}
});
}
use of io.envoyproxy.envoy.config.rbac.v3.Permission in project DevRing by LJYcoder.
the class PermissionManager method requestEachCombined.
// 请求多个权限建议用这个
public void requestEachCombined(Activity activity, final PermissionListener listener, String... permissions) {
if (activity != null) {
RxPermissions rxPermissions = new RxPermissions(activity);
rxPermissions.requestEachCombined(permissions).subscribe(new Consumer<Permission>() {
@Override
public void accept(Permission permission) throws Exception {
if (permission.granted) {
// All permissions are granted !
if (listener != null) {
listener.onGranted(permission.name);
}
} else if (permission.shouldShowRequestPermissionRationale) {
// At least one denied permission without ask never again
if (listener != null) {
listener.onDenied(permission.name);
}
} else {
// Need to go to the settings
if (listener != null) {
listener.onDeniedWithNeverAsk(permission.name);
}
}
}
});
}
}
use of io.envoyproxy.envoy.config.rbac.v3.Permission in project DevRing by LJYcoder.
the class PermissionManager method requestEach.
// 请求单个权限建议用这个
public void requestEach(Activity activity, final PermissionListener listener, String... permissions) {
if (activity != null) {
RxPermissions rxPermissions = new RxPermissions(activity);
rxPermissions.requestEach(permissions).subscribe(new Consumer<Permission>() {
@Override
public void accept(Permission permission) throws Exception {
if (permission.granted) {
// `permission.name` is granted !
if (listener != null) {
listener.onGranted(permission.name);
}
} else if (permission.shouldShowRequestPermissionRationale) {
// Denied permission without ask never again
if (listener != null) {
listener.onDenied(permission.name);
}
} else {
// Need to go to the settings
if (listener != null) {
listener.onDeniedWithNeverAsk(permission.name);
}
}
}
});
}
}
use of io.envoyproxy.envoy.config.rbac.v3.Permission in project grpc-java by grpc.
the class RbacFilterTest method compositeRules.
@Test
@SuppressWarnings("unchecked")
public void compositeRules() {
MetadataMatcher metadataMatcher = MetadataMatcher.newBuilder().build();
List<Permission> permissionList = Arrays.asList(Permission.newBuilder().setOrRules(Permission.Set.newBuilder().addRules(Permission.newBuilder().setMetadata(metadataMatcher).build()).build()).build());
List<Principal> principalList = Arrays.asList(Principal.newBuilder().setNotId(Principal.newBuilder().setMetadata(metadataMatcher).build()).build());
ConfigOrError<? extends FilterConfig> result = parse(permissionList, principalList);
assertThat(result.errorDetail).isNull();
assertThat(result.config).isInstanceOf(RbacConfig.class);
ServerCall<Void, Void> serverCall = mock(ServerCall.class);
GrpcAuthorizationEngine engine = new GrpcAuthorizationEngine(((RbacConfig) result.config).authConfig());
AuthDecision decision = engine.evaluate(new Metadata(), serverCall);
assertThat(decision.decision()).isEqualTo(GrpcAuthorizationEngine.Action.ALLOW);
}
use of io.envoyproxy.envoy.config.rbac.v3.Permission in project grpc-java by grpc.
the class RbacFilterTest method portRangeParser.
@Test
@SuppressWarnings({ "unchecked", "deprecation" })
public void portRangeParser() {
List<Permission> permissionList = Arrays.asList(Permission.newBuilder().setDestinationPortRange(Int32Range.newBuilder().setStart(1010).setEnd(65535).build()).build());
List<Principal> principalList = Arrays.asList(Principal.newBuilder().setRemoteIp(CidrRange.newBuilder().setAddressPrefix("10.10.10.0").setPrefixLen(UInt32Value.of(24)).build()).build());
ConfigOrError<?> result = parse(permissionList, principalList);
assertThat(result.errorDetail).isNull();
ServerCall<Void, Void> serverCall = mock(ServerCall.class);
Attributes attributes = Attributes.newBuilder().set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, new InetSocketAddress("10.10.10.0", 1)).set(Grpc.TRANSPORT_ATTR_LOCAL_ADDR, new InetSocketAddress("10.10.10.0", 9090)).build();
when(serverCall.getAttributes()).thenReturn(attributes);
when(serverCall.getMethodDescriptor()).thenReturn(method().build());
GrpcAuthorizationEngine engine = new GrpcAuthorizationEngine(((RbacConfig) result.config).authConfig());
AuthDecision decision = engine.evaluate(new Metadata(), serverCall);
assertThat(decision.decision()).isEqualTo(GrpcAuthorizationEngine.Action.DENY);
}
Aggregations