forked from community/device-mgt-plugins
parent
8a9ad21e74
commit
22f4a9e2af
18
components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/util/AuthenticationInfo.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/authentication/AuthenticationInfo.java
18
components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/util/AuthenticationInfo.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/authentication/AuthenticationInfo.java
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed 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.iot.output.adapter.ui.authentication;
|
||||||
|
|
||||||
|
import javax.websocket.Session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface is used to authenticate a websocket session
|
||||||
|
*/
|
||||||
|
public interface Authenticator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the client is authenticated to connect.
|
||||||
|
* @param session user object.
|
||||||
|
* @return AuthenicationInfo which contains authentication client information.
|
||||||
|
*/
|
||||||
|
AuthenticationInfo isAutenticated(Session session);
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed 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.iot.output.adapter.ui.authentication;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.iot.output.adapter.ui.authentication.oauth.OAuthTokenValdiator;
|
||||||
|
import javax.websocket.Session;
|
||||||
|
|
||||||
|
public class OAuthAuthenticator implements Authenticator {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthenticationInfo isAutenticated(Session session) {
|
||||||
|
return OAuthTokenValdiator.getInstance().validateToken(session);
|
||||||
|
}
|
||||||
|
}
|
30
components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/OAuthTokenValdiator.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/authentication/oauth/OAuthTokenValdiator.java
30
components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/OAuthTokenValdiator.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/authentication/oauth/OAuthTokenValdiator.java
16
components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/OAuthTokenValidaterStubFactory.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/authentication/oauth/OAuthTokenValidaterStubFactory.java
16
components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/OAuthTokenValidaterStubFactory.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/authentication/oauth/OAuthTokenValidaterStubFactory.java
2
components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/exception/OAuthTokenValidationException.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/authentication/oauth/exception/OAuthTokenValidationException.java
2
components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui.endpoint/src/main/java/oauth/exception/OAuthTokenValidationException.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/authentication/oauth/exception/OAuthTokenValidationException.java
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed 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.iot.output.adapter.ui.authorization;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.iot.output.adapter.ui.authentication.AuthenticationInfo;
|
||||||
|
|
||||||
|
import javax.websocket.Session;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the client is authorized to connect.
|
||||||
|
*/
|
||||||
|
public interface Authorizer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the client is authorized to connect with the stream.
|
||||||
|
* @param authenticationInfo authenticated client information.
|
||||||
|
* @param session request session of the client.
|
||||||
|
* @param stream stream name of the client connecting to.
|
||||||
|
* @return true if authorized else return false.
|
||||||
|
*/
|
||||||
|
boolean isAuthorized(AuthenticationInfo authenticationInfo, Session session, String stream);
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed 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.iot.output.adapter.ui.authorization;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.iot.output.adapter.ui.authentication.AuthenticationInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.output.adapter.ui.constants.WebsocketConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.output.adapter.ui.util.WebSocketSessionRequest;
|
||||||
|
|
||||||
|
import javax.websocket.Session;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This authorizer crossvalidates the request with device id and device type.
|
||||||
|
*/
|
||||||
|
public class DeviceAuthorizer implements Authorizer {
|
||||||
|
private static final String STATS_SCOPE_IDENTIFIER = "stats";
|
||||||
|
private static final String DEVICE_MGT_SCOPE_IDENTIFIER = "device-mgt";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAuthorized(AuthenticationInfo authenticationInfo, Session session, String stream) {
|
||||||
|
WebSocketSessionRequest webSocketSessionRequest = new WebSocketSessionRequest(session);
|
||||||
|
Map<String, String> queryParams = webSocketSessionRequest.getQueryParamValuePairs();
|
||||||
|
String deviceId = queryParams.get("deviceId");
|
||||||
|
String deviceType = queryParams.get("deviceType");
|
||||||
|
Object scopeObject = authenticationInfo.getProperties().get(WebsocketConstants.SCOPE_IDENTIFIER);
|
||||||
|
|
||||||
|
if (deviceId != null && !deviceId.isEmpty() && deviceType != null && !deviceType.isEmpty()
|
||||||
|
&& scopeObject != null) {
|
||||||
|
String scopes[] = (String[]) scopeObject;
|
||||||
|
String requiredScope = DEVICE_MGT_SCOPE_IDENTIFIER + ":" + deviceType + ":" + deviceId + ":"
|
||||||
|
+ STATS_SCOPE_IDENTIFIER;
|
||||||
|
for (String scope : scopes) {
|
||||||
|
if (requiredScope.equals(scope)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.output.adapter.ui.config;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlAttribute;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlType;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Java class for Authenticator complex type.
|
||||||
|
*
|
||||||
|
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <complexType name="Authenticator">
|
||||||
|
* <complexContent>
|
||||||
|
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||||
|
* <sequence>
|
||||||
|
* <element name="Properties" type="{}Properties"/>
|
||||||
|
* </sequence>
|
||||||
|
* <attribute name="class" type="{http://www.w3.org/2001/XMLSchema}string" />
|
||||||
|
* </restriction>
|
||||||
|
* </complexContent>
|
||||||
|
* </complexType>
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
@XmlType(name = "Authenticator", propOrder = {
|
||||||
|
"properties"
|
||||||
|
})
|
||||||
|
public class Authenticator {
|
||||||
|
|
||||||
|
@XmlElement(name = "Properties", required = true)
|
||||||
|
protected Properties properties;
|
||||||
|
@XmlAttribute(name = "class")
|
||||||
|
protected String clazz;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the properties property.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* possible object is
|
||||||
|
* {@link Properties }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public Properties getProperties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the properties property.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* allowed object is
|
||||||
|
* {@link Properties }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setProperties(Properties value) {
|
||||||
|
this.properties = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the clazz property.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* possible object is
|
||||||
|
* {@link String }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public String getClazz() {
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the clazz property.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* allowed object is
|
||||||
|
* {@link String }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setClazz(String value) {
|
||||||
|
this.clazz = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.output.adapter.ui.config;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlAttribute;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlType;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Java class for Authorizer complex type.
|
||||||
|
*
|
||||||
|
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <complexType name="Authorizer">
|
||||||
|
* <complexContent>
|
||||||
|
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||||
|
* <sequence>
|
||||||
|
* <element name="Properties" type="{}Properties"/>
|
||||||
|
* </sequence>
|
||||||
|
* <attribute name="class" type="{http://www.w3.org/2001/XMLSchema}string" />
|
||||||
|
* </restriction>
|
||||||
|
* </complexContent>
|
||||||
|
* </complexType>
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
@XmlType(name = "Authorizer", propOrder = {
|
||||||
|
"properties"
|
||||||
|
})
|
||||||
|
public class Authorizer {
|
||||||
|
|
||||||
|
@XmlElement(name = "Properties", required = true)
|
||||||
|
protected Properties properties;
|
||||||
|
@XmlAttribute(name = "class")
|
||||||
|
protected String clazz;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the properties property.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* possible object is
|
||||||
|
* {@link Properties }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public Properties getProperties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the properties property.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* allowed object is
|
||||||
|
* {@link Properties }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setProperties(Properties value) {
|
||||||
|
this.properties = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the clazz property.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* possible object is
|
||||||
|
* {@link String }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public String getClazz() {
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the clazz property.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* allowed object is
|
||||||
|
* {@link String }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setClazz(String value) {
|
||||||
|
this.clazz = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.output.adapter.ui.config;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlType;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Java class for Properties complex type.
|
||||||
|
*
|
||||||
|
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <complexType name="Properties">
|
||||||
|
* <complexContent>
|
||||||
|
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||||
|
* <sequence>
|
||||||
|
* <element name="Property" type="{}Property" maxOccurs="unbounded" minOccurs="0"/>
|
||||||
|
* </sequence>
|
||||||
|
* </restriction>
|
||||||
|
* </complexContent>
|
||||||
|
* </complexType>
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
@XmlType(name = "Properties", propOrder = {
|
||||||
|
"property"
|
||||||
|
})
|
||||||
|
public class Properties {
|
||||||
|
|
||||||
|
@XmlElement(name = "Property")
|
||||||
|
protected List<Property> property;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the property property.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* This accessor method returns a reference to the live list,
|
||||||
|
* not a snapshot. Therefore any modification you make to the
|
||||||
|
* returned list will be present inside the JAXB object.
|
||||||
|
* This is why there is not a <CODE>set</CODE> method for the property property.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* For example, to add a new item, do as follows:
|
||||||
|
* <pre>
|
||||||
|
* getProperty().add(newItem);
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Objects of the following type(s) are allowed in the list
|
||||||
|
* {@link Property }
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public List<Property> getProperty() {
|
||||||
|
if (property == null) {
|
||||||
|
property = new ArrayList<Property>();
|
||||||
|
}
|
||||||
|
return this.property;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.output.adapter.ui.config;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlAttribute;
|
||||||
|
import javax.xml.bind.annotation.XmlType;
|
||||||
|
import javax.xml.bind.annotation.XmlValue;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Java class for Property complex type.
|
||||||
|
*
|
||||||
|
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <complexType name="Property">
|
||||||
|
* <simpleContent>
|
||||||
|
* <extension base="<http://www.w3.org/2001/XMLSchema>string">
|
||||||
|
* <attribute name="name" type="{http://www.w3.org/2001/XMLSchema}string" />
|
||||||
|
* </extension>
|
||||||
|
* </simpleContent>
|
||||||
|
* </complexType>
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
@XmlType(name = "Property", propOrder = {
|
||||||
|
"value"
|
||||||
|
})
|
||||||
|
public class Property {
|
||||||
|
|
||||||
|
@XmlValue
|
||||||
|
protected String value;
|
||||||
|
@XmlAttribute(name = "name")
|
||||||
|
protected String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the value property.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* possible object is
|
||||||
|
* {@link String }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the value property.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* allowed object is
|
||||||
|
* {@link String }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the name property.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* possible object is
|
||||||
|
* {@link String }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the name property.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* allowed object is
|
||||||
|
* {@link String }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setName(String value) {
|
||||||
|
this.name = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.output.adapter.ui.config;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.output.adapter.ui.util.WebsocketUtils;
|
||||||
|
import org.wso2.carbon.utils.CarbonUtils;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBContext;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the configuration that are needed for scopes to permission map.
|
||||||
|
*/
|
||||||
|
public class WebsocketConfig {
|
||||||
|
|
||||||
|
private static WebsocketConfig config = new WebsocketConfig();
|
||||||
|
private WebsocketValidationConfigs websocketValidationConfigs;
|
||||||
|
|
||||||
|
private static final String WEBSOCKET_VALIDATION_CONFIG_PATH =
|
||||||
|
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "websocket-validation.xml";
|
||||||
|
|
||||||
|
private WebsocketConfig() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WebsocketConfig getInstance() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() throws WebsocketValidationConfigurationFailedException {
|
||||||
|
try {
|
||||||
|
File deviceMgtConfig = new File(WEBSOCKET_VALIDATION_CONFIG_PATH);
|
||||||
|
Document doc = WebsocketUtils.convertToDocument(deviceMgtConfig);
|
||||||
|
|
||||||
|
/* Un-marshaling DeviceMGtScope configuration */
|
||||||
|
JAXBContext ctx = JAXBContext.newInstance(WebsocketValidationConfigs.class);
|
||||||
|
Unmarshaller unmarshaller = ctx.createUnmarshaller();
|
||||||
|
//unmarshaller.setSchema(getSchema());
|
||||||
|
websocketValidationConfigs = (WebsocketValidationConfigs) unmarshaller.unmarshal(doc);
|
||||||
|
if (websocketValidationConfigs != null) {
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (JAXBException e) {
|
||||||
|
throw new WebsocketValidationConfigurationFailedException("Error occurred while un-marshalling Websocket" +
|
||||||
|
" Config", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebsocketValidationConfigs getWebsocketValidationConfigs() {
|
||||||
|
return websocketValidationConfigs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWebsocketValidationConfigs(WebsocketValidationConfigs websocketValidationConfigs) {
|
||||||
|
websocketValidationConfigs = websocketValidationConfigs;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.iot.output.adapter.ui.config;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlType;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Java class for WebsocketValidationConfigs complex type.
|
||||||
|
*
|
||||||
|
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <complexType name="WebsocketValidationConfigs">
|
||||||
|
* <complexContent>
|
||||||
|
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||||
|
* <sequence>
|
||||||
|
* <element name="Authenticator" type="{}Authenticator"/>
|
||||||
|
* <element name="Authorizer" type="{}Authorizer"/>
|
||||||
|
* </sequence>
|
||||||
|
* </restriction>
|
||||||
|
* </complexContent>
|
||||||
|
* </complexType>
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
@XmlType(name = "WebsocketValidationConfigs", propOrder = {
|
||||||
|
"authenticator",
|
||||||
|
"authorizer"
|
||||||
|
})
|
||||||
|
public class WebsocketValidationConfigs {
|
||||||
|
|
||||||
|
@XmlElement(name = "Authenticator", required = true)
|
||||||
|
protected Authenticator authenticator;
|
||||||
|
@XmlElement(name = "Authorizer", required = true)
|
||||||
|
protected Authorizer authorizer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the authenticator property.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* possible object is
|
||||||
|
* {@link Authenticator }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public Authenticator getAuthenticator() {
|
||||||
|
return authenticator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the authenticator property.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* allowed object is
|
||||||
|
* {@link Authenticator }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setAuthenticator(Authenticator value) {
|
||||||
|
this.authenticator = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the authorizer property.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* possible object is
|
||||||
|
* {@link Authorizer }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public Authorizer getAuthorizer() {
|
||||||
|
return authorizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the authorizer property.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* allowed object is
|
||||||
|
* {@link Authorizer }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setAuthorizer(Authorizer value) {
|
||||||
|
this.authorizer = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.iot.output.adapter.ui.config;
|
||||||
|
|
||||||
|
public class WebsocketValidationConfigurationFailedException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -3151279329290703928L;
|
||||||
|
|
||||||
|
public WebsocketValidationConfigurationFailedException(String msg, Exception nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebsocketValidationConfigurationFailedException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebsocketValidationConfigurationFailedException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebsocketValidationConfigurationFailedException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebsocketValidationConfigurationFailedException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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.iot.output.adapter.ui.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This holds the constants related to this feature
|
||||||
|
*/
|
||||||
|
public class WebsocketConstants {
|
||||||
|
|
||||||
|
private WebsocketConstants() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String SCOPE_IDENTIFIER = "scopes";
|
||||||
|
public static final String MAXIMUM_TOTAL_HTTP_CONNECTION = "maximumTotalHttpConnection";
|
||||||
|
public static final String MAXIMUM_HTTP_CONNECTION_PER_HOST = "maximumHttpConnectionPerHost";
|
||||||
|
public static final String TOKEN_VALIDATION_ENDPOINT_URL = "tokenValidationEndpoint";
|
||||||
|
public static final String USERNAME = "username";
|
||||||
|
public static final String PASSWORD = "password";
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.iot.output.adapter.ui.service;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.iot.output.adapter.ui.authentication.Authenticator;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.output.adapter.ui.authorization.Authorizer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This returns the configured authenticator and authorizer for websocket.
|
||||||
|
*/
|
||||||
|
public interface WebsocketValidationService {
|
||||||
|
|
||||||
|
Authenticator getAuthenticator();
|
||||||
|
|
||||||
|
Authorizer getAuthorizer();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.iot.output.adapter.ui.service;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.iot.output.adapter.ui.authentication.Authenticator;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.output.adapter.ui.authorization.Authorizer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This returns the configured authenticator and authorizer for websocket.
|
||||||
|
*/
|
||||||
|
public class WebsocketValidationServiceImpl implements WebsocketValidationService{
|
||||||
|
private Authenticator authenticator;
|
||||||
|
private Authorizer authorizer;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Authenticator getAuthenticator() {
|
||||||
|
return authenticator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Authorizer getAuthorizer() {
|
||||||
|
return authorizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthenticator(Authenticator authenticator) {
|
||||||
|
this.authenticator = authenticator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthorizer(Authorizer authorizer) {
|
||||||
|
this.authorizer = authorizer;
|
||||||
|
}
|
||||||
|
}
|
10
components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/WebSocketSessionUtil.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/WebSocketSessionRequest.java
10
components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/WebSocketSessionUtil.java → components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/WebSocketSessionRequest.java
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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.iot.output.adapter.ui.util;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.wso2.carbon.device.mgt.iot.output.adapter.ui.config.WebsocketValidationConfigurationFailedException;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class holds util methods used by OAuth extension bundle.
|
||||||
|
*/
|
||||||
|
public class WebsocketUtils {
|
||||||
|
|
||||||
|
public static Document convertToDocument(File file) throws WebsocketValidationConfigurationFailedException {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
factory.setNamespaceAware(true);
|
||||||
|
try {
|
||||||
|
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||||
|
return docBuilder.parse(file);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new WebsocketValidationConfigurationFailedException("Error occurred while parsing file, while converting " +
|
||||||
|
"to a org.w3c.dom.Document", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
instructions.configure = \
|
instructions.configure = \
|
||||||
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\
|
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\
|
||||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.adapter_${feature.version}/webapps/,target:${installFolder}/../../deployment/server/webapps/,overwrite:true);\
|
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.adapter_${feature.version}/webapps/,target:${installFolder}/../../deployment/server/webapps/,overwrite:true);\
|
||||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.adapter_${feature.version}/websocket-validation.properties,target:${installFolder}/../../conf/etc/websocket-validation.properties,overwrite:true);\
|
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.adapter_${feature.version}/websocket-validation.xml,target:${installFolder}/../../conf/etc/websocket-validation.xml,overwrite:true);\
|
||||||
|
@ -1,25 +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.
|
|
||||||
#
|
|
||||||
|
|
||||||
#This hold the properties that is used for token validation for the the websocket
|
|
||||||
|
|
||||||
tokenValidationEndpoint=https://localhost:9443/services/OAuth2TokenValidationService
|
|
||||||
username=admin
|
|
||||||
password=admin
|
|
||||||
maximumHttpConnectionPerHost=2
|
|
||||||
maximumTotalHttpConnection=100
|
|
@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
This configuration file represents the configuration that are needed
|
||||||
|
for websocket connection validation
|
||||||
|
-->
|
||||||
|
<WebsocketValidationConfigs>
|
||||||
|
|
||||||
|
<!--Authenticator is holds the information of authticator that is used for websocket-->
|
||||||
|
<Authenticator class="org.wso2.carbon.device.mgt.iot.output.adapter.ui.authentication.OAuthAuthenticator">
|
||||||
|
<Properties>
|
||||||
|
<Property name="tokenValidationEndpoint">https://localhost:9443/services/OAuth2TokenValidationService</Property>
|
||||||
|
<Property name="username">admin</Property>
|
||||||
|
<Property name="password">admin</Property>
|
||||||
|
<Property name="maximumHttpConnectionPerHost">2</Property>
|
||||||
|
<Property name="maximumTotalHttpConnection">100</Property>
|
||||||
|
</Properties>
|
||||||
|
</Authenticator>
|
||||||
|
|
||||||
|
<!--Authorizer holds the information of the authorizer that is used authorize a connection.-->
|
||||||
|
<Authorizer class="org.wso2.carbon.device.mgt.iot.output.adapter.ui.authorization.DeviceAuthorizer"></Authorizer>
|
||||||
|
</WebsocketValidationConfigs>
|
Loading…
Reference in new issue