Merge branch 'application-mgt-new' into 'application-mgt-new'

Get logged in users details when loading APPM Publisher UI

See merge request entgra/carbon-device-mgt!307
feature/appm-store/pbac
Dharmakeerthi Lasantha 5 years ago
commit 812c2999ba

@ -98,19 +98,25 @@ class App extends React.Component {
}; };
checkUserLoggedIn = (config) => { checkUserLoggedIn = (config) => {
axios.get( axios.post(
window.location.origin + config.serverConfig.invoker.uri + window.location.origin + "/publisher-ui-request-handler/user",
config.serverConfig.invoker.publisher + "/applications/categories" "platform=publisher"
).then(res => { ).then(res => {
this.getAndroidEnterpriseToken(config); const pageURL = window.location.pathname;
const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1);
if (lastURLSegment === "login") {
window.location.href = window.location.origin + `/publisher/`;
} else {
this.getAndroidEnterpriseToken(config);
}
}).catch((error) => { }).catch((error) => {
if (error.hasOwnProperty("response") && error.response.status === 401) { if (error.hasOwnProperty("response") && error.response.status === 401) {
const redirectUrl = encodeURI(window.location.href); const redirectUrl = encodeURI(window.location.href);
const pageURL = window.location.pathname; const pageURL = window.location.pathname;
const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1);
if(lastURLSegment!=="login"){ if (lastURLSegment !== "login") {
window.location.href = window.location.origin + `/publisher/login?redirect=${redirectUrl}`; window.location.href = window.location.origin + `/publisher/login?redirect=${redirectUrl}`;
}else{ } else {
this.getAndroidEnterpriseToken(config); this.getAndroidEnterpriseToken(config);
} }
} else { } else {

@ -59,7 +59,7 @@ class AddNewCustomApp extends React.Component {
render() { render() {
return ( return (
<div> <div>
<PageHeader style={{paddingTop:0}}> <PageHeader style={{paddingTop:0, backgroundColor: "#fff"}}>
<Breadcrumb style={{paddingBottom:16}}> <Breadcrumb style={{paddingBottom:16}}>
<Breadcrumb.Item> <Breadcrumb.Item>
<Link to="/publisher/apps"><Icon type="home"/> Home</Link> <Link to="/publisher/apps"><Icon type="home"/> Home</Link>

@ -53,7 +53,7 @@ class AddNewEnterpriseApp extends React.Component {
render() { render() {
return ( return (
<div> <div>
<PageHeader style={{paddingTop:0}}> <PageHeader style={{paddingTop:0, backgroundColor: "#fff"}}>
<Breadcrumb style={{paddingBottom:16}}> <Breadcrumb style={{paddingBottom:16}}>
<Breadcrumb.Item> <Breadcrumb.Item>
<Link to="/publisher/apps"><Icon type="home"/> Home</Link> <Link to="/publisher/apps"><Icon type="home"/> Home</Link>

@ -61,7 +61,7 @@ class AddNewEnterpriseApp extends React.Component {
render() { render() {
return ( return (
<div> <div>
<PageHeader style={{paddingTop:0}}> <PageHeader style={{paddingTop:0, backgroundColor: "#fff"}}>
<Breadcrumb style={{paddingBottom:16}}> <Breadcrumb style={{paddingBottom:16}}>
<Breadcrumb.Item> <Breadcrumb.Item>
<Link to="/publisher/apps"><Icon type="home"/> Home</Link> <Link to="/publisher/apps"><Icon type="home"/> Home</Link>

@ -57,7 +57,7 @@ class AddNewEnterpriseApp extends React.Component {
render() { render() {
return ( return (
<div> <div>
<PageHeader style={{paddingTop:0}}> <PageHeader style={{paddingTop:0, backgroundColor: "#fff"}}>
<Breadcrumb style={{paddingBottom:16}}> <Breadcrumb style={{paddingBottom:16}}>
<Breadcrumb.Item> <Breadcrumb.Item>
<Link to="/publisher/apps"><Icon type="home"/> Home</Link> <Link to="/publisher/apps"><Icon type="home"/> Home</Link>

@ -42,7 +42,7 @@ class AddNewRelease extends React.Component {
const {appId, deviceType} = this.props.match.params; const {appId, deviceType} = this.props.match.params;
return ( return (
<div> <div>
<PageHeader style={{paddingTop: 0}}> <PageHeader style={{paddingTop:0, backgroundColor: "#fff"}}>
<Breadcrumb style={{paddingBottom: 16}}> <Breadcrumb style={{paddingBottom: 16}}>
<Breadcrumb.Item> <Breadcrumb.Item>
<Link to="/publisher/apps"><Icon type="home"/> Home</Link> <Link to="/publisher/apps"><Icon type="home"/> Home</Link>

@ -36,7 +36,7 @@ class Manage extends React.Component {
render() { render() {
return ( return (
<div> <div>
<PageHeader style={{paddingTop: 0}}> <PageHeader style={{paddingTop:0, backgroundColor: "#fff"}}>
<Breadcrumb style={{paddingBottom: 16}}> <Breadcrumb style={{paddingBottom: 16}}>
<Breadcrumb.Item> <Breadcrumb.Item>
<Link to="/publisher/apps"><Icon type="home"/> Home</Link> <Link to="/publisher/apps"><Icon type="home"/> Home</Link>

@ -38,7 +38,7 @@ class ManageAndroidEnterprise extends React.Component {
render() { render() {
return ( return (
<div> <div>
<PageHeader style={{paddingTop: 0}}> <PageHeader style={{paddingTop:0, backgroundColor: "#fff"}}>
<Breadcrumb style={{paddingBottom: 16}}> <Breadcrumb style={{paddingBottom: 16}}>
<Breadcrumb.Item> <Breadcrumb.Item>
<Link to="/publisher/apps"><Icon type="home"/> Home</Link> <Link to="/publisher/apps"><Icon type="home"/> Home</Link>

@ -281,7 +281,7 @@ class Page extends React.Component {
const {pageName, loading, clusters, applications, isAddNewClusterVisible, links} = this.state; const {pageName, loading, clusters, applications, isAddNewClusterVisible, links} = this.state;
return ( return (
<div> <div>
<PageHeader style={{paddingTop: 0}}> <PageHeader style={{paddingTop:0, backgroundColor: "#fff"}}>
<Breadcrumb style={{paddingBottom: 16}}> <Breadcrumb style={{paddingBottom: 16}}>
<Breadcrumb.Item> <Breadcrumb.Item>
<Link to="/publisher/apps"><Icon type="home"/> Home</Link> <Link to="/publisher/apps"><Icon type="home"/> Home</Link>

@ -78,22 +78,28 @@ class App extends React.Component {
} }
checkUserLoggedIn = (config) => { checkUserLoggedIn = (config) => {
axios.get( axios.post(
window.location.origin + config.serverConfig.invoker.uri + window.location.origin + "/store-ui-request-handler/user",
config.serverConfig.invoker.publisher + "/applications/categories" "platform=publisher"
).then(res => { ).then(res => {
this.setState({ const pageURL = window.location.pathname;
loading: false, const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1);
config: config if (lastURLSegment === "login") {
}) window.location.href = window.location.origin + `/store/`;
} else {
this.setState({
loading: false,
config: config
});
}
}).catch((error) => { }).catch((error) => {
if (error.hasOwnProperty("response") && error.response.status === 401) { if (error.hasOwnProperty("response") && error.response.status === 401) {
const redirectUrl = encodeURI(window.location.href); const redirectUrl = encodeURI(window.location.href);
const pageURL = window.location.pathname; const pageURL = window.location.pathname;
const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1);
if(lastURLSegment!=="login"){ if (lastURLSegment !== "login") {
window.location.href = window.location.origin + `/store/login?redirect=${redirectUrl}`; window.location.href = window.location.origin + `/store/login?redirect=${redirectUrl}`;
}else{ } else {
this.setState({ this.setState({
loading: false, loading: false,
config: config config: config
@ -106,7 +112,7 @@ class App extends React.Component {
}) })
} }
}); });
} };
render() { render() {
const {loading, error} = this.state; const {loading, error} = this.state;

@ -43,32 +43,36 @@ import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import java.io.IOException; import java.io.IOException;
@MultipartConfig @WebServlet("/user") public class UserHandler extends HttpServlet { @MultipartConfig
@WebServlet("/user")
public class UserHandler extends HttpServlet {
private static final Log log = LogFactory.getLog(UserHandler.class); private static final Log log = LogFactory.getLog(UserHandler.class);
private static final long serialVersionUID = 9050048549140517002L; private static final long serialVersionUID = 9050048549140517002L;
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) { @Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
try { try {
String platform = req.getParameter(HandlerConstants.PLATFORM); String platform = req.getParameter(HandlerConstants.PLATFORM);
String serverUrl = String serverUrl =
req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + req.getServerName() + HandlerConstants.COLON req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + req.getServerName() + HandlerConstants.COLON
+ System.getProperty("iot.gateway.https.port"); + System.getProperty("iot.gateway.https.port");
if (StringUtils.isBlank(platform)) { if (StringUtils.isBlank(platform)) {
ProxyResponse proxyResponse = new ProxyResponse(); sendUnAuthorizeResponse(req, resp, serverUrl, platform);
proxyResponse.setCode(HttpStatus.SC_BAD_REQUEST);
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
return; return;
} }
HttpSession httpSession = req.getSession(false); HttpSession httpSession = req.getSession(false);
if (httpSession == null) { if (httpSession == null) {
ProxyResponse proxyResponse = new ProxyResponse(); sendUnAuthorizeResponse(req, resp, serverUrl, platform);
proxyResponse.setCode(HttpStatus.SC_UNAUTHORIZED);
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
return; return;
} }
AuthData authData = (AuthData) httpSession.getAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY); AuthData authData = (AuthData) httpSession.getAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY);
if (authData == null) {
sendUnAuthorizeResponse(req, resp, serverUrl, platform);
return;
}
String accessToken = authData.getAccessToken(); String accessToken = authData.getAccessToken();
HttpPost tokenEndpoint = new HttpPost(serverUrl + HandlerConstants.INTROSPECT_ENDPOINT); HttpPost tokenEndpoint = new HttpPost(serverUrl + HandlerConstants.INTROSPECT_ENDPOINT);
@ -94,9 +98,7 @@ import java.io.IOException;
if (jTokenResult.isJsonObject()) { if (jTokenResult.isJsonObject()) {
JsonObject jTokenResultAsJsonObject = jTokenResult.getAsJsonObject(); JsonObject jTokenResultAsJsonObject = jTokenResult.getAsJsonObject();
if (!jTokenResultAsJsonObject.get("active").getAsBoolean()) { if (!jTokenResultAsJsonObject.get("active").getAsBoolean()) {
ProxyResponse proxyResponse = new ProxyResponse(); sendUnAuthorizeResponse(req, resp, serverUrl, platform);
proxyResponse.setCode(HttpStatus.SC_UNAUTHORIZED);
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
return; return;
} }
ProxyResponse proxyResponse = new ProxyResponse(); ProxyResponse proxyResponse = new ProxyResponse();
@ -110,4 +112,18 @@ import java.io.IOException;
log.error("Error occurred while parsing the response. ", e); log.error("Error occurred while parsing the response. ", e);
} }
} }
/**
* Send UnAuthorized Response to the user
* @param req HttpServletRequest object
* @param resp HttpServletResponse object
* @param serverUrl Url of the server
* @param platform Requested platform
*/
private void sendUnAuthorizeResponse(HttpServletRequest req, HttpServletResponse resp, String serverUrl, String platform)
throws IOException {
ProxyResponse proxyResponse = new ProxyResponse();
proxyResponse.setCode(HttpStatus.SC_UNAUTHORIZED);
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
}
} }

Loading…
Cancel
Save