-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: endpoint to get details of connected FIDO devices registered to…
… users #1465 (#1466) * feat: need endpoint to get details of connected FIDO devices registered to users #1465 * feat: need endpoint to get details of connected FIDO devices registered to users #1465
- Loading branch information
Showing
9 changed files
with
271 additions
and
2 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
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
38 changes: 38 additions & 0 deletions
38
...2-plugin/src/main/java/io/jans/configapi/plugin/fido2/rest/Fido2RegistrationResource.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 @@ | ||
package io.jans.configapi.plugin.fido2.rest; | ||
|
||
import io.jans.configapi.core.rest.BaseResource; | ||
import io.jans.configapi.core.rest.ProtectedApi; | ||
import io.jans.configapi.plugin.fido2.service.Fido2RegistrationService; | ||
import io.jans.configapi.plugin.fido2.util.Constants; | ||
import io.jans.configapi.util.ApiAccessConstants; | ||
import io.jans.configapi.util.ApiConstants; | ||
import io.jans.fido2.model.entry.Fido2RegistrationEntry; | ||
import jakarta.inject.Inject; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.ws.rs.*; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
import org.slf4j.Logger; | ||
|
||
import java.util.List; | ||
|
||
@Path(Constants.REGISTRATION) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public class Fido2RegistrationResource extends BaseResource { | ||
|
||
@Inject | ||
Logger logger; | ||
|
||
@Inject | ||
Fido2RegistrationService fido2RegistrationService; | ||
|
||
@GET | ||
@Path(Constants.ENTRIES + ApiConstants.USERNAME_PATH) | ||
@ProtectedApi(scopes = {ApiAccessConstants.FIDO2_CONFIG_READ_ACCESS}) | ||
public Response findAllRegisteredByUsername(@PathParam("username") @NotNull String username) { | ||
logger.debug("FIDO2 registration entries by username."); | ||
List<Fido2RegistrationEntry> entries = fido2RegistrationService.findAllRegisteredByUsername(username); | ||
return Response.ok(entries).build(); | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...plugin/src/main/java/io/jans/configapi/plugin/fido2/service/Fido2RegistrationService.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,106 @@ | ||
/* | ||
* Janssen Project software is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text. | ||
* | ||
* Copyright (c) 2020, Janssen Project | ||
*/ | ||
|
||
package io.jans.configapi.plugin.fido2.service; | ||
|
||
import io.jans.as.common.service.common.UserService; | ||
import io.jans.as.model.config.StaticConfiguration; | ||
import io.jans.fido2.model.entry.Fido2RegistrationEntry; | ||
import io.jans.fido2.model.entry.Fido2RegistrationStatus; | ||
import io.jans.orm.PersistenceEntryManager; | ||
import io.jans.orm.model.base.SimpleBranch; | ||
import io.jans.orm.search.filter.Filter; | ||
import io.jans.util.StringHelper; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import org.slf4j.Logger; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Yuriy Movchan | ||
* @version May 08, 2020 | ||
*/ | ||
@ApplicationScoped | ||
public class Fido2RegistrationService { | ||
|
||
@Inject | ||
private Logger log; | ||
|
||
@Inject | ||
private StaticConfiguration staticConfiguration; | ||
|
||
@Inject | ||
private UserService userService; | ||
|
||
@Inject | ||
private PersistenceEntryManager persistenceEntryManager; | ||
|
||
public List<Fido2RegistrationEntry> findAllByUsername(String username) { | ||
String userInum = userService.getUserInum(username); | ||
if (userInum == null) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
String baseDn = getBaseDnForFido2RegistrationEntries(userInum); | ||
if (persistenceEntryManager.hasBranchesSupport(baseDn)) { | ||
if (!containsBranch(baseDn)) { | ||
return Collections.emptyList(); | ||
} | ||
} | ||
|
||
Filter userFilter = Filter.createEqualityFilter("personInum", userInum); | ||
|
||
List<Fido2RegistrationEntry> fido2RegistrationnEntries = persistenceEntryManager.findEntries(baseDn, Fido2RegistrationEntry.class, userFilter); | ||
|
||
return fido2RegistrationnEntries; | ||
} | ||
|
||
public List<Fido2RegistrationEntry> findAllRegisteredByUsername(String username) { | ||
String userInum = userService.getUserInum(username); | ||
if (userInum == null) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
String baseDn = getBaseDnForFido2RegistrationEntries(userInum); | ||
if (persistenceEntryManager.hasBranchesSupport(baseDn)) { | ||
if (!containsBranch(baseDn)) { | ||
return Collections.emptyList(); | ||
} | ||
} | ||
|
||
Filter userInumFilter = Filter.createEqualityFilter("personInum", userInum); | ||
Filter registeredFilter = Filter.createEqualityFilter("jansStatus", Fido2RegistrationStatus.registered.getValue()); | ||
Filter filter = Filter.createANDFilter(userInumFilter, registeredFilter); | ||
|
||
List<Fido2RegistrationEntry> fido2RegistrationnEntries = persistenceEntryManager.findEntries(baseDn, Fido2RegistrationEntry.class, filter); | ||
|
||
return fido2RegistrationnEntries; | ||
} | ||
|
||
public String getBaseDnForFido2RegistrationEntries(String userInum) { | ||
final String userBaseDn = getDnForUser(userInum); // "ou=fido2_register,inum=1234,ou=people,o=jans" | ||
if (StringHelper.isEmpty(userInum)) { | ||
return userBaseDn; | ||
} | ||
|
||
return String.format("ou=fido2_register,%s", userBaseDn); | ||
} | ||
|
||
public String getDnForUser(String userInum) { | ||
String peopleDn = staticConfiguration.getBaseDn().getPeople(); | ||
if (StringHelper.isEmpty(userInum)) { | ||
return peopleDn; | ||
} | ||
|
||
return String.format("inum=%s,%s", userInum, peopleDn); | ||
} | ||
|
||
public boolean containsBranch(final String baseDn) { | ||
return persistenceEntryManager.contains(baseDn, SimpleBranch.class); | ||
} | ||
} |
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