/*
 * Copyright 2006 Wyona
 *
 *  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.wyona.org/licenses/APACHE-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.wyona.yanel.impl.resources;

import org.apache.log4j.Category;
import org.wyona.security.core.api.AccessManagementException;
import org.wyona.security.core.api.User;
import org.wyona.security.core.api.UserManager;
import org.wyona.yanel.impl.resources.usecase.ExecutableUsecaseResource;
import org.wyona.yanel.impl.resources.usecase.UsecaseException;

/**
 *
 */
public class DeleteUserResource extends ExecutableUsecaseResource {

    private static Category log = Category.getInstance(DeleteUserResource.class);
    
    private static final String PARAM_USER_ID = "userID";

    public void execute() throws UsecaseException {
        try {
            String id = getParameterAsString(PARAM_USER_ID);
            if (log.isDebugEnabled()) {
                log.debug("deleting user: " + id);
            }
            UserManager userManager = getRealm().getIdentityManager().getUserManager();
            userManager.removeUser(id);
            addInfoMessage("User " + id + " deleted successfully.");
            log.warn("TODO: Delete access policy!"); // Also see CreateUserResource
        } catch (AccessManagementException e) {
            log.error(e, e);
            throw new UsecaseException(e.getMessage(), e);
        }
    }
    
    public User getUser() throws AccessManagementException {
        String id = getParameterAsString(PARAM_USER_ID);
        UserManager userManager = getRealm().getIdentityManager().getUserManager();
        User user = userManager.getUser(id);
        return user;
    }

}

@@ -664,20 +664,71 @@
 .log
-4j.Category;
+ging.log4j.Logger;%0Aimport org.apache.logging.log4j.LogManager;%0A
 %0Aimp
@@ -1116,43 +1116,41 @@
 tic 
-Category log = Category.getInstance
+Logger log = LogManager.getLogger
 (Del
@@ -1666,16 +1666,17 @@
 lly.%22);%0A
+%0A
         
@@ -1683,79 +1683,42 @@
     
-log.warn(%22TODO: Delete a
+deleteUserProfileA
 ccess
- p
+P
 olicy
-!%22); // Also see CreateUserResource
+(id);
 %0A   
@@ -1863,19 +1863,634 @@
    %7D
-%0A    %7D%0A    
+ catch (Exception e) %7B%0A            log.error(e, e);%0A            throw new UsecaseException(e.getMessage(), e);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Delete user profile access policy%0A     * @param id User ID%0A     */%0A    private void deleteUserProfileAccessPolicy(String id) throws Exception %7B%0A        org.wyona.security.core.api.PolicyManager policyManager = getRealm().getPolicyManager();%0A        // TODO: Replace %22/users%22 by org.wyona.yanel.servlet.YanelGlobalResourceTypeMatcher#usersPathPrefix%0A        policyManager.removePolicy(%22/%22 + getYanel().getReservedPrefix() + %22/users/%22 + id + %22.html%22);%0A    %7D%0A    %0A    /**%0A     *%0A     */
 %0A   
@@ -2760,11 +2760,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

delete user profile