Skip to content

Commit

Permalink
feat: call id-generation script when creating user/group #1145
Browse files Browse the repository at this point in the history
  • Loading branch information
jgomer2001 committed May 12, 2022
1 parent 338166d commit 3a9a03a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public void applicationInitialized(@Observes @Initialized(ApplicationScoped.clas
configurationFactory.initTimer();
loggerService.initTimer();
//externalScimService.init();
customScriptManager.initTimer(Arrays.asList(CustomScriptType.SCIM, CustomScriptType.PERSISTENCE_EXTENSION));
customScriptManager.initTimer(Arrays.asList(
CustomScriptType.SCIM, CustomScriptType.PERSISTENCE_EXTENSION, CustomScriptType.ID_GENERATOR));
logger.info("Initialized!");

}
Expand Down
4 changes: 4 additions & 0 deletions jans-scim/service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
<groupId>io.jans</groupId>
<artifactId>jans-auth-client</artifactId>
</dependency>
<dependency>
<groupId>io.jans</groupId>
<artifactId>jans-auth-common</artifactId>
</dependency>

<!-- Weld -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@

package io.jans.scim.service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import org.slf4j.Logger;

import io.jans.as.common.service.common.ExternalIdGeneratorService;
import io.jans.as.model.common.IdType;
import io.jans.orm.PersistenceEntryManager;
import io.jans.orm.exception.EntryPersistenceException;
import io.jans.orm.exception.operation.DuplicateEntryException;
Expand All @@ -29,6 +21,15 @@
import io.jans.util.ArrayHelper;
import io.jans.util.StringHelper;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.slf4j.Logger;

/**
* Provides operations with groups
*
Expand All @@ -51,6 +52,9 @@ public class GroupService implements Serializable {
@Inject
private PersonService personService;

@Inject
private ExternalIdGeneratorService idGeneratorService;

public void addGroup(GluuGroup group) throws Exception {
GluuGroup displayNameGroup = new GluuGroup();
displayNameGroup.setDisplayName(group.getDisplayName());
Expand Down Expand Up @@ -179,7 +183,19 @@ public GluuGroupVisibility[] getVisibilityTypes() {
* @return New inum for group
*/
private String generateInumForNewGroupImpl() throws Exception {
return UUID.randomUUID().toString();

String id = null;
if (idGeneratorService.isEnabled()) {
id = idGeneratorService.executeExternalGenerateIdMethod(
//Use the first enabled script only
idGeneratorService.getCustomScriptConfigurations().stream().findFirst().orElse(null)
, "" //appId
, IdType.GROUP.getType() //idType
, "" //idPrefix
);
}
return id == null ? UUID.randomUUID().toString() : id;

}

public GluuGroup getGroupByDn(String Dn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@

package io.jans.scim.service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.time.Instant;
import java.util.UUID;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import io.jans.as.common.service.common.ExternalIdGeneratorService;
import io.jans.as.model.common.IdType;
import io.jans.model.GluuAttribute;
import io.jans.orm.PersistenceEntryManager;
import io.jans.orm.exception.operation.DuplicateEntryException;
Expand All @@ -27,16 +16,28 @@
import io.jans.orm.model.base.SimpleBranch;
import io.jans.orm.model.base.SimpleUser;
import io.jans.orm.search.filter.Filter;
import io.jans.util.ArrayHelper;
import io.jans.util.OxConstants;
import io.jans.util.StringHelper;
import org.slf4j.Logger;

import io.jans.scim.exception.DuplicateEmailException;
import io.jans.scim.model.GluuCustomAttribute;
import io.jans.scim.model.GluuCustomPerson;
import io.jans.scim.model.User;
import io.jans.scim.util.OxTrustConstants;
import io.jans.util.ArrayHelper;
import io.jans.util.OxConstants;
import io.jans.util.StringHelper;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.time.Instant;
import java.util.UUID;

import org.slf4j.Logger;

/**
* Provides operations with persons
Expand All @@ -60,6 +61,9 @@ public class PersonService implements Serializable {
@Inject
private OrganizationService organizationService;

@Inject
private ExternalIdGeneratorService idGeneratorService;

private List<GluuCustomAttribute> mandatoryAttributes;

public void addCustomObjectClass(GluuCustomPerson person) {
Expand Down Expand Up @@ -274,7 +278,19 @@ public String generateInumForNewPerson() {
* @throws Exception
*/
private String generateInumForNewPersonImpl() {
return UUID.randomUUID().toString();

String id = null;
if (idGeneratorService.isEnabled()) {
id = idGeneratorService.executeExternalGenerateIdMethod(
//Use the first enabled script only
idGeneratorService.getCustomScriptConfigurations().stream().findFirst().orElse(null)
, "" //appId
, IdType.PEOPLE.getType() //idType
, "" //idPrefix
);
}
return id == null ? UUID.randomUUID().toString() : id;

}

public String getDnForPerson(String inum) {
Expand Down

0 comments on commit 3a9a03a

Please sign in to comment.