Skip to content

Commit

Permalink
Add Auth0 migration service
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet committed Mar 18, 2024
1 parent 0ca0416 commit 981a58e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.auth0.client.auth.AuthAPI;
import com.auth0.client.mgmt.filter.RolesFilter;
import com.auth0.client.mgmt.filter.UserFilter;
import com.auth0.exception.APIException;
import com.auth0.exception.Auth0Exception;
import no.rutebanken.baba.organisation.model.OrganisationException;
import no.rutebanken.baba.organisation.model.responsibility.ResponsibilitySet;
Expand All @@ -28,6 +29,7 @@
public class Auth0IamService implements IamService {

private static final String ROR_ROLES_PREFIX = "ror_";
public static final int HTTP_STATUS_CODE_409_CONFLICT = 409;

private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final List<String> defaultRoles;
Expand Down Expand Up @@ -144,6 +146,14 @@ public void createRole(Role role) {
try {
com.auth0.json.mgmt.roles.Role createdRole = auth0ManagementAPI.getManagementAPI().roles().create(auth0Role).execute().getBody();
logger.info("Role {} successfully created in Auth0 with target name {}", role.getId(), createdRole.getName());
} catch (APIException e) {
if(e.getStatusCode() == HTTP_STATUS_CODE_409_CONFLICT) {
logger.info("The role {} already exists", role.getId());
}
else {
throw new OrganisationException("Failed to create role");
}

} catch (Exception e) {
logger.error("Failed to create role {}", role.getId(), e);
throw new OrganisationException("Failed to create role");
Expand Down Expand Up @@ -405,9 +415,9 @@ private com.auth0.json.mgmt.users.User getAuth0UserByEmail(String email, boolean
String query;
//TODO replace hardcoded preprovisioning
if (preProvisioning) {
query = "email:\"" + email + "\" AND identities.connection:\"preprovisioning\"";
query = "email:\"" + email + "\" AND identities.connection:\"preprovision\"";
} else {
query = "email:\"" + email + "\" AND NOT identities.connection:\"preprovisioning\"";
query = "email:\"" + email + "\" AND NOT identities.connection:\"preprovision\"";
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Auth0UserMapper {
private final String preProvisionedConnection;

public Auth0UserMapper(@Value("${iam.auth0.admin.connection:Username-Password-Authentication}") String connection,
@Value("${iam.auth0.admin.connection.preprovisioning:preprovisioning}") String preProvisionedConnection) {
@Value("${iam.auth0.admin.connection.preprovisioning:preprovision}") String preProvisionedConnection) {
this.connection = connection;
this.preProvisionedConnection = preProvisionedConnection;
}
Expand Down

0 comments on commit 981a58e

Please sign in to comment.