Search in sources :

Example 61 with Subject

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;
}
Also used : Subject(org.apache.shiro.subject.Subject)

Example 62 with 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;
}
Also used : AccountVO(com.netsteadfast.greenstep.vo.AccountVO) Subject(org.apache.shiro.subject.Subject)

Example 63 with 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;
}
Also used : AccountVO(com.netsteadfast.greenstep.vo.AccountVO) Subject(org.apache.shiro.subject.Subject)

Example 64 with 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("*"));
}
Also used : IniSecurityManagerFactory(org.apache.shiro.config.IniSecurityManagerFactory) Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Example 65 with Subject

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;
}
Also used : IVisionService(com.netsteadfast.greenstep.bsc.service.IVisionService) IOrganizationService(com.netsteadfast.greenstep.bsc.service.IOrganizationService) BbVision(com.netsteadfast.greenstep.po.hbm.BbVision) OrganizationVO(com.netsteadfast.greenstep.vo.OrganizationVO) VisionVO(com.netsteadfast.greenstep.vo.VisionVO) Subject(org.apache.shiro.subject.Subject) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) HttpServletRequest(javax.servlet.http.HttpServletRequest) BbEmployee(com.netsteadfast.greenstep.po.hbm.BbEmployee) EmployeeVO(com.netsteadfast.greenstep.vo.EmployeeVO) BscApiServiceResponse(com.netsteadfast.greenstep.bsc.vo.BscApiServiceResponse) BbOrganization(com.netsteadfast.greenstep.po.hbm.BbOrganization) IEmployeeService(com.netsteadfast.greenstep.bsc.service.IEmployeeService) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

Subject (org.apache.shiro.subject.Subject)78 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)11 Test (org.junit.Test)9 IOException (java.io.IOException)8 Map (java.util.Map)8 Path (javax.ws.rs.Path)8 StopProcessingException (ddf.catalog.plugin.StopProcessingException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 AccountVO (com.netsteadfast.greenstep.vo.AccountVO)5 Attribute (ddf.catalog.data.Attribute)5 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)5 GET (javax.ws.rs.GET)5 AuthenticationException (org.apache.shiro.authc.AuthenticationException)5 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)4 Metacard (ddf.catalog.data.Metacard)4 ApiOperation (io.swagger.annotations.ApiOperation)4 POST (javax.ws.rs.POST)4 PersistenceException (org.codice.ddf.persistence.PersistenceException)4