本文整理汇总了Java中org.eclipse.jetty.security.ConstraintMapping类的典型用法代码示例。如果您正苦于以下问题:Java ConstraintMapping类的具体用法?Java ConstraintMapping怎么用?Java ConstraintMapping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConstraintMapping类属于org.eclipse.jetty.security包,在下文中一共展示了ConstraintMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: basicAuth
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
private static final SecurityHandler basicAuth(String realm)
{
HashLoginService l = new HashLoginService();
l.setConfig(new File(PlatformData.installationDirectory, "webusers.properties").getAbsolutePath());
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { "user" });
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/ui/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.setRealmName("myrealm");
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
示例2: InMemoryIdentityManager
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
public InMemoryIdentityManager() {
loginService = new HashLoginService();
loginService.setName(realm);
securityHandler = new ConstraintSecurityHandler();
securityHandler.setAuthenticator(new BasicAuthenticator());
securityHandler.setRealmName(realm);
securityHandler.setLoginService(loginService);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
// constraint.setRoles(new String[] { "getRole", "postRole", "allRole" });
constraint.setRoles(new String[]{Constraint.ANY_AUTH, "getRole", "postRole", "allRole"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
securityHandler.addConstraintMapping(cm);
}
示例3: basicAuth
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
private static final SecurityHandler basicAuth(String realm) {
final OfMeetLoginService loginService = new OfMeetLoginService();
loginService.setName(realm);
final Constraint constraint = new Constraint();
constraint.setName( Constraint.__BASIC_AUTH );
constraint.setRoles( new String[] { "ofmeet" } );
constraint.setAuthenticate( true );
final ConstraintMapping constraintMapping = new ConstraintMapping();
constraintMapping.setConstraint( constraint );
constraintMapping.setPathSpec( "/*" );
final ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
securityHandler.setAuthenticator( new BasicAuthenticator() );
securityHandler.setRealmName( realm );
securityHandler.addConstraintMapping( constraintMapping );
securityHandler.setLoginService( loginService );
return securityHandler;
}
示例4: configureCommonAuthentication
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
protected ConstraintSecurityHandler configureCommonAuthentication(Server server,
ServerConnector connector, AvaticaServerConfiguration config, String constraintName,
String[] allowedRoles, Authenticator authenticator, String realm,
LoginService loginService) {
Constraint constraint = new Constraint();
constraint.setName(constraintName);
constraint.setRoles(allowedRoles);
// This is telling Jetty to not allow unauthenticated requests through (very important!)
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler sh = new ConstraintSecurityHandler();
sh.setAuthenticator(authenticator);
sh.setLoginService(loginService);
sh.setConstraintMappings(new ConstraintMapping[]{cm});
sh.setRealmName(realm);
return sh;
}
示例5: setServletSecurity
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
/**
* Delegate for ServletRegistration.Dynamic.setServletSecurity method
* @param registration ServletRegistration.Dynamic instance that setServletSecurity was called on
* @param servletSecurityElement new security info
* @return the set of exact URL mappings currently associated with the registration that are also present in the web.xml
* security constraints and thus will be unaffected by this call.
*/
public Set<String> setServletSecurity(ServletRegistration.Dynamic registration, ServletSecurityElement servletSecurityElement)
{
//Default implementation is to just accept them all. If using a webapp, then this behaviour is overridden in WebAppContext.setServletSecurity
Collection<String> pathSpecs = registration.getMappings();
if (pathSpecs != null)
{
for (String pathSpec:pathSpecs)
{
List<ConstraintMapping> mappings = ConstraintSecurityHandler.createConstraintsWithMappingsForPath(registration.getName(), pathSpec, servletSecurityElement);
for (ConstraintMapping m:mappings)
((ConstraintAware)getSecurityHandler()).addConstraintMapping(m);
}
}
return Collections.emptySet();
}
示例6: basicAuth
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
private static final SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService l = new HashLoginService();
l.putUser(username, Credential.getCredential(password), new String[] {"user"});
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] {"user"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new ProxyAuthenticator());
csh.setRealmName("myrealm");
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
示例7: basicAuth
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
private static final SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService l = new HashLoginService();
l.putUser(username, Credential.getCredential(password), new String[] {"user"});
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.setRealmName("myrealm");
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
示例8: basicAuth
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
private SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService l = new HashLoginService();
l.putUser(username, Credential.getCredential(password), new String[]{"user"});
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.setRealmName("myrealm");
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
示例9: basicAuth
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
private SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService l = new HashLoginService();
l.putUser(username, Credential.getCredential(password), new String[]{"user"});
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.setRealmName("myrealm");
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
示例10: getSecurityHandler
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
private SecurityHandler getSecurityHandler() throws IOException {
Constraint constraint = new Constraint(Constraint.__BASIC_AUTH, "user");
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setPathSpec("/*");
cm.setConstraint(constraint);
ConstraintSecurityHandler sh = new ConstraintSecurityHandler();
sh.setAuthenticator(new BasicAuthenticator());
sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] {cm}));
HashLoginService loginService = new HashLoginService("MyRealm", "src/test/resources/myRealm.properties");
sh.setLoginService(loginService);
sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[]{cm}));
return sh;
}
示例11: buildSecurityHandler
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
@Override
protected SecurityHandler buildSecurityHandler()
{
if( constraintServices != null )
{
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
for( ConstraintService eachConstraintService : constraintServices )
{
ConstraintMapping csMapping = eachConstraintService.buildConstraintMapping();
if( csMapping != null )
{
securityHandler.addConstraintMapping( csMapping );
}
}
if( !securityHandler.getConstraintMappings().isEmpty() )
{
return securityHandler;
}
}
return super.buildSecurityHandler();
}
示例12: createSecurityHandler
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
@Produces
@Named("securityHandler")
public static ConstraintSecurityHandler createSecurityHandler() {
Constraint constraint = new Constraint("BASIC", "customer");
constraint.setAuthenticate(true);
ConstraintMapping mapping = new ConstraintMapping();
mapping.setConstraint(constraint);
mapping.setPathSpec("/*");
ConstraintSecurityHandler handler = new ConstraintSecurityHandler();
handler.addConstraintMapping(mapping);
handler.setAuthenticator(new BasicAuthenticator());
handler.setLoginService(new HashLoginService("RiderAutoParts", "src/main/resources/users.properties"));
return handler;
}
示例13: addServlet
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
private void addServlet(final Servlet servlet, final String path,
WebPermission... permissions) {
servletContextHandler.addServlet(new ServletHolder(servlet), path);
if (permissions != null && permissions.length > 0) {
for (WebPermission p : permissions) {
Constraint constraint = getConstraintForPermission(p);
ConstraintMapping mapping = new ConstraintMapping();
mapping.setPathSpec(servletContextHandler.getContextPath()
+ path);
mapping.setConstraint(constraint);
if (p.hasMethod()) {
mapping.setMethod(p.getMethod().name());
}
constraintMappings.add(mapping);
}
}
LOGGER.info("Servlet added on path {}", path);
}
示例14: basicAuth
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
private static final SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService l = new HashLoginService();
l.putUser(username, Credential.getCredential(password), new String[] {"user"});
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.setRealmName("myrealm");
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
示例15: constrainHttpMethods
import org.eclipse.jetty.security.ConstraintMapping; //导入依赖的package包/类
/**
* Add constraints to a Jetty Context to disallow undesirable Http methods.
* @param ctxHandler The context to modify
*/
public static void constrainHttpMethods(ServletContextHandler ctxHandler) {
Constraint c = new Constraint();
c.setAuthenticate(true);
ConstraintMapping cmt = new ConstraintMapping();
cmt.setConstraint(c);
cmt.setMethod("TRACE");
cmt.setPathSpec("/*");
ConstraintMapping cmo = new ConstraintMapping();
cmo.setConstraint(c);
cmo.setMethod("OPTIONS");
cmo.setPathSpec("/*");
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
securityHandler.setConstraintMappings(new ConstraintMapping[]{ cmt, cmo });
ctxHandler.setSecurityHandler(securityHandler);
}