forked from community/device-mgt-core
commit
83b31f0d02
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 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.application.mgt.store.api.services.impl.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
|
||||
import org.wso2.carbon.device.application.mgt.store.api.util.Constants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RequestValidationUtil {
|
||||
|
||||
private static final Log log = LogFactory.getLog(RequestValidationUtil.class);
|
||||
|
||||
/**
|
||||
* Checks if user requested status codes are valid.
|
||||
*
|
||||
* @param statusList status codes upon to filter operation logs using status
|
||||
*/
|
||||
public static void validateStatus(List<String> statusList) throws BadRequestException {
|
||||
for (String status : statusList) {
|
||||
switch (status) {
|
||||
case "ACTIVE":
|
||||
case "INACTIVE":
|
||||
case "UNCLAIMED":
|
||||
case "UNREACHABLE":
|
||||
case "SUSPENDED":
|
||||
case "DISENROLLMENT_REQUESTED":
|
||||
case "REMOVED":
|
||||
case "BLOCKED":
|
||||
case "CREATED":
|
||||
break;
|
||||
default:
|
||||
String msg = "Invalid enrollment status type: " + status + ". \nValid status types " +
|
||||
"are ACTIVE | INACTIVE | UNCLAIMED | UNREACHABLE | SUSPENDED | " +
|
||||
"DISENROLLMENT_REQUESTED | REMOVED | BLOCKED | CREATED";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if user requested action is valid.
|
||||
*
|
||||
* @param action action upon to filter devices using action
|
||||
*/
|
||||
public static void validateAction(String action) throws BadRequestException {
|
||||
if (action.equals("SUBSCRIBED") || action.equals("UNSUBSCRIBED")) {
|
||||
} else {
|
||||
String msg = "Invalid action type received.Valid action types are SUBSCRIBED | UNSUBSCRIBED";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if user requested ownerships are valid.
|
||||
*
|
||||
* @param ownership ownerships upon to filter devices using ownership
|
||||
*/
|
||||
public static void validateOwnershipType(String ownership) throws BadRequestException {
|
||||
switch (ownership) {
|
||||
case "BYOD":
|
||||
case "COPE":
|
||||
case "WORK_PROFILE":
|
||||
case "GOOGLE_ENTERPRISE":
|
||||
case "COSU":
|
||||
case "FULLY_MANAGED":
|
||||
case "DEDICATED_DEVICE":
|
||||
break;
|
||||
default:
|
||||
String msg = "Invalid ownership type received.Valid ownership types are BYOD | COPE | WORK_PROFILE |" +
|
||||
"GOOGLE_ENTERPRISE | COSU | FULLY_MANAGED | DEDICATED_DEVICE";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if user requested Action status codes are valid.
|
||||
*
|
||||
* @param status status codes upon to filter operation logs using status
|
||||
*/
|
||||
public static void validateStatusFiltering(String status) throws BadRequestException {
|
||||
if (Constants.OperationStatus.COMPLETED.toUpperCase().equals(status)
|
||||
|| Constants.OperationStatus.ERROR.toUpperCase().equals(status)
|
||||
|| Constants.OperationStatus.NOTNOW.toUpperCase().equals(status)
|
||||
|| Constants.OperationStatus.REPEATED.toUpperCase().equals(status)
|
||||
|| Constants.OperationStatus.PENDING.toUpperCase().equals(status)
|
||||
|| Constants.OperationStatus.IN_PROGRESS.toUpperCase().equals(status)) {
|
||||
} else {
|
||||
String msg = "Invalid status type: " + status + ". \nValid status types are COMPLETED | ERROR | " +
|
||||
"IN_PROGRESS | NOTNOW | PENDING | REPEATED";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (pvt) Ltd. 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.application.mgt.store.api.util;
|
||||
|
||||
/**
|
||||
* Holds the constants used by DeviceImpl Management Admin web application.
|
||||
*/
|
||||
public class Constants {
|
||||
|
||||
public static final String USER_CLAIM_EMAIL_ADDRESS = "http://wso2.org/claims/emailaddress";
|
||||
public static final String USER_CLAIM_FIRST_NAME = "http://wso2.org/claims/givenname";
|
||||
public static final String USER_CLAIM_LAST_NAME = "http://wso2.org/claims/lastname";
|
||||
public static final String USER_CLAIM_CREATED = "http://wso2.org/claims/created";
|
||||
public static final String USER_CLAIM_MODIFIED = "http://wso2.org/claims/modified";
|
||||
public static final String USER_CLAIM_DEVICES = "http://wso2.org/claims/devices";
|
||||
public static final String PRIMARY_USER_STORE = "PRIMARY";
|
||||
public static final String DEFAULT_STREAM_VERSION = "1.0.0";
|
||||
public static final String SCOPE = "scope";
|
||||
public static final String JDBC_USERSTOREMANAGER = "org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager";
|
||||
public static final String DEFAULT_SIMPLE_DATE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
|
||||
public static final int DEFAULT_PAGE_LIMIT = 50;
|
||||
public static final String FORWARD_SLASH = "/";
|
||||
public static final String ANDROID = "android";
|
||||
public static final String ANDROID_POLICY_VALIDATOR = "io.entgra.proprietary.platform.android." +
|
||||
"core.polcy.AndroidPolicyPayloadValidator";
|
||||
public static final String IOS = "ios";
|
||||
public static final String WINDOWS = "windows";
|
||||
|
||||
|
||||
public final class OperationStatus {
|
||||
private OperationStatus () { throw new AssertionError(); }
|
||||
public static final String COMPLETED = "completed";
|
||||
public static final String ERROR = "error";
|
||||
public static final String IN_PROGRESS = "in_progress";
|
||||
public static final String PENDING = "pending";
|
||||
public static final String NOTNOW = "notnow";
|
||||
public static final String REPEATED = "repeated";
|
||||
}
|
||||
public static final String DEVICES = "devices";
|
||||
public static final String ATTRIBUTE_DISPLAY_NAME = "DisplayName";
|
||||
public static final String ATTRIBUTE_DESCRIPTION = "Description";
|
||||
public static final String EXTERNAL_DEVICE_CLAIM_DISPLAY_NAME = "Devices";
|
||||
public static final String EXTERNAL_DEVICE_CLAIM_DESCRIPTION = "Device list";
|
||||
|
||||
public final class ErrorMessages {
|
||||
private ErrorMessages () { throw new AssertionError(); }
|
||||
|
||||
public static final String STATUS_BAD_REQUEST_MESSAGE_DEFAULT = "Bad Request";
|
||||
|
||||
}
|
||||
|
||||
public final class DeviceConstants {
|
||||
private DeviceConstants () { throw new AssertionError(); }
|
||||
|
||||
public static final String APPLICATION_JSON = "application/json";
|
||||
public static final String HEADER_CONTENT_TYPE = "Content-Type";
|
||||
}
|
||||
|
||||
public final class Permission {
|
||||
private Permission() { throw new AssertionError(); }
|
||||
|
||||
public static final String ADMIN = "/permission/admin";
|
||||
public static final String LOGIN = "/permission/admin/login";
|
||||
public static final String DEVICE_MGT = "/permission/admin/device-mgt";
|
||||
public static final String APP_MGT = "/permission/admin/app-mgt";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.ui.request.interceptor;
|
||||
|
||||
import io.entgra.ui.request.interceptor.beans.AuthData;
|
||||
import io.entgra.ui.request.interceptor.beans.ProxyResponse;
|
||||
import io.entgra.ui.request.interceptor.util.HandlerConstants;
|
||||
import io.entgra.ui.request.interceptor.util.HandlerUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.MultipartConfig;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
|
||||
@MultipartConfig
|
||||
@WebServlet("/login-user/scopes")
|
||||
public class PermissionScopeHandler extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
HttpSession httpSession = req.getSession(false);
|
||||
if (httpSession == null) {
|
||||
HandlerUtil.sendUnAuthorizeResponse(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
AuthData authData = (AuthData) httpSession.getAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY);
|
||||
if (authData == null) {
|
||||
HandlerUtil.sendUnAuthorizeResponse(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(authData.getScope())) {
|
||||
ProxyResponse proxyResponse = new ProxyResponse();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put(HandlerConstants.USER_SCOPES, authData.getScope());
|
||||
proxyResponse.setCode(HttpStatus.SC_OK);
|
||||
proxyResponse.setData(jsonObject.toString());
|
||||
HandlerUtil.handleSuccess(resp, proxyResponse);
|
||||
}
|
||||
HandlerUtil.handleError(resp, null);
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.ui.request.interceptor.cache;
|
||||
|
||||
import io.entgra.ui.request.interceptor.util.HandlerConstants;
|
||||
|
||||
import javax.cache.Cache;
|
||||
import javax.cache.CacheManager;
|
||||
import javax.cache.Caching;
|
||||
|
||||
/**
|
||||
* Contains necessary functions to manage oAuth app cache during login handling
|
||||
*/
|
||||
public class LoginCacheManager {
|
||||
|
||||
private CacheManager cacheManager = null;
|
||||
private Cache<OAuthAppCacheKey, OAuthApp> cache = null;
|
||||
|
||||
/**
|
||||
* Initialize the cache manager if it is not already initialized
|
||||
*/
|
||||
public void initializeCacheManager() {
|
||||
cacheManager = Caching.getCacheManagerFactory().getCacheManager(HandlerConstants.LOGIN_CACHE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists OAuth app cache if it is not already persisted
|
||||
*
|
||||
* @param oAuthAppCacheKey - The identifier key of the cache
|
||||
* @param oAuthApp - The value of the cache which contains OAuth app data
|
||||
*/
|
||||
public void addOAuthAppToCache(OAuthAppCacheKey oAuthAppCacheKey, OAuthApp oAuthApp) {
|
||||
cache = cacheManager.getCache(HandlerConstants.LOGIN_CACHE);
|
||||
cache.put(oAuthAppCacheKey, oAuthApp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the OAuth app cache
|
||||
*
|
||||
* @param oAuthAppCacheKey - The key to identify the cache
|
||||
* @return - Returns OAuthApp object
|
||||
*/
|
||||
public OAuthApp getOAuthAppCache(OAuthAppCacheKey oAuthAppCacheKey) {
|
||||
cache = cacheManager.getCache(HandlerConstants.LOGIN_CACHE);
|
||||
return cache.get(oAuthAppCacheKey);
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.ui.request.interceptor.cache;
|
||||
|
||||
/**
|
||||
* The data object used for Login Cache
|
||||
*/
|
||||
public class OAuthApp {
|
||||
|
||||
private String appName;
|
||||
private String appOwner;
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
private String encodedClientApp;
|
||||
|
||||
public OAuthApp(String appName, String appOwner, String clientId, String clientSecret, String encodedClientApp) {
|
||||
this.appName = appName;
|
||||
this.appOwner = appOwner;
|
||||
this.clientId = clientId;
|
||||
this.clientSecret = clientSecret;
|
||||
this.encodedClientApp = encodedClientApp;
|
||||
}
|
||||
|
||||
public String getAppName() {
|
||||
return appName;
|
||||
}
|
||||
|
||||
public void setAppName(String appName) {
|
||||
this.appName = appName;
|
||||
}
|
||||
|
||||
public String getAppOwner() {
|
||||
return appOwner;
|
||||
}
|
||||
|
||||
public void setAppOwner(String appOwner) {
|
||||
this.appOwner = appOwner;
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getClientSecret() {
|
||||
return clientSecret;
|
||||
}
|
||||
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
public String getEncodedClientApp() {
|
||||
return encodedClientApp;
|
||||
}
|
||||
|
||||
public void setEncodedClientApp(String encodedClientApp) {
|
||||
this.encodedClientApp = encodedClientApp;
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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 io.entgra.ui.request.interceptor.cache;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The key object used for Login Cache
|
||||
*/
|
||||
public class OAuthAppCacheKey {
|
||||
|
||||
private String appName;
|
||||
private String appOwner;
|
||||
private volatile int hashCode;
|
||||
|
||||
public OAuthAppCacheKey(String appName, String appOwner) {
|
||||
this.appName = appName;
|
||||
this.appOwner = appOwner;
|
||||
}
|
||||
|
||||
public String getAppName() {
|
||||
return appName;
|
||||
}
|
||||
|
||||
public void setAppName(String appName) {
|
||||
this.appName = appName;
|
||||
}
|
||||
|
||||
public String getAppOwner() {
|
||||
return appOwner;
|
||||
}
|
||||
|
||||
public void setAppOwner(String appOwner) {
|
||||
this.appOwner = appOwner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj instanceof OAuthAppCacheKey) {
|
||||
final OAuthAppCacheKey other = (OAuthAppCacheKey) obj;
|
||||
String thisId = this.appName + "-" + this.appOwner;
|
||||
String otherId = other.appName + "-" + other.appOwner;
|
||||
return thisId.equals(otherId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (hashCode == 0) {
|
||||
hashCode = Objects.hash(appName, appOwner);
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
}
|
0
features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/remote-appmanager-config.xml.j2 → features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/etc/remote-appmanager-config.xml.j2
0
features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/remote-appmanager-config.xml.j2 → features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/etc/remote-appmanager-config.xml.j2
0
features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/conf_templates/templates/repository/conf/email-sender-config.xml.j2 → features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/conf_templates/templates/repository/conf/etc/email-sender-config.xml.j2
0
features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/conf_templates/templates/repository/conf/email-sender-config.xml.j2 → features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/conf_templates/templates/repository/conf/etc/email-sender-config.xml.j2
0
features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf_templates/templates/repository/conf/webapp-authenticator-config.xml.j2 → features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf_templates/templates/repository/conf/etc/webapp-authenticator-config.xml.j2
0
features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf_templates/templates/repository/conf/webapp-authenticator-config.xml.j2 → features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf_templates/templates/repository/conf/etc/webapp-authenticator-config.xml.j2
Loading…
Reference in new issue