Skip to content

Commit

Permalink
feat(jans-config-api): user mgmt endpoint - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pujavs committed Mar 28, 2022
1 parent 41b6fa1 commit aadbf8b
Show file tree
Hide file tree
Showing 6 changed files with 576 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text.
*
* Copyright (c) 2020, Janssen Project
*/

package io.jans.configapi.rest.model;

import io.jans.as.model.exception.InvalidClaimException;
import org.json.JSONArray;

import java.util.List;

public class BasePerson extends io.jans.orm.model.base.SimpleUser {

private static final long serialVersionUID = -2634191420188575733L;

public Object getAttribute(String attributeName, boolean optional, boolean multivalued) throws InvalidClaimException {
Object attribute = null;

List<String> values = getAttributeValues(attributeName);
if (values != null) {
if (multivalued) {
JSONArray array = new JSONArray();
for (String v : values) {
array.put(v);
}
attribute = array;
} else {
attribute = values.get(0);
}
}

if (attribute != null) {
return attribute;
} else if (optional) {
return attribute;
} else {
throw new InvalidClaimException("The claim " + attributeName + " was not found.");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text.
*
* Copyright (c) 2020, Janssen Project
*/

package io.jans.configapi.rest.model;

import io.jans.model.GluuStatus;
import io.jans.orm.annotation.AttributeName;
import io.jans.orm.annotation.DataEntry;
import io.jans.orm.annotation.ObjectClass;
import io.jans.orm.model.base.CustomObjectAttribute;
import io.jans.util.StringHelper;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;


@DataEntry
@ObjectClass(value = "jansPerson")
public class Person extends BasePerson {

private static final long serialVersionUID = 6634191420188575733L;

@JsonProperty("inum")
@AttributeName(name = "inum", ignoreDuringUpdate = true)
private String inum;

@AttributeName(name = "jansAssociatedClnt", consistency = true)
private List<String> associatedClient;

@AttributeName(name = "c")
private String countryName;

@AttributeName(name = "displayName")
private String displayName;

@AttributeName(name = "givenName")
private String givenName;

@AttributeName(name = "jansManagedOrganizations")
private List<String> managedOrganizations;

@AttributeName(name = "jansOptOuts")
private List<String> optOuts;

@AttributeName(name = "jansStatus")
private GluuStatus status;

@AttributeName(name = "mail")
private String mail;

@AttributeName(name = "memberOf")
private List<String> memberOf;

@AttributeName(name = "o")
private String organization;

@AttributeName(name = "jansExtUid")
private List<String> extUid;

@AttributeName(name = "jansOTPCache")
private List<String> otpCache;

@AttributeName(name = "jansLastLogonTime")
private Date lastLogonTime;

@AttributeName(name = "jansActive")
private boolean active;

@AttributeName(name = "jansAddres")
private List<String> addres;

@AttributeName(name = "jansEmail")
private List<String> email;

@AttributeName(name = "jansEntitlements")
private List<String> entitlements;



public void setAttribute(String attributeName, String attributeValue, Boolean multiValued) {
CustomObjectAttribute attribute = new CustomObjectAttribute(attributeName, attributeValue);
if (multiValued != null) {
attribute.setMultiValued(multiValued);
}

removeAttribute(attributeName);
getCustomAttributes().add(attribute);
}

@Deprecated
public void setAttribute(String attributeName, String[] attributeValues) {
setAttribute(attributeName, attributeValues, null);
}

public void setAttribute(String attributeName, String[] attributeValues, Boolean multiValued) {
CustomObjectAttribute attribute = new CustomObjectAttribute(attributeName, Arrays.asList(attributeValues));
if (multiValued != null) {
attribute.setMultiValued(multiValued);
}

removeAttribute(attributeName);
getCustomAttributes().add(attribute);
}

@Deprecated
public void setAttribute(String attributeName, List<String> attributeValues) {
setAttribute(attributeName, attributeValues, null);
}

public void setAttribute(String attributeName, List<String> attributeValues, Boolean multiValued) {
CustomObjectAttribute attribute = new CustomObjectAttribute(attributeName, attributeValues);
if (multiValued != null) {
attribute.setMultiValued(multiValued);
}

removeAttribute(attributeName);
getCustomAttributes().add(attribute);
}

public void removeAttribute(String attributeName) {
for (Iterator<CustomObjectAttribute> it = getCustomAttributes().iterator(); it.hasNext(); ) {
if (StringHelper.equalsIgnoreCase(attributeName, it.next().getName())) {
it.remove();
break;
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ private ApiAccessConstants() {
public static final String ORG_CONFIG_READ_ACCESS = "https://jans.io/oauth/config/organization.readonly";
public static final String ORG_CONFIG_WRITE_ACCESS = "https://jans.io/oauth/config/organization.write";

public static final String USER_READ_ACCESS = "https://jans.io/oauth/config/user.readonly";
public static final String USER_WRITE_ACCESS = "https://jans.io/oauth/config/user.write";
public static final String USER_DELETE_ACCESS = "https://jans.io/oauth/config/user.delete";

}
91 changes: 90 additions & 1 deletion jans-config-api/docs/jans-config-api-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6744,4 +6744,93 @@ components:
$ref: '#/components/schemas/FacterData'
description: Underlying Server stats


User:
title: User object
description: User.
type: object
required:
- displayName
properties:
inum:
description: XRI i-number. Identifier to uniquely identify the user.
type: string
associatedClient:
description: dn of associated clients with the person.
type: array
items:
type: string
countryName:
description: county name.
type: string
displayName:
description: Name of the user suitable for display to end-users
type: string
givenName:
description: Given name(s) or first name(s) of the End-User.
type: string
managedOrganizations:
description: Organizations with which a person is associated.
type: array
items:
type: string
optOuts:
description: White pages attributes restricted by person in exclude profile management.
type: array
items:
type: string
status:
description: Status of the entry.
type: string
mail:
description: Primary Email Address.
type: string
memberOf:
description: Groups with which a person is associated.
type: array
items:
type: string
organization:
description: Users organization.
type: string
oxAuthPersistentJwt:
description: Persistent JWT.
type: array
items:
type: string
createdAt:
description: User creation date.
type: string
format: date-time
extUid:
description: List of associated external uid.
type: array
items:
type: string
otpCache:
description: List of used OTP to prevent a hacker from using it again. Complementary to jansExtUid attribute.
type: array
items:
type: string
lastLogonTime:
description: 'Integer timestamp, measured in the number of seconds since January 1 1970 UTC, indicating last login time.'
type: string
format: date-time
active:
type: boolean
description: boolean value indicating if user is active.
default: true
addres:
description: List of users address.
type: array
items:
$ref: '#/components/schemas/Address'
email:
description: List of users email address.
type: array
items:
type: string
entitlements:
description: List of users entitlement.
type: array
items:
$ref: '#/components/schemas/Entitlement'
Loading

0 comments on commit aadbf8b

Please sign in to comment.