svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.downloader / org.gvsig.downloader.swing / org.gvsig.downloader.swing.scribejava / src / main / java / org / gvsig / downloader / swing / scribejava / keycloak / DownloaderAuthenticationKeycloakFactory.java @ 47841
History | View | Annotate | Download (2.45 KB)
1 |
package org.gvsig.downloader.swing.scribejava.keycloak; |
---|---|
2 |
|
3 |
import com.sun.net.httpserver.HttpHandler; |
4 |
import com.sun.net.httpserver.HttpServer; |
5 |
import java.io.IOException; |
6 |
import java.net.InetSocketAddress; |
7 |
import org.gvsig.downloader.DownloaderAuthenticationFactory; |
8 |
import org.gvsig.downloader.DownloaderLocator; |
9 |
import org.gvsig.downloader.DownloaderManager; |
10 |
import org.gvsig.downloader.spi.AbstractDownloaderAuthenticationFactory; |
11 |
import org.gvsig.json.Json; |
12 |
|
13 |
/**
|
14 |
*
|
15 |
* @author jjdelcerro
|
16 |
*/
|
17 |
public class DownloaderAuthenticationKeycloakFactory |
18 |
extends AbstractDownloaderAuthenticationFactory
|
19 |
implements DownloaderAuthenticationFactory
|
20 |
{ |
21 |
|
22 |
public static final String AUTH_MODE_KEYCLOAK = "Keycloak"; |
23 |
|
24 |
private HttpServer httpserver;
|
25 |
|
26 |
public DownloaderAuthenticationKeycloakFactory() {
|
27 |
super(AUTH_MODE_KEYCLOAK);
|
28 |
} |
29 |
|
30 |
@Override
|
31 |
public DownloaderAuthenticationKeycloakConfig create(Object... parameters) { |
32 |
return new DownloaderAuthenticationKeycloakConfig(this, (String) parameters[0]); |
33 |
} |
34 |
|
35 |
public HttpServer getHttpServer(DownloaderAuthenticationKeycloakConfig config) throws IOException { |
36 |
if( this.httpserver == null ) { |
37 |
this.httpserver = HttpServer.create(new InetSocketAddress(config.getLocalPort()), 0); |
38 |
this.httpserver.setExecutor(null); // creates a default executor |
39 |
this.httpserver.start();
|
40 |
} |
41 |
return this.httpserver; |
42 |
} |
43 |
|
44 |
public void stopHttpServer(int delay) { |
45 |
if( this.httpserver!=null ) { |
46 |
this.httpserver.stop(0); |
47 |
} |
48 |
} |
49 |
|
50 |
public void addCallback(DownloaderAuthenticationKeycloakConfig config, String contextPath, HttpHandler handler ) throws IOException { |
51 |
this.getHttpServer(config).createContext(contextPath, handler);
|
52 |
} |
53 |
|
54 |
public void removeCallback(DownloaderAuthenticationKeycloakConfig config, String contextPath) throws IOException { |
55 |
this.getHttpServer(config).removeContext(contextPath);
|
56 |
} |
57 |
|
58 |
public static void selfRegister() { |
59 |
DownloaderAuthenticationKeycloakConfig.selfRegister(); |
60 |
|
61 |
DownloaderManager manager = DownloaderLocator.getDownloaderManager(); |
62 |
manager.registerAuthenticationType(new DownloaderAuthenticationKeycloakFactory());
|
63 |
} |
64 |
|
65 |
@Override
|
66 |
public String toString() { |
67 |
return AUTH_MODE_KEYCLOAK;
|
68 |
} |
69 |
|
70 |
@Override
|
71 |
public String getDescription() { |
72 |
return "Authentication using keycloak (OpenId Connect)"; |
73 |
} |
74 |
|
75 |
} |