forked from community/device-mgt-core
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
commit
1e32d5f89f
@ -1,173 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.scope.mgt;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.wso2.carbon.apimgt.api.model.Scope;
|
|
||||||
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementService;
|
|
||||||
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAO;
|
|
||||||
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAOException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAOFactory;
|
|
||||||
|
|
||||||
import java.lang.annotation.Inherited;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is an implementation of a Scope Management Service.
|
|
||||||
*/
|
|
||||||
public class ScopeManagementServiceImpl implements ScopeManagementService {
|
|
||||||
|
|
||||||
private ScopeManagementDAO scopeManagementDAO;
|
|
||||||
|
|
||||||
public ScopeManagementServiceImpl() {
|
|
||||||
this.scopeManagementDAO = ScopeManagementDAOFactory.getScopeManagementDAO();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateScopes(List<Scope> scopes) throws ScopeManagementException {
|
|
||||||
try {
|
|
||||||
ScopeManagementDAOFactory.beginTransaction();
|
|
||||||
scopeManagementDAO.updateScopes(scopes);
|
|
||||||
ScopeManagementDAOFactory.commitTransaction();
|
|
||||||
} catch (TransactionManagementException e) {
|
|
||||||
ScopeManagementDAOFactory.rollbackTransaction();
|
|
||||||
throw new ScopeManagementException("Transactional error occurred while adding the scopes.", e);
|
|
||||||
} catch (ScopeManagementDAOException e) {
|
|
||||||
ScopeManagementDAOFactory.rollbackTransaction();
|
|
||||||
throw new ScopeManagementException("Error occurred while adding the scopes to database.", e);
|
|
||||||
} finally {
|
|
||||||
ScopeManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateScopes(List<String> scopeKeys, String roleName) throws ScopeManagementException {
|
|
||||||
List<Scope> scopes = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
List<Scope> allScopes = this.getAllScopes();
|
|
||||||
for (Scope scope : allScopes) {
|
|
||||||
for (String key : scopeKeys) {
|
|
||||||
if (scope.getKey().equals(key)) {
|
|
||||||
scope.setRoles(scope.getRoles() + "," + roleName);
|
|
||||||
scopes.add(scope);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ScopeManagementDAOFactory.beginTransaction();
|
|
||||||
scopeManagementDAO.updateScopes(scopes);
|
|
||||||
ScopeManagementDAOFactory.commitTransaction();
|
|
||||||
} catch (TransactionManagementException e) {
|
|
||||||
ScopeManagementDAOFactory.rollbackTransaction();
|
|
||||||
throw new ScopeManagementException("Transactional error occurred while adding the scopes.", e);
|
|
||||||
} catch (ScopeManagementDAOException e) {
|
|
||||||
ScopeManagementDAOFactory.rollbackTransaction();
|
|
||||||
throw new ScopeManagementException("Error occurred while adding the scopes to database.", e);
|
|
||||||
} finally {
|
|
||||||
ScopeManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Scope> getAllScopes() throws ScopeManagementException {
|
|
||||||
List<Scope> scopes = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
ScopeManagementDAOFactory.openConnection();
|
|
||||||
scopes = scopeManagementDAO.getAllScopes();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new ScopeManagementException("SQL error occurred while retrieving scopes from database.", e);
|
|
||||||
} catch (ScopeManagementDAOException e) {
|
|
||||||
throw new ScopeManagementException("Error occurred while retrieving scopes from database.", e);
|
|
||||||
} finally {
|
|
||||||
ScopeManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
return scopes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRolesOfScope(String scopeKey) throws ScopeManagementException {
|
|
||||||
String roles;
|
|
||||||
if (scopeKey == null || scopeKey.isEmpty()) {
|
|
||||||
throw new ScopeManagementException("Scope key is null or empty");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ScopeManagementDAOFactory.openConnection();
|
|
||||||
roles = scopeManagementDAO.getRolesOfScope(scopeKey);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new ScopeManagementException("SQL error occurred while retrieving roles of scope from database.", e);
|
|
||||||
} catch (ScopeManagementDAOException e) {
|
|
||||||
throw new ScopeManagementException("Error occurred while retrieving roles of scope from database.", e);
|
|
||||||
} finally {
|
|
||||||
ScopeManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
return roles;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Scope> getScopesOfRole(String roleName) throws ScopeManagementException {
|
|
||||||
if (roleName == null || roleName.isEmpty()) {
|
|
||||||
throw new ScopeManagementException("Role name is null or empty");
|
|
||||||
}
|
|
||||||
List<Scope> filteredScopes = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
ScopeManagementDAOFactory.openConnection();
|
|
||||||
List<Scope> allScopes = scopeManagementDAO.getScopesHavingRole(roleName);
|
|
||||||
|
|
||||||
String roles[];
|
|
||||||
for (Scope scope : allScopes) {
|
|
||||||
roles = scope.getRoles().split(",");
|
|
||||||
for (String role : roles) {
|
|
||||||
if (roleName.equals(role.trim())) {
|
|
||||||
filteredScopes.add(scope);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new ScopeManagementException("SQL error occurred while retrieving scopes of role from database.", e);
|
|
||||||
} catch (ScopeManagementDAOException e) {
|
|
||||||
throw new ScopeManagementException("Error occurred while retrieving scopes of role from database.", e);
|
|
||||||
} finally {
|
|
||||||
ScopeManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
return filteredScopes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeScopes(String roleName) throws ScopeManagementException {
|
|
||||||
|
|
||||||
List<Scope> scopes = this.getScopesOfRole(roleName);
|
|
||||||
String roles[];
|
|
||||||
ArrayList<String> filteredRoles = new ArrayList<>();
|
|
||||||
for (Scope scope : scopes) {
|
|
||||||
roles = scope.getRoles().split(",");
|
|
||||||
for (String role : roles) {
|
|
||||||
if (!roleName.equals(role.trim())) {
|
|
||||||
filteredRoles.add(role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
scope.setRoles(StringUtils.join(filteredRoles, ","));
|
|
||||||
filteredRoles.clear();
|
|
||||||
}
|
|
||||||
this.updateScopes(scopes);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.scope.mgt.dao;
|
|
||||||
|
|
||||||
import org.wso2.carbon.apimgt.api.model.Scope;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This interface contains the basic database operations related to scope management.
|
|
||||||
*/
|
|
||||||
public interface ScopeManagementDAO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is used to update the list of scopes.
|
|
||||||
*
|
|
||||||
* @param scopes List of scopes to be updated.
|
|
||||||
* @throws ScopeManagementDAOException
|
|
||||||
*/
|
|
||||||
void updateScopes(List<Scope> scopes) throws ScopeManagementDAOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is used to retrieve all the scopes.
|
|
||||||
*
|
|
||||||
* @return List of scopes.
|
|
||||||
* @throws ScopeManagementDAOException
|
|
||||||
*/
|
|
||||||
List<Scope> getAllScopes() throws ScopeManagementDAOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is to retrieve the roles of the given scope
|
|
||||||
* @param scopeKey key of the scope
|
|
||||||
* @return List of roles
|
|
||||||
* @throws ScopeManagementDAOException
|
|
||||||
*/
|
|
||||||
String getRolesOfScope(String scopeKey) throws ScopeManagementDAOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is to retrieve all the scopes of the given role name.
|
|
||||||
* Thus it returns the scopes even if the part of the given name is matched.
|
|
||||||
*
|
|
||||||
* @param roleName Role name
|
|
||||||
* @return List of scopes
|
|
||||||
* @throws ScopeManagementDAOException
|
|
||||||
*/
|
|
||||||
List<Scope> getScopesHavingRole(String roleName) throws ScopeManagementDAOException;
|
|
||||||
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.scope.mgt.dao;
|
|
||||||
|
|
||||||
public class ScopeManagementDAOException extends Exception {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -315127931137771199L;
|
|
||||||
|
|
||||||
private String errorMessage;
|
|
||||||
|
|
||||||
public String getErrorMessage() {
|
|
||||||
return errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorMessage(String errorMessage) {
|
|
||||||
this.errorMessage = errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ScopeManagementDAOException(String msg, Exception nestedEx) {
|
|
||||||
super(msg, nestedEx);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ScopeManagementDAOException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
setErrorMessage(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ScopeManagementDAOException(String msg) {
|
|
||||||
super(msg);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ScopeManagementDAOException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ScopeManagementDAOException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,139 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.scope.mgt.dao;
|
|
||||||
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
|
||||||
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.impl.ScopeManagementDAOImpl;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class ScopeManagementDAOFactory {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(ScopeManagementDAOFactory.class);
|
|
||||||
private static DataSource dataSource;
|
|
||||||
private static String databaseEngine;
|
|
||||||
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
|
||||||
|
|
||||||
public static ScopeManagementDAO getScopeManagementDAO() {
|
|
||||||
return new ScopeManagementDAOImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void init(String dataSourceName) {
|
|
||||||
dataSource = resolveDataSource(dataSourceName);
|
|
||||||
try {
|
|
||||||
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error("Error occurred while retrieving config.datasource connection", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void beginTransaction() throws TransactionManagementException {
|
|
||||||
try {
|
|
||||||
Connection conn = dataSource.getConnection();
|
|
||||||
conn.setAutoCommit(false);
|
|
||||||
currentConnection.set(conn);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new TransactionManagementException(
|
|
||||||
"Error occurred while retrieving config.datasource connection", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openConnection() throws SQLException {
|
|
||||||
currentConnection.set(dataSource.getConnection());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Connection getConnection() throws SQLException {
|
|
||||||
if (currentConnection.get() == null) {
|
|
||||||
throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
|
|
||||||
"This might have ideally caused by not properly initiating the transaction via " +
|
|
||||||
"'beginTransaction'/'openConnection' methods");
|
|
||||||
}
|
|
||||||
return currentConnection.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void closeConnection() {
|
|
||||||
Connection con = currentConnection.get();
|
|
||||||
if (con != null) {
|
|
||||||
try {
|
|
||||||
con.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error("Error occurred while close the connection");
|
|
||||||
}
|
|
||||||
currentConnection.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void commitTransaction() {
|
|
||||||
try {
|
|
||||||
Connection conn = currentConnection.get();
|
|
||||||
if (conn != null) {
|
|
||||||
conn.commit();
|
|
||||||
} else {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Datasource connection associated with the current thread is null, hence commit " +
|
|
||||||
"has not been attempted");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error("Error occurred while committing the transaction", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void rollbackTransaction() {
|
|
||||||
try {
|
|
||||||
Connection conn = currentConnection.get();
|
|
||||||
if (conn != null) {
|
|
||||||
conn.rollback();
|
|
||||||
} else {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Datasource connection associated with the current thread is null, hence rollback " +
|
|
||||||
"has not been attempted");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error("Error occurred while roll-backing the transaction", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolve data source from the data source name.
|
|
||||||
*
|
|
||||||
* @param dataSourceName data source name
|
|
||||||
* @return data source resolved from the data source definition
|
|
||||||
*/
|
|
||||||
private static DataSource resolveDataSource(String dataSourceName) {
|
|
||||||
DataSource dataSource;
|
|
||||||
if (dataSourceName == null || dataSourceName.isEmpty()) {
|
|
||||||
throw new RuntimeException("Scope Management Repository data source configuration is null and " +
|
|
||||||
"thus, is not initialized");
|
|
||||||
}
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Initializing Scope Management Repository data source using the JNDI Lookup Definition");
|
|
||||||
}
|
|
||||||
dataSource = DeviceManagementDAOUtil.lookupDataSource(dataSourceName, null);
|
|
||||||
return dataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.core.scope.mgt.dao;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
|
|
||||||
public class ScopeManagementDAOUtil {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(ScopeManagementDAOUtil.class);
|
|
||||||
|
|
||||||
public static void cleanupResources(Statement stmt, ResultSet rs) {
|
|
||||||
if (rs != null) {
|
|
||||||
try {
|
|
||||||
rs.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.warn("Error occurred while closing the result set", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (stmt != null) {
|
|
||||||
try {
|
|
||||||
stmt.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.warn("Error occurred while closing the statement", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static void cleanupResources(Statement stmt) {
|
|
||||||
if (stmt != null) {
|
|
||||||
try {
|
|
||||||
stmt.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.warn("Error occurred while closing the statement", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,148 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.scope.mgt.dao.impl;
|
|
||||||
|
|
||||||
import org.wso2.carbon.apimgt.api.model.Scope;
|
|
||||||
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAO;
|
|
||||||
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAOException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAOFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAOUtil;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ScopeManagementDAOImpl implements ScopeManagementDAO {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateScopes(List<Scope> scopes) throws ScopeManagementDAOException {
|
|
||||||
Connection conn;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String sql = "UPDATE IDN_OAUTH2_SCOPE SET ROLES=? WHERE SCOPE_KEY=?";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
|
|
||||||
// creating a batch request
|
|
||||||
for (Scope scope : scopes) {
|
|
||||||
stmt.setString(1, scope.getRoles());
|
|
||||||
stmt.setString(2, scope.getKey());
|
|
||||||
stmt.addBatch();
|
|
||||||
}
|
|
||||||
stmt.executeBatch();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new ScopeManagementDAOException("Error occurred while updating the details of the scopes.", e);
|
|
||||||
} finally {
|
|
||||||
ScopeManagementDAOUtil.cleanupResources(stmt, rs);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public List<Scope> getAllScopes() throws ScopeManagementDAOException {
|
|
||||||
Connection conn;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
List<Scope> scopes;
|
|
||||||
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String sql = "SELECT * FROM IDN_OAUTH2_SCOPE";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
rs = stmt.executeQuery();
|
|
||||||
scopes = this.getScopesFromResultSet(rs);
|
|
||||||
return scopes;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new ScopeManagementDAOException("Error occurred while fetching the details of the scopes.", e);
|
|
||||||
} finally {
|
|
||||||
ScopeManagementDAOUtil.cleanupResources(stmt, rs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRolesOfScope(String scopeKey) throws ScopeManagementDAOException {
|
|
||||||
Connection conn;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
String roles = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String sql = "SELECT ROLES FROM IDN_OAUTH2_SCOPE WHERE SCOPE_KEY = ?";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setString(1, scopeKey);
|
|
||||||
rs = stmt.executeQuery();
|
|
||||||
|
|
||||||
if (rs.next()) {
|
|
||||||
roles = rs.getString("ROLES");
|
|
||||||
}
|
|
||||||
return roles;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new ScopeManagementDAOException("Error occurred while fetching the details of the scopes.", e);
|
|
||||||
} finally {
|
|
||||||
ScopeManagementDAOUtil.cleanupResources(stmt, rs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Scope> getScopesHavingRole(String roleName) throws ScopeManagementDAOException {
|
|
||||||
Connection conn;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
List<Scope> scopes;
|
|
||||||
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String sql = "SELECT * FROM IDN_OAUTH2_SCOPE WHERE ROLES LIKE ?";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setString(1, "%" + roleName + "%");
|
|
||||||
rs = stmt.executeQuery();
|
|
||||||
scopes = this.getScopesFromResultSet(rs);
|
|
||||||
return scopes;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new ScopeManagementDAOException("Error occurred while fetching the details of the scopes.", e);
|
|
||||||
} finally {
|
|
||||||
ScopeManagementDAOUtil.cleanupResources(stmt, rs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Connection getConnection() throws SQLException {
|
|
||||||
return ScopeManagementDAOFactory.getConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Scope> getScopesFromResultSet(ResultSet rs) throws SQLException {
|
|
||||||
List<Scope> scopes = new ArrayList<>();
|
|
||||||
Scope scope;
|
|
||||||
while (rs.next()) {
|
|
||||||
scope = new Scope();
|
|
||||||
scope.setKey(rs.getString("SCOPE_KEY"));
|
|
||||||
scope.setName(rs.getString("NAME"));
|
|
||||||
scope.setDescription(rs.getString("DESCRIPTION"));
|
|
||||||
scope.setRoles(rs.getString("ROLES"));
|
|
||||||
scopes.add(scope);
|
|
||||||
}
|
|
||||||
return scopes;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,203 +1,515 @@
|
|||||||
{{!
|
{{unit "mdm.unit.lib.leaflet"}}
|
||||||
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
{{unit "cdmf.unit.lib.qrcode"}}
|
||||||
|
{{unit "mdm.unit.device.qr-modal"}}
|
||||||
WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
Version 2.0 (the "License"); you may not use this file except
|
|
||||||
in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing,
|
|
||||||
software distributed under the License is distributed on an
|
|
||||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
KIND, either express or implied. See the License for the
|
|
||||||
specific language governing permissions and limitations
|
|
||||||
under the License.
|
|
||||||
}}
|
|
||||||
|
|
||||||
{{#zone "content"}}
|
{{#zone "content"}}
|
||||||
<h1 class="page-sub-title device-id device-select" data-deviceid="{{device.deviceIdentifier}}" data-type="{{device.type}}">
|
{{#if deviceFound}}
|
||||||
Device {{device.name}}
|
{{#if isAuthorized}}
|
||||||
{{#if device.viewModel.model}}
|
<h1 class="page-sub-title device-id device-select"
|
||||||
<span class="lbl-device">
|
data-deviceid="{{deviceView.deviceIdentifier}}" data-type="{{deviceView.deviceType}}"
|
||||||
( {{device.viewModel.vendor}} {{device.viewModel.model}} )
|
data-ownership="{{deviceView.ownership}}">
|
||||||
</span>
|
Device {{deviceView.name}}
|
||||||
{{/if}}
|
{{#if deviceView.model}}
|
||||||
</h1>
|
<span class="lbl-device">
|
||||||
<div class="row no-gutter add-padding-5x add-margin-top-5x" style="border: 1px solid #e4e4e4;">
|
( {{deviceView.vendor}} {{deviceView.model}} )
|
||||||
<div class="media">
|
</span>
|
||||||
<div id="device_overview">
|
{{/if}}
|
||||||
<div class="media-left media-middle asset-image col-xs-2 col-sm-2 col-md-2 col-lg-2">
|
</h1>
|
||||||
<div class="thumbnail icon">
|
<div class="row no-gutter add-padding-5x add-margin-top-5x" style="border: 1px solid #e4e4e4;">
|
||||||
{{#defineZone "device-thumbnail"}}
|
<div class="media">
|
||||||
<i class="square-element text fw fw-mobile"></i>
|
<div class="media-left media-middle asset-image col-xs-2 col-sm-2 col-md-2 col-lg-2">
|
||||||
{{/defineZone}}
|
<div class="thumbnail icon"><i class="square-element text fw fw-mobile"></i></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="media-body asset-desc add-padding-left-5x">
|
||||||
<div class="media-body asset-desc add-padding-left-5x">
|
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">Device
|
||||||
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">
|
Overview
|
||||||
Device Overview - {{label}}</div>
|
</div>
|
||||||
{{unit "cdmf.unit.device.overview-section" device=device}}
|
{{#defineZone "device-detail-properties"}}
|
||||||
{{#defineZone "operation-status"}}{{/defineZone}}
|
<table class="table table-responsive table-striped" id="members">
|
||||||
{{#defineZone "device-opetations"}}
|
<tbody>
|
||||||
|
{{#if deviceView.deviceIdentifier}}
|
||||||
|
<tr role="row" class="odd">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Device ID</td>
|
||||||
|
<td style="padding:10px 15px;">{{deviceView.deviceIdentifier}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.name}}
|
||||||
|
<tr role="row" class="even">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Name</td>
|
||||||
|
<td style="padding:10px 15px;">{{deviceView.name}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.vendor}}
|
||||||
|
{{#if deviceView.model}}
|
||||||
|
<tr role="row" class="odd">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Model</td>
|
||||||
|
<td style="padding:10px 15px;">{{deviceView.vendor}} {{deviceView.model}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.status}}
|
||||||
|
<tr role="row" class="even">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Status</td>
|
||||||
|
<td style="padding:10px 15px;">
|
||||||
|
{{#equal deviceView.status "ACTIVE"}}<span><i
|
||||||
|
class="fw fw-ok icon-success"></i>Active</span>{{/equal}}
|
||||||
|
{{#equal deviceView.status "INACTIVE"}}<span><i
|
||||||
|
class="fw fw-warning icon-warning"></i>Inactive</span>{{/equal}}
|
||||||
|
{{#equal deviceView.status "BLOCKED"}}<span><i
|
||||||
|
class="fw fw-remove icon-danger"></i>Blocked</span>{{/equal}}
|
||||||
|
{{#equal deviceView.status "REMOVED"}}<span><i
|
||||||
|
class="fw fw-delete icon-danger"></i>Removed</span>{{/equal}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.owner}}
|
||||||
|
<tr role="row" class="odd">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Owner</td>
|
||||||
|
<td style="padding:10px 15px;">{{deviceView.owner}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.ownership}}
|
||||||
|
<tr role="row" class="even">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Ownership</td>
|
||||||
|
<td style="padding:10px 15px;">{{deviceView.ownership}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.imei}}
|
||||||
|
<tr role="row" class="even">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px; width: 15%;">IMEI</td>
|
||||||
|
<td style="padding:10px 15px;">{{deviceView.imei}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.udid}}
|
||||||
|
<tr role="row" class="odd">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px; width: 15%;">UDID</td>
|
||||||
|
<td style="padding:10px 15px;">{{deviceView.udid}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.osBuildDate}}
|
||||||
|
<tr role="row" class="even">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Firmware Build
|
||||||
|
Date
|
||||||
|
</td>
|
||||||
|
<td style="padding:10px 15px;">{{deviceView.osBuildDate}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.phoneNumber}}
|
||||||
|
<tr role="row" class="odd">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Phone Number</td>
|
||||||
|
<td style="padding:10px 15px;">{{deviceView.phoneNumber}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.lastUpdatedTime}}
|
||||||
|
<tr role="row" class="even">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Last Update</td>
|
||||||
|
<td style="padding:10px 15px;">{{deviceView.lastUpdatedTime}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{{/defineZone}}
|
||||||
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">
|
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">
|
||||||
Operations
|
Operations
|
||||||
</div>
|
</div>
|
||||||
<div class="add-margin-top-4x" style="height: 90px;">
|
<div class="add-margin-top-4x">
|
||||||
{{unit "cdmf.unit.device.operation-bar" device=device}}
|
{{unit "mdm.unit.device.operation-bar" deviceType=deviceView.deviceType ownership=deviceView.ownership}}
|
||||||
</div>
|
</div>
|
||||||
{{/defineZone}}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="media tab-responsive">
|
||||||
</div>
|
<div class="media-left col-xs-1 col-sm-1 col-md-2 col-lg-2 hidden-xs">
|
||||||
|
<ul class="list-group nav nav-pills nav-stacked" role="tablist">
|
||||||
|
{{#if deviceView.isNotWindows}}
|
||||||
|
<li role="presentation" class="list-group-item active">
|
||||||
|
<a href="#device_details_tab" role="tab" data-toggle="tab"
|
||||||
|
aria-controls="device_details_tab">
|
||||||
|
<i class="icon fw fw-mobile"></i><span class="hidden-sm">Device Details</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.isNotWindows}}
|
||||||
|
<li role="presentation" class="list-group-item">
|
||||||
|
{{else}}
|
||||||
|
<li role="presentation" class="list-group-item active">
|
||||||
|
{{/if}}
|
||||||
|
<li role="presentation" class="list-group-item">
|
||||||
|
<a href="#policy_compliance_tab" role="tab" data-toggle="tab"
|
||||||
|
aria-controls="policy_compliance_tab">
|
||||||
|
<i class="icon fw fw-policy"></i><span class="hidden-sm">Policy Compliance</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{#if deviceView.isNotWindows}}
|
||||||
|
<li role="presentation" class="list-group-item">
|
||||||
|
<a href="#device_location_tab" role="tab" data-toggle="tab"
|
||||||
|
data-lat="{{deviceView.location.latitude}}"
|
||||||
|
data-long="{{deviceView.location.longitude}}"
|
||||||
|
aria-controls="device_location_tab">
|
||||||
|
<i class="icon fw fw-map-location"></i><span
|
||||||
|
class="hidden-sm">Device Location</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li role="presentation" class="list-group-item">
|
||||||
|
<a href="#installed_applications_tab" role="tab" data-toggle="tab"
|
||||||
|
aria-controls="installed_applications_tab">
|
||||||
|
<i class="icon fw fw-application"></i><span class="hidden-sm">Installed Applications</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.isNotRemoved}}
|
||||||
|
|
||||||
{{#defineZone "device-detail-properties"}}
|
<li role="presentation" class="list-group-item">
|
||||||
<div class="media">
|
<a href="#event_log_tab" role="tab" data-toggle="tab"
|
||||||
<div class="media-left col-xs-12 col-sm-2 col-md-2 col-lg-2">
|
aria-controls="event_log_tab">
|
||||||
<ul class="list-group" role="tablist">
|
<i class="icon fw fw-text"></i><span class="hidden-sm">Operations Log</span>
|
||||||
<li class="active"><a class="list-group-item"
|
</a>
|
||||||
href="#device_details"
|
</li>
|
||||||
role="tab" data-toggle="tab"
|
|
||||||
aria-controls="device_details">Device
|
|
||||||
Details</a>
|
|
||||||
</li>
|
|
||||||
<li><a class="list-group-item" href="#policies"
|
|
||||||
role="tab"
|
|
||||||
data-toggle="tab" aria-controls="policies">Policies</a>
|
|
||||||
</li>
|
|
||||||
<li><a class="list-group-item" href="#policy_compliance"
|
|
||||||
role="tab"
|
|
||||||
data-toggle="tab" aria-controls="policy_compliance">Policy
|
|
||||||
Compliance</a>
|
|
||||||
</li>
|
|
||||||
<li><a class="list-group-item" href="#device_location"
|
|
||||||
role="tab"
|
|
||||||
data-toggle="tab" aria-controls="device_location">Device
|
|
||||||
Location</a>
|
|
||||||
</li>
|
|
||||||
<li><a class="list-group-item" href="#event_log" role="tab"
|
|
||||||
data-toggle="tab" aria-controls="event_log">Operations
|
|
||||||
Log</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div class="media-body add-padding-left-5x remove-padding-xs tab-content">
|
|
||||||
<div class="panel-group tab-content">
|
|
||||||
|
|
||||||
<div class="panel panel-default tab-pane active"
|
{{/if}}
|
||||||
id="device_details" role="tabpanel"
|
</ul>
|
||||||
aria-labelledby="device_details">
|
|
||||||
{{unit "cdmf.unit.device.details" device=device}}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="panel panel-default tab-pane" id="policies" role="tabpanel"
|
{{#defineZone "device-detail-properties"}}
|
||||||
aria-labelledby="policies">
|
<div class="media-body add-padding-left-5x remove-padding-xs">
|
||||||
<div class="panel-heading">Policies</div>
|
<div class="panel-group tab-content remove-padding" id="tabs" data-status="{{deviceView.isNotRemoved}}"role="tablist"
|
||||||
<div class="panel-body">
|
aria-multiselectable="true">
|
||||||
<div id="policy-spinner" class="wr-advance-operations-init hidden">
|
<div class="arrow-left hidden-xs"></div>
|
||||||
<br>
|
|
||||||
|
{{#if deviceView.isNotWindows}}
|
||||||
<i class="fw fw-settings fw-spin fw-2x"></i>
|
<div class="panel panel-default" role="tabpanel" id="device_details_tab">
|
||||||
|
<div class="panel-heading visible-xs collapsed" id="device_details">
|
||||||
Loading Policies . . .
|
<h4 class="panel-title">
|
||||||
<br>
|
<a role="button" data-toggle="collapse" data-parent="#tabs"
|
||||||
<br>
|
href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
|
||||||
</div>
|
<i class="fw fw-mobile fw-2x"></i>
|
||||||
<div id="policy-list-container">
|
Device Details
|
||||||
<div class="panel-body">
|
<i class="caret-updown fw fw-down"></i>
|
||||||
No policies found
|
</a>
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<div class="panel-heading display-none-xs">Device Details</div>
|
||||||
|
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel"
|
||||||
|
aria-labelledby="device_details">
|
||||||
|
<div class="panel-body ">
|
||||||
|
<div class="device-detail-body">
|
||||||
|
<!-- device summary -->
|
||||||
|
{{#equal deviceView.deviceType "windows"}}
|
||||||
|
<div class="message message-info">
|
||||||
|
<h4 class="remove-margin"><i class="icon fw fw-info"></i>Not
|
||||||
|
available yet</h4>
|
||||||
|
</div>
|
||||||
|
{{/equal}}
|
||||||
|
{{#if deviceView.deviceInfoAvailable}}
|
||||||
|
{{#if deviceView.BatteryLevel}}
|
||||||
|
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="wr-stats-board-tile">
|
||||||
|
<div class="tile-name">BATTERY</div>
|
||||||
|
<div>
|
||||||
|
<div class="tile-icon"><i
|
||||||
|
class="fw fw-battery"></i></div>
|
||||||
|
<div class="tile-stats">
|
||||||
|
{{deviceView.BatteryLevel.value}} %
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
<!--{{#if deviceView.cpuUsage}}-->
|
||||||
|
<!--<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">-->
|
||||||
|
<!--<div class="col-md-12">-->
|
||||||
|
<!--<div class="wr-stats-board-tile">-->
|
||||||
|
<!--<div class="tile-name">CPU Usage</div>-->
|
||||||
|
<!--<div>-->
|
||||||
|
<!--<div class="tile-icon"><i class="fw fw-dashboard"></i></div>-->
|
||||||
|
<!--<div class="tile-stats">-->
|
||||||
|
<!--{{deviceView.cpuUsage.value}} %-->
|
||||||
|
<!--</div>-->
|
||||||
|
<!--</div>-->
|
||||||
|
<!--</div>-->
|
||||||
|
<!--</div>-->
|
||||||
|
<!--</div>-->
|
||||||
|
<!--{{/if}}-->
|
||||||
|
{{#if deviceView.ramUsage}}
|
||||||
|
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="wr-stats-board-tile">
|
||||||
|
<div class="tile-name">RAM Usage</div>
|
||||||
|
<div>
|
||||||
|
<div class="tile-icon"><i
|
||||||
|
class="fw fw-hardware"></i></div>
|
||||||
|
<div class="tile-stats">
|
||||||
|
{{deviceView.ramUsage.value}} %
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.internalMemory}}
|
||||||
|
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="wr-stats-board-tile">
|
||||||
|
<div class="tile-name">Local Storage</div>
|
||||||
|
<div>
|
||||||
|
<div class="tile-icon"><i
|
||||||
|
class="fw fw-hdd"></i>
|
||||||
|
</div>
|
||||||
|
<div class="tile-stats">
|
||||||
|
{{deviceView.internalMemory.usage}} %
|
||||||
|
<span class="tile-stats-free">
|
||||||
|
TOTAL OF {{deviceView.internalMemory.total}} GB
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
{{#if deviceView.externalMemory}}
|
||||||
|
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="wr-stats-board-tile">
|
||||||
|
<div class="tile-name">External Storage</div>
|
||||||
|
<div>
|
||||||
|
<div class="tile-icon"><i
|
||||||
|
class="fw fw-usb-drive"></i></div>
|
||||||
|
<div class="tile-stats">
|
||||||
|
{{deviceView.externalMemory.usage}} %
|
||||||
|
<span class="tile-stats-free">
|
||||||
|
TOTAL OF {{deviceView.externalMemory.total}} GB
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
{{else}}
|
||||||
|
<div class="message message-info">
|
||||||
|
<h4 class="remove-margin">
|
||||||
|
<i class="icon fw fw-info"></i>
|
||||||
|
Battery, RAM and Storage related information are not
|
||||||
|
available yet.
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
<div class="panel panel-default visible-xs-block" role="tabpanel"
|
||||||
|
id="policy_compliance_tab">
|
||||||
|
<div class="panel-heading visible-xs collapsed" id="policy_compliance">
|
||||||
|
<h4 class="panel-title">
|
||||||
|
<a role="button"
|
||||||
|
data-toggle="collapse" data-parent="#tabs" href="#collapseTwo"
|
||||||
|
aria-expanded="true" aria-controls="collapseTwo">
|
||||||
|
<i class="fw fw-policy fw-2x"></i>
|
||||||
|
Policy Compliance
|
||||||
|
<i class="caret-updown fw fw-down"></i>
|
||||||
|
</a>
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<div class="panel-heading display-none-xs">
|
||||||
|
Policy Compliance
|
||||||
|
|
||||||
|
<span>
|
||||||
|
<a href="javascript:void(0);" id="refresh-policy">
|
||||||
|
<i class="fw fw-refresh"></i>
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel"
|
||||||
|
aria-labelledby="policy_compliance">
|
||||||
|
<div class="panel-body ">
|
||||||
|
<span class="visible-xs add-padding-2x text-right">
|
||||||
|
<a href="javascript:void(0);" id="refresh-policy">
|
||||||
|
<i class="fw fw-refresh"></i>
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
<div id="policy-spinner"
|
||||||
|
class="wr-advance-operations-init add-padding-bottom-2x add-padding-bottom-4x hidden">
|
||||||
|
<i class="fw fw-settings fw-spin fw-2x"></i>Loading Policy
|
||||||
|
Compliance...
|
||||||
|
</div>
|
||||||
|
<div id="policy-list-container">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br class="c-both"/>
|
<div class="panel panel-default visible-xs-block" role="tabpanel"
|
||||||
</div>
|
id="device_location_tab">
|
||||||
</div>
|
<div class="panel-heading visible-xs collapsed" id="device_location">
|
||||||
<a class="padding-left"
|
<h4 class="panel-title">
|
||||||
href="{{@app.context}}/policy/add/{{device.type}}?deviceId={{device.deviceIdentifier}}">
|
<a role="button" data-toggle="collapse" data-parent="#tabs"
|
||||||
<span class="fw-stack">
|
href="#collapseThree" aria-expanded="true" aria-controls="collapseThree">
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
<i class="fw fw-map-location fw-2x"></i>
|
||||||
<i class="fw fw-policy fw-stack-1x"></i>
|
Device Location
|
||||||
</span> Add device specific policy</a>
|
<i class="caret-updown fw fw-down"></i>
|
||||||
</div>
|
</a>
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<div class="panel-heading display-none-xs">Device Location</div>
|
||||||
|
<div id="collapseThree" class="panel-collapse collapse in" role="tabpanel"
|
||||||
|
aria-labelledby="device_location">
|
||||||
|
<div class="panel-body">
|
||||||
|
{{#if deviceView.location}}
|
||||||
|
<div id="device-location"
|
||||||
|
data-lat="{{deviceView.location.latitude}}"
|
||||||
|
data-long="{{deviceView.location.longitude}}">
|
||||||
|
</div>
|
||||||
|
{{else}}
|
||||||
|
<div id="map-error" class="message message-warning">
|
||||||
|
<h4 class="remove-margin">
|
||||||
|
<i class="icon fw fw-warning"></i>
|
||||||
|
Device location information is not available.
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<p class="add-padding-5x"></p>
|
||||||
|
<p class="add-padding-5x"></p>
|
||||||
|
<p class="add-padding-5x"></p>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="panel panel-default visible-xs-block" role="tabpanel"
|
||||||
|
id="installed_applications_tab">
|
||||||
|
<div class="panel-heading visible-xs collapsed" id="installed_applications">
|
||||||
|
<h4 class="panel-title">
|
||||||
|
<a role="button" data-toggle="collapse" data-parent="#tabs"
|
||||||
|
href="#collapseFour" aria-expanded="true" aria-controls="collapseFour">
|
||||||
|
<i class="fw fw-application fw-2x"></i>
|
||||||
|
Installed Applications
|
||||||
|
<i class="caret-updown fw fw-down"></i>
|
||||||
|
</a>
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<div class="panel-heading display-none-xs">
|
||||||
|
Installed Applications
|
||||||
|
|
||||||
<div class="panel panel-default tab-pane" id="policy_compliance"
|
<span>
|
||||||
role="tabpanel" aria-labelledby="policy_compliance">
|
<a href="javascript:void(0);" id="refresh-apps">
|
||||||
<div class="panel-heading">Policy Compliance <span><a
|
<i class="fw fw-refresh"></i>
|
||||||
href="#" id="refresh-policy"><i
|
</a>
|
||||||
class="fw fw-refresh"></i></a></span></div>
|
</span>
|
||||||
<div class="panel-body">
|
</div>
|
||||||
<div id="policy-spinner"
|
<div id="collapseFour" class="panel-collapse collapse in" role="tabpanel"
|
||||||
class="wr-advance-operations-init hidden">
|
aria-labelledby="installed_applications">
|
||||||
<br>
|
<div class="panel-body">
|
||||||
|
<span class="visible-xs add-padding-2x text-right">
|
||||||
<i class="fw fw-settings fw-spin fw-2x"></i>
|
<a href="javascript:void(0);" id="refresh-apps">
|
||||||
|
<i class="fw fw-refresh"></i>
|
||||||
Loading Policy Compliance . . .
|
</a>
|
||||||
<br>
|
</span>
|
||||||
<br>
|
<div id="apps-spinner" class="wr-advance-operations-init hidden">
|
||||||
</div>
|
<i class="fw fw-settings fw-spin fw-2x"></i> Loading Applications
|
||||||
<div id="policy-list-container">
|
List...
|
||||||
<div class="panel-body">
|
</div>
|
||||||
Not available yet
|
<div id="applications-list-container">
|
||||||
|
<div class="message message-info">
|
||||||
|
<h4>
|
||||||
|
<i class="icon fw fw-info"></i>
|
||||||
|
No applications found.
|
||||||
|
</h4>
|
||||||
|
<p>Please try refreshing in a while.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br class="c-both"/>
|
<div class="panel panel-default visible-xs-block" role="tabpanel" id="event_log_tab">
|
||||||
</div>
|
<div class="panel-heading visible-xs collapsed" id="event_log">
|
||||||
</div>
|
<h4 class="panel-title">
|
||||||
</div>
|
<a role="button" data-toggle="collapse" data-parent="#tabs"
|
||||||
<div class="panel panel-default tab-pane" id="device_location"
|
href="#collapseFive" aria-expanded="true" aria-controls="collapseFive">
|
||||||
role="tabpanel" aria-labelledby="device_location">
|
<i class="fw fw-text fw-2x"></i>
|
||||||
<div class="panel-heading">Device Location</div>
|
Operations Log
|
||||||
<div class="panel-body">
|
<i class="caret-updown fw fw-down"></i>
|
||||||
<div id="device-location"
|
</a>
|
||||||
data-lat="{{device.viewModel.location.latitude}}"
|
</h4>
|
||||||
data-long="{{device.viewModel.location.longitude}}"
|
</div>
|
||||||
style="height:450px" class="panel-body">
|
<div class="panel-heading display-none-xs">
|
||||||
</div>
|
Operations Log
|
||||||
<div id="map-error" class="panel-body">
|
|
||||||
Not available yet
|
<span>
|
||||||
</div>
|
<a href="javascript:void(0);" id="refresh-operations">
|
||||||
<br class="c-both"/>
|
<i class="fw fw-refresh"></i>
|
||||||
</div>
|
</a>
|
||||||
</div>
|
</span>
|
||||||
<div class="panel panel-default tab-pane" id="event_log"
|
</div>
|
||||||
role="tabpanel" aria-labelledby="event_log">
|
<div id="collapseFive" class="panel-collapse collapse in" role="tabpanel"
|
||||||
<div class="panel-heading">Operations Log <span><a href="#"
|
aria-labelledby="event_log">
|
||||||
id="refresh-operations"><i
|
<div class="panel-body">
|
||||||
class="fw fw-refresh"></i></a></span></div>
|
<span class="visible-xs add-padding-2x text-right">
|
||||||
<div class="panel-body">
|
<a href="javascript:void(0);" id="refresh-operations">
|
||||||
<div id="operations-spinner"
|
<i class="fw fw-refresh"></i>
|
||||||
class="wr-advance-operations-init hidden">
|
</a>
|
||||||
<br>
|
</span>
|
||||||
|
<div id="operations-spinner" class="wr-advance-operations-init hidden">
|
||||||
<i class="fw fw-settings fw-spin fw-2x"></i>
|
<i class="fw fw-settings fw-spin fw-2x"></i> Loading Operations Log...
|
||||||
|
</div>
|
||||||
Loading Operations Log . . .
|
<div id="operations-log-container">
|
||||||
<br>
|
<div class="message message-info">
|
||||||
<br>
|
<h4 class="remove-margin">
|
||||||
</div>
|
<i class="icon fw fw-info"></i>
|
||||||
<div id="operations-log-container">
|
There are no operations, performed yet on this device.
|
||||||
<div class="panel-body">
|
</h4>
|
||||||
Not available yet
|
</div>
|
||||||
|
</div>
|
||||||
|
<table class="table table-striped table-hover table-bordered display data-table"
|
||||||
|
id="operations-log-table">
|
||||||
|
<thead>
|
||||||
|
<tr class="sort-row">
|
||||||
|
<th>Operation Code</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Request created at</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br class="c-both"/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{{/defineZone}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{{else}}
|
||||||
{{/defineZone}}
|
<h1 class="page-sub-title">
|
||||||
</div>
|
Permission Denied
|
||||||
|
</h1>
|
||||||
|
<br>
|
||||||
|
You are not authorized to view specified device in the system.
|
||||||
|
{{/if}}
|
||||||
|
{{else}}
|
||||||
|
<h1 class="page-sub-title">
|
||||||
|
Device not found
|
||||||
|
</h1>
|
||||||
|
<br>
|
||||||
|
You have tried to access either a removed or non-existing device.
|
||||||
|
{{/if}}
|
||||||
{{/zone}}
|
{{/zone}}
|
||||||
{{#zone "bottomJs"}}
|
{{#zone "bottomJs"}}
|
||||||
{{js "js/device-view.js"}}
|
{{#if isAuthorized}}
|
||||||
<script id="policy-view" src="{{@unit.publicUri}}/templates/policy-compliance.hbs"
|
<!--suppress HtmlUnknownTarget -->
|
||||||
data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}"
|
<script id="policy-view" src="{{@unit.publicUri}}/templates/policy-compliance.hbs"
|
||||||
type="text/x-handlebars-template"></script>
|
data-device-id="{{deviceView.deviceIdentifier}}" data-device-type="{{deviceView.deviceType}}"
|
||||||
<script id="policy-list" src="{{@unit.publicUri}}/templates/policy-list.hbs"
|
type="text/x-handlebars-template"></script>
|
||||||
data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}"
|
<!--suppress HtmlUnknownTarget -->
|
||||||
type="text/x-handlebars-template"></script>
|
<script id="applications-list" src="{{@unit.publicUri}}/templates/applications-list.hbs"
|
||||||
<script id="applications-list" src="{{@unit.publicUri}}/templates/applications-list.hbs"
|
data-device-id="{{deviceView.deviceIdentifier}}" data-device-type="{{deviceView.deviceType}}"
|
||||||
data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}"
|
type="text/x-handlebars-template"></script>
|
||||||
type="text/x-handlebars-template"></script>
|
<!--suppress HtmlUnknownTarget -->
|
||||||
<script id="operations-log" src="{{@unit.publicUri}}/templates/operations-log.hbs"
|
<script id="operations-log" src="{{@unit.publicUri}}/templates/operations-log.hbs"
|
||||||
data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}"
|
data-device-id="{{deviceView.deviceIdentifier}}" data-device-type="{{deviceView.deviceType}}"
|
||||||
type="text/x-handlebars-template"></script>
|
type="text/x-handlebars-template"></script>
|
||||||
|
{{js "js/device-detail.js"}}
|
||||||
|
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
|
||||||
|
{{js "js/load-map.js"}}
|
||||||
|
{{/if}}
|
||||||
{{/zone}}
|
{{/zone}}
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.oauth.extensions.handlers.grant;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.oauth.extensions.OAuthExtUtils;
|
||||||
|
import org.wso2.carbon.identity.oauth2.token.OAuthTokenReqMessageContext;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class ExtendedPasswordGrantHandler extends org.wso2.carbon.apimgt.keymgt.handlers.ExtendedPasswordGrantHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validateScope(OAuthTokenReqMessageContext tokReqMsgCtx) {
|
||||||
|
return OAuthExtUtils.setScopes(tokReqMsgCtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue