org.usergrid.services.users.UsersService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of usergrid-services Show documentation
Show all versions of usergrid-services Show documentation
Service layer for Usergrid system.
/*******************************************************************************
* Copyright 2012 Apigee Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.usergrid.services.users;
import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
import static org.apache.commons.lang.StringUtils.isBlank;
import static org.apache.commons.lang.StringUtils.isNotBlank;
import static org.usergrid.persistence.Schema.PROPERTY_EMAIL;
import static org.usergrid.persistence.Schema.PROPERTY_PICTURE;
import static org.usergrid.services.ServiceResults.genericServiceResults;
import static org.usergrid.utils.ConversionUtils.string;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.usergrid.management.UserInfo;
import org.usergrid.persistence.Entity;
import org.usergrid.persistence.EntityRef;
import org.usergrid.persistence.Identifier;
import org.usergrid.persistence.Query;
import org.usergrid.persistence.Results;
import org.usergrid.persistence.Schema;
import org.usergrid.persistence.entities.Role;
import org.usergrid.security.shiro.utils.SubjectUtils;
import org.usergrid.services.AbstractCollectionService;
import org.usergrid.services.ServiceContext;
import org.usergrid.services.ServicePayload;
import org.usergrid.services.ServiceRequest;
import org.usergrid.services.ServiceResults;
import org.usergrid.services.exceptions.ServiceResourceNotFoundException;
public class UsersService extends AbstractCollectionService {
private static final Logger logger = LoggerFactory
.getLogger(UsersService.class);
public UsersService() {
super();
logger.info("/users");
makeConnectionPrivate("following");
declareVirtualCollections(Arrays.asList("following", "followers"));
addReplaceParameters(Arrays.asList("$id", "followers"),
Arrays.asList("\\0", "connecting", "following"));
declareEntityDictionaries(Arrays.asList("rolenames", "permissions"));
}
@Override
public ServiceResults getItemByName(ServiceContext context, String name) throws Exception {
String nameProperty = Schema.getDefaultSchema().aliasProperty(
getEntityType());
if (nameProperty == null) {
nameProperty = "name";
}
EntityRef entity = null;
Identifier id = Identifier.from(name);
if ( id != null ) {
entity = em.getUserByIdentifier(id);
}
if (entity == null) {
logger.info("miss on entityType: {} with name: {}", getEntityType(), name);
throw new ServiceResourceNotFoundException(context);
}
if (!context.moreParameters()) {
entity = em.get(entity);
entity = importEntity(context, (Entity) entity);
}
checkPermissionsForEntity(context, entity);
List nextRequests = context
.getNextServiceRequests(entity);
return new ServiceResults(this, context, ServiceResults.Type.COLLECTION,
Results.fromRef(entity), null, nextRequests);
}
@Override
public ServiceResults invokeItemWithName(ServiceContext context, String name)
throws Exception {
if ("me".equals(name)) {
UserInfo user = SubjectUtils.getUser();
if ((user != null) && (user.getUuid() != null)) {
return super.invokeItemWithId(context, user.getUuid());
}
}
return super.invokeItemWithName(context, name);
}
@Override
public ServiceResults postCollection(ServiceContext context)
throws Exception {
Iterator
© 2015 - 2024 Weber Informatics LLC | Privacy Policy