use of org.apache.shiro.subject.Subject in project bamboobsc by billchen198318.
the class WsAuthenticateUtils method login.
public static Subject login() throws Exception {
ShiroLoginSupport loginSupport = new ShiroLoginSupport();
Subject subject = loginSupport.forceCreateLoginSubject(getDefaultUser());
return subject;
}
use of org.apache.shiro.subject.Subject in project bamboobsc by billchen198318.
the class ShiroLoginSupport method forceCreateLoginSubject.
public Subject forceCreateLoginSubject(HttpServletRequest request, HttpServletResponse response, String accountId, String captchaStr) throws Exception {
AccountVO account = this.queryUser(accountId);
if (account == null) {
logger.warn("no accountId: " + accountId);
throw new Exception("no accountId: " + accountId);
}
request.getSession().setAttribute(GreenStepBaseFormAuthenticationFilter.DEFAULT_CAPTCHA_PARAM, captchaStr);
GreenStepBaseUsernamePasswordToken token = new GreenStepBaseUsernamePasswordToken();
token.setCaptcha(captchaStr);
token.setUsername(account.getAccount());
token.setPassword(account.getPassword().toCharArray());
Subject subject = this.getSubject(request, response);
subject.login(token);
return subject;
}
use of org.apache.shiro.subject.Subject in project bamboobsc by billchen198318.
the class ShiroLoginSupport method forceCreateLoginSubject.
public Subject forceCreateLoginSubject(String accountId) throws Exception {
AccountVO account = this.queryUser(accountId);
if (account == null) {
logger.warn("no accountId: " + accountId);
throw new Exception("no accountId: " + accountId);
}
Subject subject = SecurityUtils.getSubject();
GreenStepBaseUsernamePasswordToken token = new GreenStepBaseUsernamePasswordToken();
token.setCaptcha("0123");
token.setUsername(account.getAccount());
token.setPassword(account.getPassword().toCharArray());
subject.login(token);
return subject;
}
use of org.apache.shiro.subject.Subject in project bamboobsc by billchen198318.
the class SubjectBuilderForBackground method login.
public static void login() throws Exception {
Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
org.apache.shiro.mgt.SecurityManager securityManager = (org.apache.shiro.mgt.SecurityManager) factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
Subject currentUser = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(Constants.SYSTEM_BACKGROUND_USER, Constants.SYSTEM_BACKGROUND_PASSWORD);
currentUser.login(token);
//System.out.println(currentUser.hasRole("admin"));
//System.out.println(currentUser.hasRole("*"));
}
use of org.apache.shiro.subject.Subject in project bamboobsc by billchen198318.
the class ApiWebServiceImpl method getScorecard2.
@WebMethod
@GET
@Path("/scorecard2/")
@Override
public BscApiServiceResponse getScorecard2(@WebParam(name = "visionId") @QueryParam("visionId") String visionId, @WebParam(name = "startDate") @QueryParam("startDate") String startDate, @WebParam(name = "endDate") @QueryParam("endDate") String endDate, @WebParam(name = "startYearDate") @QueryParam("startYearDate") String startYearDate, @WebParam(name = "endYearDate") @QueryParam("endYearDate") String endYearDate, @WebParam(name = "frequency") @QueryParam("frequency") String frequency, @WebParam(name = "dataFor") @QueryParam("dataFor") String dataFor, @WebParam(name = "measureDataOrganizationId") @QueryParam("measureDataOrganizationId") String measureDataOrganizationId, @WebParam(name = "measureDataEmployeeId") @QueryParam("measureDataEmployeeId") String measureDataEmployeeId, @WebParam(name = "contentFlag") @QueryParam("contentFlag") String contentFlag) throws Exception {
HttpServletRequest request = null;
if (this.getWebServiceContext() != null && this.getWebServiceContext().getMessageContext() != null) {
request = (HttpServletRequest) this.getWebServiceContext().getMessageContext().get(MessageContext.SERVLET_REQUEST);
}
Subject subject = null;
BscApiServiceResponse responseObj = new BscApiServiceResponse();
responseObj.setSuccess(YesNo.NO);
try {
subject = WsAuthenticateUtils.login();
@SuppressWarnings("unchecked") IVisionService<VisionVO, BbVision, String> visionService = (IVisionService<VisionVO, BbVision, String>) AppContext.getBean("bsc.service.VisionService");
@SuppressWarnings("unchecked") IEmployeeService<EmployeeVO, BbEmployee, String> employeeService = (IEmployeeService<EmployeeVO, BbEmployee, String>) AppContext.getBean("bsc.service.EmployeeService");
@SuppressWarnings("unchecked") IOrganizationService<OrganizationVO, BbOrganization, String> organizationService = (IOrganizationService<OrganizationVO, BbOrganization, String>) AppContext.getBean("bsc.service.OrganizationService");
String visionOid = "";
String measureDataOrganizationOid = "";
String measureDataEmployeeOid = "";
DefaultResult<VisionVO> visionResult = visionService.findForSimpleByVisId(visionId);
if (visionResult.getValue() == null) {
throw new Exception(visionResult.getSystemMessage().getValue());
}
visionOid = visionResult.getValue().getOid();
if (StringUtils.isBlank(measureDataOrganizationId)) {
measureDataOrganizationOid = BscBaseLogicServiceCommonSupport.findEmployeeDataByEmpId(employeeService, measureDataOrganizationId).getOid();
}
if (StringUtils.isBlank(measureDataEmployeeId)) {
measureDataEmployeeOid = BscBaseLogicServiceCommonSupport.findOrganizationDataByUK(organizationService, measureDataEmployeeId).getOid();
}
this.processForScorecard(responseObj, request, visionOid, startDate, endDate, startYearDate, endYearDate, frequency, dataFor, measureDataOrganizationOid, measureDataEmployeeOid, contentFlag);
} catch (Exception e) {
responseObj.setMessage(e.getMessage());
} finally {
if (!YesNo.YES.equals(responseObj.getSuccess())) {
responseObj.setMessage(SysMessageUtil.get(GreenStepSysMsgConstants.SEARCH_NO_DATA));
}
WsAuthenticateUtils.logout(subject);
}
subject = null;
return responseObj;
}
Aggregations