Search in sources :

Example 16 with Permission

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;
}
Also used : Permission(com.willshex.blogwt.shared.api.datatype.Permission) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 17 with Permission

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);
}
Also used : Permission(com.willshex.blogwt.shared.api.datatype.Permission) AuthorisationException(com.willshex.blogwt.server.api.exception.AuthorisationException)

Example 18 with Permission

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;
}
Also used : Role(com.willshex.blogwt.shared.api.datatype.Role) Permission(com.willshex.blogwt.shared.api.datatype.Permission) Document(com.google.appengine.api.search.Document) ScoredDocument(com.google.appengine.api.search.ScoredDocument)

Aggregations

Permission (com.willshex.blogwt.shared.api.datatype.Permission)18 Role (com.willshex.blogwt.shared.api.datatype.Role)8 User (com.willshex.blogwt.shared.api.datatype.User)5 ArrayList (java.util.ArrayList)5 JsonElement (com.google.gson.JsonElement)4 Date (java.util.Date)4 InputValidationException (com.willshex.gson.web.service.server.InputValidationException)3 Key (com.googlecode.objectify.Key)2 AuthorisationException (com.willshex.blogwt.server.api.exception.AuthorisationException)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 Document (com.google.appengine.api.search.Document)1 ScoredDocument (com.google.appengine.api.search.ScoredDocument)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 GetPostsActionHandler (com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler)1 IPropertyService (com.willshex.blogwt.server.service.property.IPropertyService)1 Pager (com.willshex.blogwt.shared.api.Pager)1 GetPostsRequest (com.willshex.blogwt.shared.api.blog.call.GetPostsRequest)1 GeneratedDownload (com.willshex.blogwt.shared.api.datatype.GeneratedDownload)1 MetaNotification (com.willshex.blogwt.shared.api.datatype.MetaNotification)1