-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved out password credentials out of core package (they are not mandatory kind of creds any more). Added session cookie authentication. Signed-off-by: Łukasz Dywicki <luke@code-house.org>
- Loading branch information
Showing
27 changed files
with
392 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.opensmarthouse.core.bundles</groupId> | ||
<artifactId>org.opensmarthouse.core.reactor.bundles</artifactId> | ||
<version>0.9.2-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>org.opensmarthouse.core.auth.cookie</artifactId> | ||
|
||
<name>OpenSmartHouse Core | Bundles | Cookie Credentials</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.opensmarthouse.core.bundles</groupId> | ||
<artifactId>org.opensmarthouse.core.auth</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
45 changes: 45 additions & 0 deletions
45
...thouse.core.auth.cookie/src/main/java/org/openhab/core/auth/cookie/CookieCredentials.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright (c) 2019-2020 Contributors to the OpenSmartHouse project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.auth.cookie; | ||
|
||
import org.openhab.core.auth.Credentials; | ||
|
||
/** | ||
* Credentials which represent key/value pair coming from HTTP cookie. | ||
* | ||
* @author Łukasz Dywicki - Initial contribution. | ||
*/ | ||
public class CookieCredentials implements Credentials { | ||
|
||
private final String name; | ||
private final String value; | ||
|
||
public CookieCredentials(String name, String value) { | ||
this.name = name; | ||
this.value = value; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public String getScheme() { | ||
return "cookie"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
bundles/org.opensmarthouse.core.io.http.auth.cookie/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.opensmarthouse.core.bundles</groupId> | ||
<artifactId>org.opensmarthouse.core.reactor.bundles</artifactId> | ||
<version>0.9.2-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>org.opensmarthouse.core.io.http.auth.cookie</artifactId> | ||
|
||
<name>OpenSmartHouse Core | Bundles | HTTP Cookie Authentication</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.opensmarthouse.core.bundles</groupId> | ||
<artifactId>org.opensmarthouse.core.auth.cookie</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.opensmarthouse.core.bundles</groupId> | ||
<artifactId>org.opensmarthouse.core.io.auth</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.opensmarthouse.core.bundles</groupId> | ||
<artifactId>org.opensmarthouse.core.io.http.facade</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.opensmarthouse.core.bundles</groupId> | ||
<artifactId>org.opensmarthouse.core.io.http.auth</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
42 changes: 42 additions & 0 deletions
42
...c/main/java/org/openhab/core/io/http/auth/cookie/internal/CookieCredentialsExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) 2010-2020 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.io.http.auth.cookie.internal; | ||
|
||
import java.util.Optional; | ||
|
||
import org.openhab.core.auth.Credentials; | ||
import org.openhab.core.auth.cookie.CookieCredentials; | ||
import org.openhab.core.io.auth.CredentialsExtractor; | ||
import org.openhab.core.io.http.facade.Cookie; | ||
import org.openhab.core.io.http.facade.HttpRequestDelegate; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
/** | ||
* Extract session information from cookie inincoming request. | ||
* | ||
* @author Łukasz Dywicki - Initial contribution. | ||
*/ | ||
@Component(property = { "context=org.openhab.core.io.http.facade.HttpRequestDelegate" }) | ||
public class CookieCredentialsExtractor implements CredentialsExtractor<HttpRequestDelegate> { | ||
|
||
public static final String SESSIONID_COOKIE_NAME = "X-OPENHAB-SESSIONID"; | ||
|
||
@Override | ||
public Optional<Credentials> retrieveCredentials(HttpRequestDelegate request) { | ||
return request.getCookie(SESSIONID_COOKIE_NAME).map(this::process); | ||
} | ||
|
||
private CookieCredentials process(Cookie cookie) { | ||
return new CookieCredentials(cookie.getName(), cookie.getValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...nsmarthouse.core.io.http.facade/src/main/java/org/openhab/core/io/http/facade/Cookie.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright (c) 2019-2020 Contributors to the OpenSmartHouse project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.io.http.facade; | ||
|
||
/** | ||
* An unified (facade) version of http cookie. | ||
* | ||
* @author Łukasz Dywicki - Initial contribution. | ||
*/ | ||
public class Cookie { | ||
|
||
private final String name; | ||
private final String value; | ||
|
||
public Cookie(String name, String value) { | ||
this.name = name; | ||
this.value = value; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.