use of com.willshex.blogwt.shared.api.datatype.Permission in project blogwt by billy1380.
the class PermissionValidator method lookup.
public static Permission lookup(Permission permission, String name) throws InputValidationException {
if (permission == null)
ApiValidator.throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
boolean isIdLookup = false, isCodeLookup = false, isNameLookup = false;
if (permission.id != null) {
isIdLookup = true;
} else if (permission.code != null) {
isCodeLookup = true;
}
if (!(isIdLookup || isNameLookup || isCodeLookup))
ApiValidator.throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
Permission lookupPermission = null;
if (isIdLookup) {
lookupPermission = PermissionServiceProvider.provide().getPermission(permission.id);
} else if (isCodeLookup) {
lookupPermission = PermissionServiceProvider.provide().getCodePermission(permission.code);
}
if (lookupPermission == null)
ApiValidator.throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
return lookupPermission;
}
use of com.willshex.blogwt.shared.api.datatype.Permission in project blogwt by billy1380.
the class UserValidator method authorisation.
public static void authorisation(User user, Collection<Permission> requiredPermissions, String name) throws AuthorisationException {
boolean authorised = isAdmin(user);
List<Permission> permissions = user.permissions == null && user.permissionKeys != null ? PersistenceHelper.batchLookup(PermissionServiceProvider.provide(), user.permissionKeys) : user.permissions;
if (!authorised && user != null && permissions != null) {
if (requiredPermissions != null && requiredPermissions.size() > 0) {
Map<String, Permission> lookup = PermissionHelper.toLookup(permissions);
for (Permission permission : requiredPermissions) {
if (permission.code != null && lookup.containsKey(permission.code)) {
authorised = true;
break;
}
}
}
}
if (!authorised)
throw new AuthorisationException(user, permissions, name);
}
use of com.willshex.blogwt.shared.api.datatype.Permission in project blogwt by billy1380.
the class UserService method toDocument.
/* (non-Javadoc)
*
* @see
* com.willshex.blogwt.server.service.search.IIndex#toDocument(java.lang.
* Object) */
@Override
public Document toDocument(User user) {
Document document = null;
if (user != null) {
Document.Builder documentBuilder = Document.newBuilder();
documentBuilder.setId(getName() + user.id.toString()).addField(Field.newBuilder().setName("username").setAtom(user.username)).addField(Field.newBuilder().setName("name").setText(UserHelper.name(user))).addField(Field.newBuilder().setName("forename").setText(user.forename)).addField(Field.newBuilder().setName("surname").setText(user.surname)).addField(Field.newBuilder().setName("email").setText(user.email)).addField(Field.newBuilder().setName("created").setDate(user.created)).addField(Field.newBuilder().setName("group").setText(user.group)).addField(Field.newBuilder().setName("summary").setText(user.summary));
if (user.roles != null) {
for (Role role : user.roles) {
documentBuilder.addField(Field.newBuilder().setName("role").setText(role.name));
}
}
if (user.permissions != null) {
for (Permission permission : user.permissions) {
documentBuilder.addField(Field.newBuilder().setName("permission").setText(permission.name));
}
}
document = documentBuilder.build();
}
return document;
}
Aggregations