Search in sources :

Example 31 with User

use of org.gluu.oxtrust.model.scim2.User in project oxTrust by GluuFederation.

the class Scim2UserService method updateUser.

public UserResource updateUser(String id, UserResource user, String url) throws InvalidAttributeValueException {
    // This is never null (see decorator involved)
    GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
    UserResource tmpUser = new UserResource();
    transferAttributesToUserResource(gluuPerson, tmpUser, url);
    long now = System.currentTimeMillis();
    tmpUser.getMeta().setLastModified(ISODateTimeFormat.dateTime().withZoneUTC().print(now));
    tmpUser = (UserResource) ScimResourceUtil.transferToResourceReplace(user, tmpUser, extService.getResourceExtensions(user.getClass()));
    replacePersonInfo(gluuPerson, tmpUser, url);
    return tmpUser;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource)

Example 32 with User

use of org.gluu.oxtrust.model.scim2.User in project oxTrust by GluuFederation.

the class Scim2UserService method transferExtendedAttributesToPerson.

/**
 * Takes all extended attributes found in the SCIM resource and copies them to a GluuCustomPerson
 * This method is called after validations take place (see associated decorator for User Service), so all inputs are
 * OK and can go straight to LDAP with no runtime surprises
 * @param resource A SCIM resource used as origin of data
 * @param person a GluuCustomPerson used as destination
 */
private void transferExtendedAttributesToPerson(BaseScimResource resource, GluuCustomPerson person) {
    try {
        // Gets all the extended attributes for this resource
        Map<String, Object> extendedAttrs = resource.getCustomAttributes();
        // Iterates over all extensions this type of resource might have
        for (Extension extension : extService.getResourceExtensions(resource.getClass())) {
            Object val = extendedAttrs.get(extension.getUrn());
            if (val != null) {
                // Obtains the attribute/value(s) pairs in the current extension
                Map<String, Object> attrsMap = IntrospectUtil.strObjMap(val);
                for (String attribute : attrsMap.keySet()) {
                    Object value = attrsMap.get(attribute);
                    // Ignore if the attribute is unassigned in this resource: destination will not be changed in this regard
                    if (value != null) {
                        // Get properly formatted string representations for the value(s) associated to the attribute
                        List<String> values = extService.getStringAttributeValues(extension.getFields().get(attribute), value);
                        log.debug("transferExtendedAttributesToPerson. Setting attribute '{}' with values {}", attribute, values.toString());
                        person.setAttribute(attribute, values.toArray(new String[] {}));
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 33 with User

use of org.gluu.oxtrust.model.scim2.User in project Douya by DreaminginCodeZH.

the class NavigationHeaderLayout method bindRecentUser.

private void bindRecentUser(ImageView avatarImage, final Account account) {
    if (account == null) {
        avatarImage.setVisibility(GONE);
        return;
    }
    avatarImage.setVisibility(VISIBLE);
    User user = mAdapter.getUser(account);
    if (user != null) {
        bindAvatarImage(avatarImage, user.getLargeAvatarOrAvatar());
    } else {
        bindAvatarImage(avatarImage, null);
    }
    avatarImage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            switchToAccountWithTransitionIfNotRunning(account);
        }
    });
}
Also used : User(me.zhanghai.android.douya.network.api.info.apiv2.User) SimpleUser(me.zhanghai.android.douya.network.api.info.apiv2.SimpleUser) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView)

Example 34 with User

use of org.gluu.oxtrust.model.scim2.User in project Douya by DreaminginCodeZH.

the class NavigationHeaderLayout method bindActiveUser.

private void bindActiveUser() {
    mActiveAccount = AccountUtils.getActiveAccount();
    User user = mAdapter.getUser(mActiveAccount);
    if (user != null) {
        bindAvatarImage(mAvatarImage, user.getLargeAvatarOrAvatar());
        mNameText.setText(user.name);
        if (!TextUtils.isEmpty(user.signature)) {
            mDescriptionText.setText(user.signature);
        } else {
            //noinspection deprecation
            mDescriptionText.setText(user.uid);
        }
    } else {
        SimpleUser partialUser = mAdapter.getPartialUser(mActiveAccount);
        bindAvatarImage(mAvatarImage, null);
        mNameText.setText(partialUser.name);
        //noinspection deprecation
        mDescriptionText.setText(partialUser.uid);
    }
    mAvatarImage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mAccountTransitionRunning) {
                return;
            }
            if (mListener != null) {
                mListener.openProfile(mActiveAccount);
            }
        }
    });
//mBackdropImage.setImageResource();
}
Also used : User(me.zhanghai.android.douya.network.api.info.apiv2.User) SimpleUser(me.zhanghai.android.douya.network.api.info.apiv2.SimpleUser) SimpleUser(me.zhanghai.android.douya.network.api.info.apiv2.SimpleUser) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView)

Example 35 with User

use of org.gluu.oxtrust.model.scim2.User in project Douya by DreaminginCodeZH.

the class UserResource method get.

@Override
public User get() {
    User user = super.get();
    if (user == null) {
        // Can be called before onCreate() is called.
        ensureArguments();
        user = mExtraUser;
    }
    return user;
}
Also used : User(me.zhanghai.android.douya.network.api.info.apiv2.User) SimpleUser(me.zhanghai.android.douya.network.api.info.apiv2.SimpleUser)

Aggregations

GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)18 User (org.gluu.oxtrust.model.scim2.User)17 ArrayList (java.util.ArrayList)13 Response (javax.ws.rs.core.Response)13 DefaultValue (javax.ws.rs.DefaultValue)12 HeaderParam (javax.ws.rs.HeaderParam)12 Produces (javax.ws.rs.Produces)12 URI (java.net.URI)11 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)11 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)10 ScimPatchUser (org.gluu.oxtrust.model.scim2.ScimPatchUser)10 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)10 User (org.openstack4j.model.identity.v3.User)10 Date (java.util.Date)9 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)8 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)8 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)8 IOException (java.io.IOException)7 Map (java.util.Map)7 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7