How to use Interface HasPermissions class of org.openqa.selenium.safari package

Best Selenium code snippet using org.openqa.selenium.safari.Interface HasPermissions

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1// Licensed to the Software Freedom Conservancy (SFC) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The SFC licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18package org.openqa.selenium.safari;
19
20import com.google.auto.service.AutoService;
21import com.google.common.collect.ImmutableMap;
22import org.openqa.selenium.Capabilities;
23import org.openqa.selenium.remote.AdditionalHttpCommands;
24import org.openqa.selenium.remote.AugmenterProvider;
25import org.openqa.selenium.remote.CommandInfo;
26import org.openqa.selenium.remote.ExecuteMethod;
27import org.openqa.selenium.remote.http.HttpMethod;
28
29import java.util.Map;
30import java.util.function.Predicate;
31
32@AutoService({AdditionalHttpCommands.class, AugmenterProvider.class})
33public class AddHasPermissions implements AugmenterProvider<HasPermissions>, AdditionalHttpCommands {
34
35  public static final String GET_PERMISSIONS = "getPermissions";
36  public static final String SET_PERMISSIONS = "setPermissions";
37
38  private static final Map<String, CommandInfo> COMMANDS = ImmutableMap.of(
39    GET_PERMISSIONS, new CommandInfo("/session/:sessionId/apple/permissions",HttpMethod.GET),
40    SET_PERMISSIONS, new CommandInfo("/session/:sessionId/apple/permissions", HttpMethod.POST));
41
42  @Override
43  public Map<String, CommandInfo> getAdditionalCommands() {
44    return COMMANDS;
45  }
46
47  @Override
48  public Predicate<Capabilities> isApplicable() {
49    return caps -> "Safari".equals(caps.getBrowserName());
50  }
51
52  @Override
53  public Class<HasPermissions> getDescribedInterface() {
54    return HasPermissions.class;
55  }
56
57  @Override
58  public HasPermissions getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
59    return new HasPermissions() {
60      @Override
61      public void setPermissions(String permission, boolean value) {
62        executeMethod.execute(SET_PERMISSIONS, ImmutableMap.of("permissions", ImmutableMap.of(permission, value)));
63      }
64
65      @Override
66      public Map<String, Boolean> getPermissions() {
67        Map<String, Object> results = (Map<String, Object>) executeMethod.execute(GET_PERMISSIONS, null);
68        return (Map<String, Boolean>) results.get("permissions");
69      }
70    };
71  }
72}
73
Full Screen
copy
1// Licensed to the Software Freedom Conservancy (SFC) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The SFC licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18package org.openqa.selenium.safari;
19
20import org.openqa.selenium.Beta;
21
22import java.util.Map;
23
24/**
25 * Used by classes to indicate that they can take adjust permissions.
26 */
27@Beta
28public interface HasPermissions {
29
30  /**
31   * Set permission on the browser.
32   * The only supported permission at this time is "getUserMedia".
33   *
34   * @param permission the name of the item to set permission on.
35   * @param value whether the permission has been granted.
36   */
37  void setPermissions(String permission, boolean value);
38
39  /**
40   *
41   * @return each permission and whether it is allowed or not.
42   */
43  Map<String, Boolean> getPermissions();
44}
45
Full Screen
copy
1import org.springframework.beans.factory.annotation.Autowired;
2import org.springframework.context.annotation.Configuration;
3import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
4import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
5import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
6
7@Configuration
8public class MethodSecurityConfiguration extends GlobalMethodSecurityConfiguration {
9
10    @Autowired
11    private CustomPermissionEvaluator permissionEvaluator;
12
13    @Override
14    protected MethodSecurityExpressionHandler createExpressionHandler() {
15        DefaultMethodSecurityExpressionHandler expressionHandler =
16                new DefaultMethodSecurityExpressionHandler();
17        expressionHandler.setPermissionEvaluator(permissionEvaluator);
18        return expressionHandler;
19    }
20}
21
Full Screen
copy
1import org.springframework.beans.factory.annotation.Autowired;
2import org.springframework.context.annotation.Configuration;
3import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
4import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
5import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
6
7@Configuration
8public class MethodSecurityConfiguration extends GlobalMethodSecurityConfiguration {
9
10    @Autowired
11    private CustomPermissionEvaluator permissionEvaluator;
12
13    @Override
14    protected MethodSecurityExpressionHandler createExpressionHandler() {
15        DefaultMethodSecurityExpressionHandler expressionHandler =
16                new DefaultMethodSecurityExpressionHandler();
17        expressionHandler.setPermissionEvaluator(permissionEvaluator);
18        return expressionHandler;
19    }
20}
21
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)