Java Code Examples for javax.security.auth.message.config.AuthConfigFactory#setFactory()

The following examples show how to use javax.security.auth.message.config.AuthConfigFactory#setFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExampleApplicationTest.java    From crnk-example with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    RestAssured.port = port;

    docs = setupAsciidoc();

    client = new CrnkClient("http://localhost:" + port + "/api");
    client.addModule(docs);
    client.addModule(new PlainJsonFormatModule());
    client.findModules();

    // NPE fix
    if (AuthConfigFactory.getFactory() == null) {
        AuthConfigFactory.setFactory(new AuthConfigFactoryImpl());
    }
}
 
Example 2
Source File: BasicSpringBoot2Test.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	TestModule.clear();

	// NPE fix
	if (AuthConfigFactory.getFactory() == null) {
		AuthConfigFactory.setFactory(new AuthConfigFactoryImpl());
	}
}
 
Example 3
Source File: BasicSpringBoot1Test.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	TestModule.clear();

	// NPE fix
	if (AuthConfigFactory.getFactory() == null) {
		AuthConfigFactory.setFactory(new AuthConfigFactoryImpl());
	}
}
 
Example 4
Source File: SpringBootSimpleExampleApplicationTests.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    // NPE fix
    if (AuthConfigFactory.getFactory() == null) {
        AuthConfigFactory.setFactory(new AuthConfigFactoryImpl());
    }
}
 
Example 5
Source File: ServingLayer.java    From oryx with Apache License 2.0 4 votes vote down vote up
private void makeContext(Tomcat tomcat, Path noSuchBaseDir) throws IOException {
  Path contextPath = noSuchBaseDir.resolve("context");
  Files.createDirectories(contextPath);

  context = tomcat.addContext(contextPathURIBase, contextPath.toAbsolutePath().toString());

  context.setWebappVersion("3.1");
  context.setName("Oryx");

  context.addWelcomeFile("index.html");
  addErrorPages(context);

  // OryxApplication only needs one config value, so just pass it
  context.addParameter(OryxApplication.class.getName() + ".packages", appResourcesPackages);
  // ModelManagerListener will need whole config
  String serializedConfig = ConfigUtils.serialize(config);
  context.addParameter(ConfigUtils.class.getName() + ".serialized", serializedConfig);

  Wrapper wrapper =
      Tomcat.addServlet(context, "Jersey", "org.glassfish.jersey.servlet.ServletContainer");
  wrapper.addInitParameter("javax.ws.rs.Application", OryxApplication.class.getName());
  //wrapper.addInitParameter(OryxApplication.class.getName() + ".packages", appResourcesPackage);
  wrapper.addMapping("/*");
  wrapper.setLoadOnStartup(1);
  wrapper.setMultipartConfigElement(new MultipartConfigElement(""));

  if (!doNotInitTopics) { // Only for tests
    context.addApplicationListener(ModelManagerListener.class.getName());
  }

  // Better way to configure JASPIC?
  AuthConfigFactory.setFactory(new AuthConfigFactoryImpl());

  boolean needHTTPS = keystoreFile != null;
  boolean needAuthentication = userName != null;

  if (needHTTPS || needAuthentication) {

    SecurityCollection securityCollection = new SecurityCollection();
    securityCollection.addPattern("/*");
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.addCollection(securityCollection);

    if (needHTTPS) {
      securityConstraint.setUserConstraint("CONFIDENTIAL");
    }

    if (needAuthentication) {

      LoginConfig loginConfig = new LoginConfig();
      loginConfig.setAuthMethod("DIGEST");
      loginConfig.setRealmName(InMemoryRealm.NAME);
      context.setLoginConfig(loginConfig);

      securityConstraint.addAuthRole(InMemoryRealm.AUTH_ROLE);

      context.addSecurityRole(InMemoryRealm.AUTH_ROLE);
      DigestAuthenticator authenticator = new DigestAuthenticator();
      authenticator.setNonceValidity(10 * 1000L); // Shorten from 5 minutes to 10 seconds
      authenticator.setNonceCacheSize(20000); // Increase from 1000 to 20000
      context.getPipeline().addValve(authenticator);
    }

    context.addConstraint(securityConstraint);
  }

  context.setCookies(false);
}