1 16 package org.jmanage.cmdui; 17 18 import org.jmanage.core.services.ServiceContext; 19 import org.jmanage.core.services.ServiceContextImpl; 20 import org.jmanage.core.auth.User; 21 22 27 public class HandlerContext { 28 29 private final Command command; 30 private final ServiceContextImpl serviceContext; 31 32 HandlerContext(Command command){ 33 this(command, true); 34 } 35 36 HandlerContext(Command command, boolean isAuthRequired){ 37 this.command = command; 38 this.serviceContext = getServiceContext(command, isAuthRequired); 39 } 40 41 public Command getCommand(){ 42 return command; 43 } 44 45 public ServiceContext getServiceContext(){ 46 return serviceContext; 47 } 48 49 public ServiceContext getServiceContext(String appName){ 50 assert appName != null; 51 ServiceContextImpl serviceContext = getServiceContext(command, true); 52 serviceContext.setApplicationName(appName); 53 return serviceContext; 54 } 55 56 public ServiceContext getServiceContext(String appName, String mbeanName) { 57 assert mbeanName != null; 58 ServiceContextImpl serviceContext = 59 (ServiceContextImpl)getServiceContext(appName); 60 serviceContext.setMBeanName(mbeanName); 61 return serviceContext; 62 } 63 64 private static ServiceContextImpl getServiceContext(Command command, 65 boolean isAuthRequired){ 66 ServiceContextImpl context = new ServiceContextImpl(); 67 if(isAuthRequired){ 68 assert command.getUsername() != null; 69 assert command.getPassword() != null; 70 User user = new User(command.getUsername(), 71 null, null, null, 0); 72 user.setPlaintextPassword(command.getPassword()); 73 context.setUser(user); 74 } 75 return context; 76 } 77 } 78 | Popular Tags |