This repository has been archived by the owner on Jul 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RFES-13: adds session creation policy
- Loading branch information
Showing
9 changed files
with
108 additions
and
26 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
26 changes: 26 additions & 0 deletions
26
...rity/src/main/java/org/echocat/marquardt/authority/persistence/SessionCreationPolicy.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,26 @@ | ||
/* | ||
* echocat Marquardt Java SDK, Copyright (c) 2015 echocat | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package org.echocat.marquardt.authority.persistence; | ||
|
||
import java.util.UUID; | ||
|
||
public interface SessionCreationPolicy { | ||
|
||
/** | ||
* You can use this to implement different policies how access to create a session is granted. | ||
* This may be a one session per user per client policy, or maybe you want some clients to create more sessions than | ||
* others. | ||
* | ||
* @param userId User id of the user. | ||
* @param clientPublicKey Public key of the client. | ||
* @return True if (another) session may be created, false if not. | ||
*/ | ||
boolean mayCreateSession(UUID userId, byte[] clientPublicKey); | ||
|
||
} |
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
40 changes: 40 additions & 0 deletions
40
...le/src/main/java/org/echocat/marquardt/example/persistence/OneSessionPerClientPolicy.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,40 @@ | ||
/* | ||
* echocat Marquardt Java SDK, Copyright (c) 2015 echocat | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package org.echocat.marquardt.example.persistence; | ||
|
||
import org.echocat.marquardt.authority.persistence.SessionCreationPolicy; | ||
import org.echocat.marquardt.authority.persistence.SessionStore; | ||
import org.echocat.marquardt.common.util.DateProvider; | ||
import org.echocat.marquardt.example.domain.PersistentSession; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
public class OneSessionPerClientPolicy implements SessionCreationPolicy { | ||
|
||
private final SessionStore<PersistentSession> _sessionStore; | ||
private DateProvider _dateProvider; | ||
|
||
@Autowired | ||
public OneSessionPerClientPolicy(SessionStore<PersistentSession> sessionStore) { | ||
_sessionStore = sessionStore; | ||
_dateProvider = new DateProvider(); | ||
} | ||
|
||
@Override | ||
public boolean mayCreateSession(UUID userId, byte[] clientPublicKey) { | ||
return !_sessionStore.existsActiveSession(userId, clientPublicKey, _dateProvider.now()); | ||
} | ||
|
||
public void setDateProvider(DateProvider dateProvider) { | ||
_dateProvider = dateProvider; | ||
} | ||
} |