Skip to content

Commit

Permalink
Fix of Forbidden error when auth cookie gets expired.
Browse files Browse the repository at this point in the history
Fix of issue with XStream 4.1.18 library.
  • Loading branch information
andan67 committed Oct 27, 2021
1 parent 230392d commit 49f9486
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.sony/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<version>3.1.0-SNAPSHOT</version>
</parent>

<version>3.1.1</version>
<version>3.1.3</version>
<artifactId>org.openhab.binding.sony</artifactId>

<name>openHAB Add-ons :: Bundles :: Sony Binding</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.sony.internal.SonyHandlerFactory;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.thoughtworks.xstream.security.NoTypePermission;

/**
* This class represents creates the various XML readers (using XStream) to deserialize various calls.
Expand Down Expand Up @@ -53,6 +55,8 @@ public class DialXmlReader<T> {
private DialXmlReader(@SuppressWarnings("rawtypes") final Class[] classes) {
Objects.requireNonNull(classes, "classes cannot be null");

xstream.addPermission(NoTypePermission.NONE);
xstream.allowTypesByWildcard(new String[] { SonyHandlerFactory.class.getPackageName() + ".**" });
xstream.setClassLoader(getClass().getClassLoader());
xstream.ignoreUnknownElements();
xstream.processAnnotations(classes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.jupnp.UpnpService;
import org.openhab.binding.sony.internal.SonyHandlerFactory;
import org.openhab.binding.sony.internal.upnp.models.UpnpServiceList;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.thoughtworks.xstream.security.NoTypePermission;

/**
* This class represents creates the various XML readers (using XStream) to deserialize various calls.
Expand Down Expand Up @@ -71,6 +73,9 @@ public class IrccXmlReader<T> {
private IrccXmlReader(@SuppressWarnings("rawtypes") final Class[] classes, final Converter... converters) {
Objects.requireNonNull(classes, "classes cannot be null");

// XStream.setupDefaultSecurity(xstream);
xstream.addPermission(NoTypePermission.NONE);
xstream.allowTypesByWildcard(new String[] { SonyHandlerFactory.class.getPackageName() + ".**" });
xstream.setClassLoader(getClass().getClassLoader());
xstream.ignoreUnknownElements();
xstream.processAnnotations(classes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ protected void connect() {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Error connecting to Scalar Web device (may need to turn it on manually)");
} catch (final Exception e) {
logger.debug("Unhandled exception connecting to Scalar Web device: {} ", e.getMessage(), e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Unhandled exception connecting to Scalar Web device (may need to turn it on manually): "
+ e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ public void filter(final @Nullable ClientRequestContext requestCtx) throws IOExc
final NewCookie authCookie = newCookies.get(AUTHCOOKIENAME);
if (authCookie != null) {
// create cookie with expiry date using 80% of maxAge given in seconds
final Date expiryDate = new Date(new Date().getTime() + 800L *authCookie.getMaxAge());
final NewCookie newAuthCookieToStore = new NewCookie(
authCookie.toCookie(), authCookie.getComment(), authCookie.getMaxAge(),
expiryDate, authCookie.isSecure(), authCookie.isHttpOnly());
final Date expiryDate = new Date(new Date().getTime() + 800L * authCookie.getMaxAge());
final NewCookie newAuthCookieToStore = new NewCookie(authCookie.toCookie(),
authCookie.getComment(), authCookie.getMaxAge(), expiryDate, authCookie.isSecure(),
authCookie.isHttpOnly());
logger.debug("Authorization cookie was renewed");
logger.debug("New auth cookie: {} for host: {}", newAuthCookieToStore.getValue(), host);
authCookieStore.setAuthCookieForHost(host, newAuthCookieToStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.sony.internal.SonyHandlerFactory;
import org.openhab.binding.sony.internal.SonyUtil;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.thoughtworks.xstream.security.NoTypePermission;

/**
* This class represents creates the various XML readers (using XStream) to deserialize various calls.
Expand Down Expand Up @@ -47,6 +49,8 @@ public class UpnpXmlReader<T> {
private UpnpXmlReader(@SuppressWarnings("rawtypes") final Class[] classes) {
Objects.requireNonNull(classes, "classes cannot be null");

xstream.addPermission(NoTypePermission.NONE);
xstream.allowTypesByWildcard(new String[] { SonyHandlerFactory.class.getPackageName() + ".**" });
xstream.setClassLoader(getClass().getClassLoader());
xstream.ignoreUnknownElements();
xstream.processAnnotations(classes);
Expand Down

0 comments on commit 49f9486

Please sign in to comment.