/*
 * Copyright 2013 - 2013 Cole Wen
 *
 * 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.maodian.flyingcat.im.template;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.maodian.flyingcat.im.Type;
import org.maodian.flyingcat.im.Verb;
import org.springframework.stereotype.Component;

/**
 * @author Cole Wen
 *
 */
@Component
@Domain(Type.SESSION)
public class SessionTemplate extends AbstractTemplate {

  @Operation(Verb.CREATE)
  public void login(UsernamePasswordToken token) {
    SecurityUtils.getSubject().login(token);
  }
}

@@ -636,16 +636,56 @@
 plate;%0A%0A
+import java.lang.invoke.MethodHandles;%0A%0A
 import o
@@ -749,105 +749,305 @@
 thc.
-UsernamePasswordToken;%0Aimport org.maodian.flyingcat.im.Type;%0Aimport org.maodian.flyingcat.im.Verb
+AuthenticationException;%0Aimport org.apache.shiro.authc.UsernamePasswordToken;%0Aimport org.maodian.flyingcat.im.IMException;%0Aimport org.maodian.flyingcat.im.Type;%0Aimport org.maodian.flyingcat.im.UserError;%0Aimport org.maodian.flyingcat.im.Verb;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory
 ;%0Aim
@@ -1214,16 +1214,117 @@
 plate %7B%0A
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());%0A  
 %0A  @Oper
@@ -1393,16 +1393,28 @@
 oken) %7B%0A
+    try %7B%0A  
     Secu
@@ -1450,14 +1450,190 @@
 token);%0A
+    %7D catch (AuthenticationException e) %7B%0A      log.warn(%22User %5B%7B%7D%5D login failed%22, token.getPrincipal());%0A      throw IMException.wrap(e, UserError.AUTHENTICATED_FAILS);%0A    %7D%0A
   %7D%0A%7D%0A

throw IMException when login fail