Package org.internna.iwebmvc.spring.mvc.controllers.security

Source Code of org.internna.iwebmvc.spring.mvc.controllers.security.SecurityController

/*
* Copyright 2002-2007 the original author or authors.
*
* 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.internna.iwebmvc.spring.mvc.controllers.security;

import java.util.Set;
import org.internna.iwebmvc.core.context.ContextHolder;
import org.internna.iwebmvc.core.dao.DAO;
import org.internna.iwebmvc.core.dao.SecurityDAO;
import org.internna.iwebmvc.model.core.Locale;
import org.internna.iwebmvc.model.security.UserImpl;
import org.internna.iwebmvc.spring.binding.AuthoritiesBinder;
import org.internna.iwebmvc.spring.binding.LocaleBinder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;

/**
* Administers User entity
*
* @author Jose Noheda
* @since 1.0
*/
@Controller
@SessionAttributes("newuser")
@RequestMapping("/security/users.iwebmvc")
public class SecurityController {

    @Autowired @Qualifier("persistenceFacade") protected DAO dao;
    @Autowired protected SecurityDAO securityDao;
    @Autowired protected ContextHolder holder;

    @RequestMapping(method = RequestMethod.GET)
    public String showForm(@RequestParam(required = false, value = "username") String username, ModelMap model) {
        model.addAttribute("newuser", username == null ? new UserImpl() : securityDao.findUser(username));
        model.addAttribute("authorities", holder.getAuthorities());
        model.addAttribute("availableLocales", holder.getAvailableLocales());
        return "security/template";
    }

    @InitBinder
    protected void initBinder(WebDataBinder binder) {
        binder.registerCustomEditor(Locale.class, new LocaleBinder(dao));
        binder.registerCustomEditor(Set.class, new AuthoritiesBinder(securityDao));
    }

    @RequestMapping(method = RequestMethod.POST)
    public String onSubmit(@ModelAttribute("newuser") UserImpl user, SessionStatus status) {
        securityDao.createUser(user);
        status.setComplete();
        return "security/template_search";
    }

}
TOP

Related Classes of org.internna.iwebmvc.spring.mvc.controllers.security.SecurityController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.