当前位置: 首页>>代码示例>>Java>>正文


Java SecurityConstraint类代码示例

本文整理汇总了Java中org.apache.tomcat.util.descriptor.web.SecurityConstraint的典型用法代码示例。如果您正苦于以下问题:Java SecurityConstraint类的具体用法?Java SecurityConstraint怎么用?Java SecurityConstraint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SecurityConstraint类属于org.apache.tomcat.util.descriptor.web包,在下文中一共展示了SecurityConstraint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldPassAuthToken

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
@Test
public void shouldPassAuthToken() throws Exception {
    final ArgumentCaptor<GenericPrincipal> argument = ArgumentCaptor.forClass(GenericPrincipal.class);
    final String token = "Bearer 1337";
    final SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setAuthConstraint(true);
    when(realm.findSecurityConstraints(request, request.getContext()))
            .thenReturn(new SecurityConstraint[] { securityConstraint });
    when(request.getHeader("Authorization"))
            .thenReturn(token);

    synValve.start();
    synValve.invoke(request, response);

    final InOrder inOrder = inOrder(request, nextValve);
    inOrder.verify(request).getHeader("Authorization");
    inOrder.verify(request).setUserPrincipal(argument.capture());
    inOrder.verify(request).setAuthType("SYN");
    inOrder.verify(nextValve).invoke(request, response);

    assertEquals("islandoraAdmin", argument.getValue().getName());
    final List<String> roles = Arrays.asList(argument.getValue().getRoles());
    assertEquals(1, roles.size());
    assertTrue(roles.contains("islandora"));
    assertNull(argument.getValue().getPassword());
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:27,代码来源:SynValveTest.java

示例2: shouldFailTokenMissingUid

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
@Test
public void shouldFailTokenMissingUid() throws Exception {
    final String host = "http://test.com";
    final String token = JWT
            .create()
            .withClaim("name", "adminuser")
            .withClaim("url", host)
            .withArrayClaim("roles", new String[] {"role1", "role2", "role3"})
            .withIssuedAt(Date.from(LocalDateTime.now().toInstant(offset)))
            .withExpiresAt(Date.from(LocalDateTime.now().plusHours(2).toInstant(offset)))
            .sign(Algorithm.HMAC256("secret"));

    final SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setAuthConstraint(true);
    when(realm.findSecurityConstraints(request, request.getContext()))
            .thenReturn(new SecurityConstraint[] { securityConstraint });
    when(request.getHeader("Authorization"))
            .thenReturn("Bearer " + token);

    synValve.start();
    synValve.invoke(request, response);

    verify(request).getHeader("Authorization");
    verify(response).sendError(401, "Token authentication failed.");
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:26,代码来源:SynValveTest.java

示例3: servletContainer

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };

    tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
    return tomcat;
}
 
开发者ID:sfahadahmed,项目名称:hungrydragon,代码行数:18,代码来源:TomcatConfig.java

示例4: servletContainer

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
@Bean
public EmbeddedServletContainerFactory servletContainer(SslProperties properties) {
	TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
		@Override
		protected void postProcessContext(Context context) {
			SecurityConstraint securityConstraint = new SecurityConstraint();
			securityConstraint.setUserConstraint("CONFIDENTIAL");
			SecurityCollection collection = new SecurityCollection();
			collection.addPattern("/*");
			securityConstraint.addCollection(collection);
			context.addConstraint(securityConstraint);
		}
	};
	tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
	return tomcat;
}
 
开发者ID:Saisimon,项目名称:tip,代码行数:17,代码来源:TomcatWebConfig.java

示例5: servletContainer

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
/**
 * <p>servletContainer.</p>
 *
 * @return a {@link org.springframework.boot.context.embedded.EmbeddedServletContainerFactory} object.
 */
@Bean
public EmbeddedServletContainerFactory servletContainer() {
	TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
		@Override
		protected void postProcessContext(Context context) {
			SecurityConstraint securityConstraint = new SecurityConstraint();
			securityConstraint.setUserConstraint("CONFIDENTIAL");
			SecurityCollection collection = new SecurityCollection();
			collection.addPattern("/*");
			securityConstraint.addCollection(collection);
			context.addConstraint(securityConstraint);
		}
	};

	tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
	return tomcat;
}
 
开发者ID:rajadilipkolli,项目名称:springsecuredthymeleafapp,代码行数:23,代码来源:WebConfiguration.java

示例6: servletContainer

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
    return tomcat;
}
 
开发者ID:bhits,项目名称:edge-server,代码行数:17,代码来源:WebConfig.java

示例7: servletContainer

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
@Bean
public EmbeddedServletContainerFactory servletContainer() {
  if (https) {
    TomcatEmbeddedServletContainerFactory tomcat =
        new TomcatEmbeddedServletContainerFactory() {
          @Override
          protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
          }
        };

    tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
    return tomcat;
  }
  return new TomcatEmbeddedServletContainerFactory();
}
 
开发者ID:openbaton,项目名称:NFVO,代码行数:22,代码来源:SystemConfiguration.java

示例8: shouldPassAuth

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
/**
 * @throws Exception
 */
@Test
public void shouldPassAuth() throws Exception {
	SecurityConstraint securityConstraint = new SecurityConstraint();
	securityConstraint.setAuthConstraint(true);
	when(realm.findSecurityConstraints(request, request.getContext()))
			.thenReturn(new SecurityConstraint[] { securityConstraint });
	when(request.getHeader(JwtConstants.AUTH_HEADER)).thenReturn(
			getTestToken());

	jwtValve.invoke(request, response);

	InOrder inOrder = inOrder(request, nextValve);
	inOrder.verify(request).getHeader(JwtConstants.AUTH_HEADER);
	inOrder.verify(request).setUserPrincipal(any(UserPrincipal.class));
	inOrder.verify(request).setAuthType("TOKEN");
	inOrder.verify(nextValve).invoke(request, response);
}
 
开发者ID:andreacomo,项目名称:tomcat-jwt-security,代码行数:21,代码来源:JwtTokenValveTest.java

示例9: servletContainer

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
@Bean
public EmbeddedServletContainerFactory servletContainer()
{
	TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory()
	{
		@Override
		protected void postProcessContext(Context context)
		{
			SecurityConstraint securityConstraint = new SecurityConstraint();
			securityConstraint.setUserConstraint("CONFIDENTIAL");
			SecurityCollection collection = new SecurityCollection();
			collection.addPattern("/*");
			securityConstraint.addCollection(collection);
			context.addConstraint(securityConstraint);
		}
	};

	tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
	return tomcat;
}
 
开发者ID:sivaprasadreddy,项目名称:jcart,代码行数:21,代码来源:WebConfig.java

示例10: servletContainer

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
@Bean
public EmbeddedServletContainerFactory servletContainer() {
	TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
		@Override
		protected void postProcessContext(Context context) {
			SecurityConstraint securityConstraint = new SecurityConstraint();
			securityConstraint.setUserConstraint("CONFIDENTIAL");
			SecurityCollection collection = new SecurityCollection();
			collection.addPattern("/*");
			securityConstraint.addCollection(collection);
			context.addConstraint(securityConstraint);
		}
	};

	tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
	return tomcat;
}
 
开发者ID:sivaprasadreddy,项目名称:jcart,代码行数:18,代码来源:WebConfig.java

示例11: servletContainer

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
@Bean
@Profile({ "staging", "production", "localpg" })
public EmbeddedServletContainerFactory servletContainer() {

   return new TomcatEmbeddedServletContainerFactory(){
        @Override
        protected void postProcessContext(Context context) {
            if (environment.acceptsProfiles("~staging", "~production")) {
                SecurityConstraint securityConstraint = new SecurityConstraint();
                securityConstraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                securityConstraint.addCollection(collection);
                context.addConstraint(securityConstraint);
            }
        }
    };

}
 
开发者ID:grassrootza,项目名称:grassroot-platform,代码行数:20,代码来源:GrassrootWebApplicationConfig.java

示例12: servletContainer

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
public EmbeddedServletContainerFactory servletContainer() {
	TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
		@Override
		protected void postProcessContext(Context context) {
			SecurityConstraint constraint = new SecurityConstraint();
			constraint.setUserConstraint("CONFIDENTIAL");
			SecurityCollection collection = new SecurityCollection();
			collection.addPattern("/*");
			constraint.addCollection(collection);
			context.addConstraint(constraint);
		}
	};
	tomcat.addAdditionalTomcatConnectors(httpConnector());
	return tomcat;
}
 
开发者ID:514840279,项目名称:danyuan-application,代码行数:16,代码来源:App.java

示例13: invoke

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
@Override
public void invoke(final Request request, final Response response)
        throws IOException, ServletException {

    final SecurityConstraint[] constraints = this.container.getRealm()
            .findSecurityConstraints(request, request.getContext());

    if ((constraints == null
            && !request.getContext().getPreemptiveAuthentication())
        || !hasAuthConstraint(constraints)) {
        this.getNext().invoke(request, response);
    } else {
        handleAuthentication(request, response);
    }
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:16,代码来源:SynValve.java

示例14: hasAuthConstraint

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
private boolean hasAuthConstraint(final SecurityConstraint[] constraints) {
    boolean authConstraint = true;
    for (SecurityConstraint securityConstraint : constraints) {
        authConstraint &= securityConstraint.getAuthConstraint();
    }
    return authConstraint;
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:8,代码来源:SynValve.java

示例15: shouldFailAuthBecauseOfTokenNotSet

import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入依赖的package包/类
@Test
public void shouldFailAuthBecauseOfTokenNotSet() throws Exception {
    final SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setAuthConstraint(true);
    when(realm.findSecurityConstraints(request, request.getContext()))
            .thenReturn(new SecurityConstraint[] { securityConstraint });

    synValve.start();
    synValve.invoke(request, response);

    verify(request).getHeader("Authorization");
    verify(response).sendError(401, "Token authentication failed.");
}
 
开发者ID:Islandora-CLAW,项目名称:Syn,代码行数:14,代码来源:SynValveTest.java


注:本文中的org.apache.tomcat.util.descriptor.web.SecurityConstraint类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。