本文整理汇总了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());
}
示例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.");
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
};
}
示例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;
}
示例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);
}
}
示例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;
}
示例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.");
}