Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-1359: Create Authorizer for Bootstrap server
- Loading branch information
1 parent
7547de5
commit 05dbddb
Showing
5 changed files
with
113 additions
and
30 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
51 changes: 51 additions & 0 deletions
51
...er-core/src/main/java/org/eclipse/leshan/server/bootstrap/DefaultBootstrapAuthorizer.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,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Orange - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.server.bootstrap; | ||
|
||
import java.util.Iterator; | ||
|
||
import org.eclipse.leshan.core.request.BootstrapRequest; | ||
import org.eclipse.leshan.core.request.Identity; | ||
import org.eclipse.leshan.server.security.BootstrapAuthorizer; | ||
import org.eclipse.leshan.server.security.BootstrapSecurityStore; | ||
import org.eclipse.leshan.server.security.SecurityChecker; | ||
import org.eclipse.leshan.server.security.SecurityInfo; | ||
|
||
public class DefaultBootstrapAuthorizer implements BootstrapAuthorizer { | ||
|
||
private BootstrapSecurityStore bsSecurityStore; | ||
private SecurityChecker securityChecker; | ||
|
||
public DefaultBootstrapAuthorizer(BootstrapSecurityStore bsSecurityStore, SecurityChecker securityChecker) { | ||
this.bsSecurityStore = bsSecurityStore; | ||
this.securityChecker = securityChecker; | ||
} | ||
|
||
public DefaultBootstrapAuthorizer(BootstrapSecurityStore bsSecurityStore) { | ||
this.bsSecurityStore = bsSecurityStore; | ||
this.securityChecker = new SecurityChecker(); | ||
} | ||
|
||
@Override | ||
public boolean isAuthorized(BootstrapRequest request, Identity clientIdentity) { | ||
if (bsSecurityStore != null && securityChecker != null) { | ||
Iterator<SecurityInfo> securityInfos = bsSecurityStore.getAllByEndpoint(request.getEndpointName()); | ||
return securityChecker.checkSecurityInfos(request.getEndpointName(), clientIdentity, securityInfos); | ||
} else { | ||
return true; | ||
} | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
leshan-server-core/src/main/java/org/eclipse/leshan/server/security/BootstrapAuthorizer.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,31 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Orange - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.server.security; | ||
|
||
import org.eclipse.leshan.core.request.BootstrapRequest; | ||
import org.eclipse.leshan.core.request.Identity; | ||
|
||
public interface BootstrapAuthorizer { | ||
|
||
/** | ||
* Returns if request is authorized for given client identity. | ||
* | ||
* @param request the request received | ||
* @param clientIdentity the {@link Identity} of the client that sent the request. | ||
* @return <code>true</code> if request is authorized or <code>false</code> if it is not authorized. | ||
*/ | ||
boolean isAuthorized(BootstrapRequest request, Identity clientIdentity); | ||
} |