Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
add changes for #155
Browse files Browse the repository at this point in the history
  • Loading branch information
dz-1 committed Dec 20, 2018
1 parent 343876a commit cf2cb3a
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 12 deletions.
1 change: 1 addition & 0 deletions db/mysql/config/oauth2-service/oauth_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
---
enableAudit: false

consoleURL: http://localhost:3000
5 changes: 4 additions & 1 deletion oauth2-console/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#custom environment variables must begin with REACT_APP_
REACT_APP_API_URL=http://localhost:8080
REACT_APP_SERVICES_URL=https://localhost:6883/oauth2/service?page=1
#REACT_APP_CLIENTS_URL=https://localhost:6884/oauth2/client?page=1
#REACT_APP_USERS_URL=https://localhost:6885/oauth2/user?page=1


#built-in React.js env variables
#PORT=8080
26 changes: 23 additions & 3 deletions oauth2-console/src/js/main/views.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import React from 'react';

export const Service = () => (
<div> Hello, services. </div>
);
export class Service extends React.Component {
constructor(props){
super(props);
this.state = {
services: []
}
}

componentDidMount(){
fetch(process.env.REACT_APP_SERVICES_URL)
.then(results => results.json())
.then(data => {
let services = data.map(service => <div key="{service.serviceId}"> {service.serviceName} </div>);
this.setState({services: services});
});
}

render(){
return (
<div> {this.state.services} </div>
);
}
};

export const Client = () => (
<div> Hello, clients. </div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package com.networknt.oauth.service.handler;

import java.util.Collection;
import java.util.Deque;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hazelcast.core.IMap;
import com.hazelcast.query.PagingPredicate;
import com.hazelcast.query.impl.predicates.LikePredicate;
Expand All @@ -8,18 +15,14 @@
import com.networknt.oauth.cache.CacheStartupHookProvider;
import com.networknt.oauth.cache.model.Service;
import com.networknt.oauth.cache.model.ServiceComparator;
import io.undertow.server.HttpHandler;

import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers;
import io.undertow.util.HttpString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.Deque;

public class Oauth2ServiceGetHandler extends ServiceAuditHandler implements LightHttpHandler {
static final Logger logger = LoggerFactory.getLogger(Oauth2ServiceGetHandler.class);

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
IMap<String, Service> services = CacheStartupHookProvider.hz.getMap("services");
Expand All @@ -37,6 +40,14 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
Collection<Service> values = services.values(pagingPredicate);

exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, "application/json");

String consoleURL = oauth_config.getConsoleURL();

if (StringUtils.isNotBlank(consoleURL)) {
exchange.getResponseHeaders().add(new HttpString("Access-Control-Allow-Origin"), consoleURL);
exchange.getResponseHeaders().add(Headers.VARY, Headers.ORIGIN_STRING);
}

exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(values));
processAudit(exchange);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class OauthServiceConfig {
boolean enableAudit;
String consoleURL;

public boolean isEnableAudit() {
return enableAudit;
Expand All @@ -10,4 +11,12 @@ public boolean isEnableAudit() {
public void setEnableAudit(boolean enableAudit) {
this.enableAudit = enableAudit;
}

public String getConsoleURL() {
return consoleURL;
}

public void setConsoleURL(String consoleURL) {
this.consoleURL = consoleURL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

public class ServiceAuditHandler extends AuditInfoHandler {
static final Logger logger = LoggerFactory.getLogger(ServiceAuditHandler.class);
private final static String CONFIG = "oauth_service";
private final static OauthServiceConfig oauth_config = (OauthServiceConfig) Config.getInstance().getJsonObjectConfig(CONFIG, OauthServiceConfig.class);
static final String CONFIG = "oauth_service";
static final OauthServiceConfig oauth_config = (OauthServiceConfig) Config.getInstance().getJsonObjectConfig(CONFIG, OauthServiceConfig.class);


protected void processAudit(HttpServerExchange exchange) throws Exception{
Expand Down
1 change: 1 addition & 0 deletions service/src/main/resources/config/oauth_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
---
enableAudit: false

consoleURL: http://localhost:3000

0 comments on commit cf2cb3a

Please sign in to comment.