Search in sources :

Example 1 with LoginService

use of org.eclipse.jetty.security.LoginService in project jetty.project by eclipse.

the class JettyRunTask method execute.

/**
     * Executes this Ant task. The build flow is being stopped until Jetty
     * server stops.
     *
     * @throws BuildException if unable to build
     */
public void execute() throws BuildException {
    TaskLog.log("Configuring Jetty for project: " + getProject().getName());
    setSystemProperties();
    List<Connector> connectorsList = null;
    if (connectors != null)
        connectorsList = connectors.getConnectors();
    else
        connectorsList = new Connectors(jettyPort, 30000).getDefaultConnectors();
    List<LoginService> loginServicesList = (loginServices != null ? loginServices.getLoginServices() : new ArrayList<LoginService>());
    ServerProxyImpl server = new ServerProxyImpl();
    server.setConnectors(connectorsList);
    server.setLoginServices(loginServicesList);
    server.setRequestLog(requestLog);
    server.setJettyXml(jettyXml);
    server.setDaemon(daemon);
    server.setStopPort(stopPort);
    server.setStopKey(stopKey);
    server.setContextHandlers(contextHandlers);
    server.setTempDirectory(tempDirectory);
    server.setScanIntervalSecs(scanIntervalSeconds);
    try {
        for (WebAppContext webapp : webapps) {
            server.addWebApplication((AntWebAppContext) webapp);
        }
    } catch (Exception e) {
        throw new BuildException(e);
    }
    server.start();
}
Also used : Connectors(org.eclipse.jetty.ant.types.Connectors) Connector(org.eclipse.jetty.ant.types.Connector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ArrayList(java.util.ArrayList) BuildException(org.apache.tools.ant.BuildException) LoginService(org.eclipse.jetty.security.LoginService) BuildException(org.apache.tools.ant.BuildException)

Example 2 with LoginService

use of org.eclipse.jetty.security.LoginService in project jetty.project by eclipse.

the class ServerProxyImpl method configure.

/**
     * Configures Jetty server before adding any web applications to it.
     */
private void configure() {
    if (configured)
        return;
    configured = true;
    if (stopPort > 0 && stopKey != null) {
        ShutdownMonitor monitor = ShutdownMonitor.getInstance();
        monitor.setPort(stopPort);
        monitor.setKey(stopKey);
        monitor.setExitVm(false);
    }
    if (tempDirectory != null && !tempDirectory.exists())
        tempDirectory.mkdirs();
    // Applies external configuration via jetty.xml
    applyJettyXml();
    // Configures connectors for this server instance.
    if (connectors != null) {
        for (Connector c : connectors) {
            ServerConnector jc = new ServerConnector(server);
            jc.setPort(c.getPort());
            jc.setIdleTimeout(c.getMaxIdleTime());
            server.addConnector(jc);
        }
    }
    // Configures login services
    if (loginServices != null) {
        for (LoginService ls : loginServices) {
            server.addBean(ls);
        }
    }
    // Does not cache resources, to prevent Windows from locking files
    Resource.setDefaultUseCaches(false);
    // Set default server handlers
    configureHandlers();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.ant.types.Connector) ShutdownMonitor(org.eclipse.jetty.server.ShutdownMonitor) LoginService(org.eclipse.jetty.security.LoginService)

Example 3 with LoginService

use of org.eclipse.jetty.security.LoginService in project jetty.project by eclipse.

the class JdbcLoginServiceTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    _docRoot = MavenTestingUtils.getTargetTestingDir("loginservice-test");
    FS.ensureDirExists(_docRoot);
    File content = new File(_docRoot, "input.txt");
    try (FileOutputStream out = new FileOutputStream(content)) {
        out.write(_content.getBytes("utf-8"));
    }
    //drop any tables that might have existed
    File scriptFile = MavenTestingUtils.getTestResourceFile("droptables.sql");
    int result = DatabaseLoginServiceTestServer.runscript(scriptFile);
    //ignore result, if the tables dont already exist, derby spits out an error
    //create the tables afresh
    scriptFile = MavenTestingUtils.getTestResourceFile("createdb.sql");
    result = DatabaseLoginServiceTestServer.runscript(scriptFile);
    assertThat("runScript result", result, is(0));
    File jdbcRealmFile = MavenTestingUtils.getTestResourceFile("jdbcrealm.properties");
    LoginService loginService = new JDBCLoginService(__realm, jdbcRealmFile.getAbsolutePath());
    _testServer = new DatabaseLoginServiceTestServer();
    _testServer.setResourceBase(_docRoot.getAbsolutePath());
    _testServer.setLoginService(loginService);
    _testServer.start();
    _baseUri = _testServer.getBaseUri();
}
Also used : FileOutputStream(java.io.FileOutputStream) JDBCLoginService(org.eclipse.jetty.security.JDBCLoginService) File(java.io.File) JDBCLoginService(org.eclipse.jetty.security.JDBCLoginService) LoginService(org.eclipse.jetty.security.LoginService) BeforeClass(org.junit.BeforeClass)

Example 4 with LoginService

use of org.eclipse.jetty.security.LoginService in project jetty.project by eclipse.

the class HttpClientAuthenticationTest method start.

private void start(Authenticator authenticator, Handler handler) throws Exception {
    server = new Server();
    File realmFile = MavenTestingUtils.getTestResourceFile("realm.properties");
    LoginService loginService = new HashLoginService(realm, realmFile.getAbsolutePath());
    server.addBean(loginService);
    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    Constraint constraint = new Constraint();
    constraint.setAuthenticate(true);
    //allow any authenticated user
    constraint.setRoles(new String[] { "**" });
    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setPathSpec("/secure");
    mapping.setConstraint(constraint);
    securityHandler.addConstraintMapping(mapping);
    securityHandler.setAuthenticator(authenticator);
    securityHandler.setLoginService(loginService);
    securityHandler.setHandler(handler);
    start(securityHandler);
}
Also used : HashLoginService(org.eclipse.jetty.security.HashLoginService) ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) Server(org.eclipse.jetty.server.Server) Constraint(org.eclipse.jetty.util.security.Constraint) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) File(java.io.File) HashLoginService(org.eclipse.jetty.security.HashLoginService) LoginService(org.eclipse.jetty.security.LoginService)

Example 5 with LoginService

use of org.eclipse.jetty.security.LoginService in project jetty.project by eclipse.

the class DeferredAuthentication method authenticate.

/* ------------------------------------------------------------ */
/**
     * @see org.eclipse.jetty.server.Authentication.Deferred#authenticate(ServletRequest)
     */
@Override
public Authentication authenticate(ServletRequest request) {
    try {
        Authentication authentication = _authenticator.validateRequest(request, __deferredResponse, true);
        if (authentication != null && (authentication instanceof Authentication.User) && !(authentication instanceof Authentication.ResponseSent)) {
            LoginService login_service = _authenticator.getLoginService();
            IdentityService identity_service = login_service.getIdentityService();
            if (identity_service != null)
                _previousAssociation = identity_service.associate(((Authentication.User) authentication).getUserIdentity());
            return authentication;
        }
    } catch (ServerAuthException e) {
        LOG.debug(e);
    }
    return this;
}
Also used : IdentityService(org.eclipse.jetty.security.IdentityService) UserAuthentication(org.eclipse.jetty.security.UserAuthentication) Authentication(org.eclipse.jetty.server.Authentication) ServerAuthException(org.eclipse.jetty.security.ServerAuthException) LoginService(org.eclipse.jetty.security.LoginService)

Aggregations

LoginService (org.eclipse.jetty.security.LoginService)16 HashLoginService (org.eclipse.jetty.security.HashLoginService)5 ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)4 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)4 IdentityService (org.eclipse.jetty.security.IdentityService)4 ServerAuthException (org.eclipse.jetty.security.ServerAuthException)4 UserAuthentication (org.eclipse.jetty.security.UserAuthentication)4 Authentication (org.eclipse.jetty.server.Authentication)4 Constraint (org.eclipse.jetty.util.security.Constraint)4 File (java.io.File)3 URL (java.net.URL)2 Connector (org.eclipse.jetty.ant.types.Connector)2 SecurityHandler (org.eclipse.jetty.security.SecurityHandler)2 BasicAuthenticator (org.eclipse.jetty.security.authentication.BasicAuthenticator)2 Server (org.eclipse.jetty.server.Server)2 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 PamConstraint (org.apache.hive.http.security.PamConstraint)1 PamConstraintMapping (org.apache.hive.http.security.PamConstraintMapping)1