Skip to content

Commit

Permalink
Jetty
Browse files Browse the repository at this point in the history
  • Loading branch information
vharseko committed Mar 21, 2024
1 parent 16ebd57 commit a858f21
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@

package org.forgerock.openicf.framework.server.jetty;

import org.eclipse.jetty.websocket.common.SessionListener;
import org.eclipse.jetty.websocket.common.WebSocketSessionFactory;
import org.eclipse.jetty.websocket.common.events.EventDriver;
import org.eclipse.jetty.websocket.common.events.JettyAnnotatedEventDriver;
import org.eclipse.jetty.websocket.common.events.JettyListenerEventDriver;
import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;

public class OpenICFWebSocketSessionFactory extends WebSocketSessionFactory {
public OpenICFWebSocketSessionFactory(WebSocketContainerScope containerScope) {
super(containerScope);
}

public OpenICFWebSocketSessionFactory(SessionListener... sessionListeners) {
/*public OpenICFWebSocketSessionFactory(SessionListener... sessionListeners) {
super(sessionListeners);
}
}*/

@Override
public boolean supports(final EventDriver websocket) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void sendPong(byte[] applicationData) throws Exception {
}

protected void tryClose() {
WebSocketListenerBridge.this.terminateConnection(StatusCode.NORMAL, "TEST003");
WebSocketListenerBridge.this.session.close(StatusCode.NORMAL, "TEST003");
}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
import java.util.concurrent.TimeUnit;

import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.MappedLoginService;
import org.eclipse.jetty.security.SecurityHandler;
import org.eclipse.jetty.security.*;
import org.eclipse.jetty.security.authentication.BasicAuthenticator;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration;
Expand All @@ -41,6 +38,7 @@
import org.eclipse.jetty.servlet.BaseHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlet.Source;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.util.security.Credential;
import org.eclipse.jetty.util.ssl.SslContextFactory;
Expand Down Expand Up @@ -114,23 +112,15 @@ private SecurityHandler getSecurityHandler() throws IOException {
sh.setAuthenticator(new BasicAuthenticator());
sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] { cm }));

MappedLoginService loginService = new MappedLoginService() {

@Override
protected UserIdentity loadUser(String username) {
return null;
}

@Override
protected void loadUsers() throws IOException {
Credential credential = Credential.getCredential(DEFAULT_PASSWORD);
String[] roles = new String[] { "websocket" };
putUser("plain", credential, roles);
putUser("secure", credential, roles);
putUser("proxy", credential, roles);
putUser("anonymous", credential, roles);
}
};
HashLoginService loginService = new HashLoginService();
UserStore us=new UserStore();
String[] roles = new String[] { "websocket" };
Credential credential = Credential.getCredential(DEFAULT_PASSWORD);
us.addUser("plain", credential, roles);
us.addUser("secure", credential, roles);
us.addUser("proxy", credential, roles);
us.addUser("anonymous", credential, roles);
loginService.setUserStore(us);
loginService.setName("OpenICF-Service");
sh.setLoginService(loginService);
sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] { cm }));
Expand Down Expand Up @@ -191,7 +181,7 @@ protected void setupTest(ITestContext context) throws Exception {
| ServletContextHandler.SECURITY);

ServletHolder holder =
handler.getServletHandler().newServletHolder(BaseHolder.Source.EMBEDDED);
handler.getServletHandler().newServletHolder(Source.EMBEDDED);

serverConnectorFramework = serverConnectorFrameworkFactory.acquire();
localConnectorFramework = localConnectorFrameworkFactory.acquire();
Expand Down

0 comments on commit a858f21

Please sign in to comment.