Search in sources :

Example 66 with GatewayServices

use of org.apache.knox.gateway.services.GatewayServices in project knox by apache.

the class TopologiesResource method uploadSimpleDescriptor.

@PUT
@Consumes({ APPLICATION_JSON, TEXT_PLAIN })
@Path(SINGLE_DESCRIPTOR_API_PATH)
public Response uploadSimpleDescriptor(@PathParam("name") String name, @Context HttpHeaders headers, String content) {
    Response response = null;
    GatewayServices gs = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
    TopologyService ts = gs.getService(GatewayServices.TOPOLOGY_SERVICE);
    File existing = getExistingConfigFile(ts.getDescriptors(), name);
    boolean isUpdate = (existing != null);
    // If it's an update, then use the matching existing filename; otherwise, use the media type to determine the file
    // extension.
    String filename = isUpdate ? existing.getName() : getFileNameForResource(name, headers);
    if (ts.deployDescriptor(filename, content)) {
        try {
            if (isUpdate) {
                response = Response.noContent().build();
            } else {
                response = created(new URI(buildHref(request))).build();
            }
        } catch (URISyntaxException e) {
            log.invalidResourceURI(e.getInput(), e.getReason(), e);
            response = status(Response.Status.BAD_REQUEST).entity("{ \"error\" : \"Failed to deploy descriptor " + name + "\" }").build();
        }
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) GatewayServices(org.apache.knox.gateway.services.GatewayServices) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI) TopologyService(org.apache.knox.gateway.services.topology.TopologyService) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 67 with GatewayServices

use of org.apache.knox.gateway.services.GatewayServices in project knox by apache.

the class VersionResource method getServerVersion.

/**
 * @return
 */
private ServerVersion getServerVersion() {
    GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
    ServerInfoService sis = services.getService(GatewayServices.SERVER_INFO_SERVICE);
    return new ServerVersion(sis.getBuildVersion(), sis.getBuildHash());
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) ServerInfoService(org.apache.knox.gateway.services.ServerInfoService)

Example 68 with GatewayServices

use of org.apache.knox.gateway.services.GatewayServices in project knox by apache.

the class KnoxLdapContextFactory method setSystemPassword.

@Override
public void setSystemPassword(String systemPass) {
    if (systemPass == null) {
        return;
    }
    systemPass = systemPass.trim();
    if (systemPass.length() == 0) {
        return;
    }
    if (!systemPass.startsWith("S{ALIAS=")) {
        super.setSystemPassword(systemPass);
        return;
    }
    systemPass = systemPass.substring("S{ALIAS=".length(), systemPass.length() - 1);
    String aliasName = systemPass;
    GatewayServices services = GatewayServer.getGatewayServices();
    AliasService aliasService = (AliasService) services.getService(GatewayServices.ALIAS_SERVICE);
    String clusterName = getClusterName();
    // System.err.println("FACTORY systempass 30: " + systemPass);
    // System.err.println("FACTORY clustername 40: " + clusterName);
    // System.err.println("FACTORY SystemProperty GatewayHome 50: " + System.getProperty(GatewayConfig.GATEWAY_HOME_VAR));
    char[] password = null;
    try {
        password = aliasService.getPasswordFromAliasForCluster(clusterName, systemPass);
    } catch (AliasServiceException e) {
        LOG.unableToGetPassword(e);
    }
    // System.err.println("FACTORY password: " + ((password == null) ? "NULL" : new String(password)));
    if (password != null) {
        // System.err.println("FACTORY SUCCESS 20 system password :" + new String(password));
        super.setSystemPassword(new String(password));
    } else {
        // System.err.println("FACTORY FORCING system password to blank");
        super.setSystemPassword("");
        LOG.aliasValueNotFound(clusterName, aliasName);
    }
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) AliasServiceException(org.apache.knox.gateway.services.security.AliasServiceException)

Example 69 with GatewayServices

use of org.apache.knox.gateway.services.GatewayServices in project knox by apache.

the class ShiroDeploymentContributorTest method testDeployment.

@Test
public void testDeployment() throws IOException {
    WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test-archive");
    Map<String, String> providerParams = new HashMap<>();
    Provider provider = new Provider();
    provider.setEnabled(true);
    provider.setName("shiro");
    provider.setParams(providerParams);
    Topology topology = new Topology();
    topology.setName("Sample");
    DeploymentContext context = EasyMock.createNiceMock(DeploymentContext.class);
    EasyMock.expect(context.getWebArchive()).andReturn(webArchive).anyTimes();
    EasyMock.expect(context.getWebAppDescriptor()).andReturn(Descriptors.create(WebAppDescriptor.class)).anyTimes();
    EasyMock.expect(context.getTopology()).andReturn(topology).anyTimes();
    EasyMock.replay(context);
    AliasService as = EasyMock.createNiceMock(AliasService.class);
    CryptoService cryptoService = new DefaultCryptoService();
    ((DefaultCryptoService) cryptoService).setAliasService(as);
    GatewayServices gatewayServices = EasyMock.createNiceMock(GatewayServices.class);
    EasyMock.expect(gatewayServices.getService(GatewayServices.CRYPTO_SERVICE)).andReturn(cryptoService).anyTimes();
    ShiroDeploymentContributor contributor = new ShiroDeploymentContributor();
    assertThat(contributor.getRole(), is("authentication"));
    assertThat(contributor.getName(), is("ShiroProvider"));
    // Just make sure it doesn't blow up.
    contributor.initializeContribution(context);
    contributor.contributeProvider(context, provider);
    // Just make sure it doesn't blow up.
    contributor.finalizeContribution(context);
    assertThat(context.getWebAppDescriptor().getOrCreateSessionConfig().getOrCreateCookieConfig().isHttpOnly(), is(true));
    assertThat(context.getWebAppDescriptor().getOrCreateSessionConfig().getOrCreateCookieConfig().isSecure(), is(true));
}
Also used : DeploymentContext(org.apache.knox.gateway.deploy.DeploymentContext) GatewayServices(org.apache.knox.gateway.services.GatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) HashMap(java.util.HashMap) DefaultCryptoService(org.apache.knox.gateway.services.security.impl.DefaultCryptoService) CryptoService(org.apache.knox.gateway.services.security.CryptoService) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) Topology(org.apache.knox.gateway.topology.Topology) DefaultCryptoService(org.apache.knox.gateway.services.security.impl.DefaultCryptoService) Provider(org.apache.knox.gateway.topology.Provider) Test(org.junit.Test)

Example 70 with GatewayServices

use of org.apache.knox.gateway.services.GatewayServices in project knox by apache.

the class HaServletContextListener method setupHaProvider.

private void setupHaProvider(HaDescriptor descriptor, ServletContext servletContext) {
    GatewayServices services = (GatewayServices) servletContext.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
    String clusterName = (String) servletContext.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE);
    ServiceRegistry serviceRegistry = services.getService(GatewayServices.SERVICE_REGISTRY_SERVICE);
    HaProvider provider = new DefaultHaProvider(descriptor);
    List<String> serviceNames = descriptor.getEnabledServiceNames();
    for (String serviceName : serviceNames) {
        provider.addHaService(serviceName, serviceRegistry.lookupServiceURLs(clusterName, serviceName));
    }
    servletContext.setAttribute(PROVIDER_ATTRIBUTE_NAME, provider);
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) DefaultHaProvider(org.apache.knox.gateway.ha.provider.impl.DefaultHaProvider) ServiceRegistry(org.apache.knox.gateway.services.registry.ServiceRegistry) DefaultHaProvider(org.apache.knox.gateway.ha.provider.impl.DefaultHaProvider)

Aggregations

GatewayServices (org.apache.knox.gateway.services.GatewayServices)75 Test (org.junit.Test)37 HttpServletRequest (javax.servlet.http.HttpServletRequest)24 ServletContext (javax.servlet.ServletContext)22 Principal (java.security.Principal)21 JWTokenAuthority (org.apache.knox.gateway.services.security.token.JWTokenAuthority)21 AliasService (org.apache.knox.gateway.services.security.AliasService)20 HttpServletResponse (javax.servlet.http.HttpServletResponse)19 JWT (org.apache.knox.gateway.services.security.token.impl.JWT)18 Response (javax.ws.rs.core.Response)17 JWTToken (org.apache.knox.gateway.services.security.token.impl.JWTToken)17 TopologyService (org.apache.knox.gateway.services.topology.TopologyService)17 HashMap (java.util.HashMap)14 Path (javax.ws.rs.Path)12 File (java.io.File)11 PrintWriter (java.io.PrintWriter)11 StringWriter (java.io.StringWriter)11 UrlRewriteEnvironment (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment)11 PrimaryPrincipal (org.apache.knox.gateway.security.PrimaryPrincipal)11 TokenResource (org.apache.knox.gateway.service.knoxtoken.TokenResource)11