Package es.ipsa.atril.sec.authentication

Examples of es.ipsa.atril.sec.authentication.AtrilSession


      return oRes;
    } else {
      final String sNickName = oBab.getSessionAttribute("nickname");
      final String sPassword = oBab.getSessionAttribute("password");
      final String sTaxPayer = oBab.getSessionAttribute("taxpayer_docid");
      AtrilSession oSes = null;
      if (sNickName==null || sPassword==null || sTaxPayer==null) {
        oRes = new RedirectResolution("/enter.jsp?e=expiredsession");
        ((RedirectResolution) oRes).addParameter("lastUrl" , oBab.getLastUrl());       
      } else {
        if (!oCredentials.contains(sNickName+sPassword)) {
          try {
            oSes = DAO.getSession("LoginInterceptor", sNickName, sPassword);
            try {
              User oUsr = new User(oSes, User.forUuid(sNickName));
              if (!oUsr.isActive()) {
                oRes = resolve(oCls, "deactivated", oBab.getLastUrl());
              } else {
                if (CHKTXP.contains(oCls) && !oActive.contains(sTaxPayer)) {
                  TaxPayer oTxp = new TaxPayer(oSes.getDms(), sTaxPayer);
                  if (oTxp.getRequiresActivation()) {
                    oRes = new RedirectResolution(ActivateTaxPayer.class);
                  } else {
                    oActive.add(sTaxPayer);
                  }
                }
                oCredentials.add(sNickName+sPassword);
              }
            } catch (ElementNotFoundException enfe) {
              Log.out.error("ElementNotFoundException "+enfe.getMessage(), enfe);
              oRes = resolve(oCls, "userdatanotfound", oBab.getLastUrl());
            }
          } catch (Exception xcpt) {
            Log.out.error(xcpt.getClass().getName()+" "+xcpt.getMessage(), xcpt);
            oRes = resolve(oCls, "systemsecurity", oBab.getLastUrl());
          } finally {
            if (null!=oSes) {
              if (oSes.isConnected()) oSes.disconnect();
              if (oSes.isOpen()) oSes.close();
            } // fi
          }         
        } else if (oBab.getSessionAttribute("businessname").length()==32) {
          if (CHKTXP.contains(oCls)) {
            oSes = DAO.getSession("LoginInterceptor", sNickName, sPassword);
            TaxPayer oTxp = new TaxPayer(oSes.getDms(), sTaxPayer);
            oBab.setSessionAttribute("businessname", oTxp.getBusinessName());
            if (oTxp.getRequiresActivation()) {
              oRes = new RedirectResolution(ActivateTaxPayer.class);
            } else if (!oActive.contains(sTaxPayer)) {
              oActive.add(sTaxPayer);
            }
            oSes.disconnect();
            oSes.close();           
          }
        }
      } // fi
    }
    return oRes;
View Full Code Here


      else
        aAmountRange = new BigDecimal[]{null,new BigDecimal(sAmountTo)};
      
      try {
        connect(sNickN, sPassw);
        AtrilSession oSes = getSession();
        Dms oDms = oSes.getDms();
        if (sDocId.length()>0) {
          aLst = new QueryResultSet<Invoice>();
          aLst.add(new Invoice(oDms, sDocId));
        } else {
          TaxPayer oTxpr = new TaxPayer(oDms, sTaxPayer);
View Full Code Here

    return forTaxId(sTaxId, "Client");
  }

  private void loadCountryAndStateNames() throws IllegalStateException {
    if (!isNull("country")) {
      AtrilSession oSes = DAO.getAdminSession("Client");
      oCntr = new Countries().getCountry(oSes, getCountry());
      if (!isNull("state"))
        oStat = oCntr.states(oSes).getState(oSes, getState());
      else
        oStat = null;
      oSes.disconnect();
      oSes.close();
    } else {
      oCntr = null;
      oStat = null;
    }
   
View Full Code Here

  public Client convert(String sClientId, Class<? extends Client> clientClass,
              Collection<ValidationError> conversionErrors) {
    if (sClientId==null) return null;
    if (sClientId.length()==0) return null;
    try {
      AtrilSession oSes = DAO.getAdminSession("Client");
      Client oClnt = new Client(oSes.getDms(), sClientId);
      oSes.disconnect();
      oSes.close();
      oSes = null;
      if (null==oClnt) {
        Log.out.error("No client with id "+sClientId+" was found");
        conversionErrors.add(new SimpleError("No client with id "+sClientId+" was found"));
      }
View Full Code Here

    }

    public void run() {
      final float MaxWidth = 512f;
      final float MaxHeight = 640f;
      AtrilSession oSes = null;
      StreamPipe oPipe;
      try {
        oSes = DAO.getAdminSession("ThumbnailCreator");
        oSes.autoCommit(true);
        Dms oDms = oSes.getDms();
        Document oDoc = oDms.getDocument(sParent);
        Item oItm = oDms.getDocument(sItem).item();
        String sFileName = oItm.name().toLowerCase();
        oPipe = new StreamPipe();
        ByteArrayOutputStream oByOut = new ByteArrayOutputStream();
        if (sFileName.endsWith(".pdf")) {
          Log.out.debug("Item.getInputStreamTranscodedToMime(image/jpeg)");
          oPipe.between(oItm.getInputStreamTranscodedToMime("image/jpeg"), oByOut);
        } else {
            Log.out.debug("Item.getInputStream()");
            oPipe.between(oItm.getInputStream(), oByOut);         
        }
        byte[] aBytes = oByOut.toByteArray();
        oByOut.close();
        oByOut = null;
        Log.out.debug("new Picture()");
        Picture oPic = new Picture();
        Log.out.debug("Before Picture.dimensions()");
        int[] aWidthHeight = oPic.dimensions(aBytes, "jpeg");
        Log.out.debug("After Picture.dimensions()");
        if (null==aWidthHeight)
          throw new NullPointerException("Unable to get dimensions for image "+oItm.name());
        Log.out.debug("Image width="+String.valueOf(aWidthHeight[0])+" height="+String.valueOf(aWidthHeight[1]));
        int iWidth, iHeight;
        if (aWidthHeight[0]<=MaxWidth && aWidthHeight[0]<=MaxHeight) {
          iWidth = aWidthHeight[0];
          iHeight = aWidthHeight[1];
        } else {
          float fWidthRatio = ((float) aWidthHeight[0]) / MaxWidth;
          float fHeightRatio = ((float) aWidthHeight[1]) / MaxHeight;
          if (fWidthRatio>fHeightRatio) {
            iWidth = (int) MaxWidth;
            iHeight = (int) (MaxWidth*aWidthHeight[1])/aWidthHeight[0];
          } else {
            iWidth = (int) (aWidthHeight[0]*MaxHeight)/aWidthHeight[1];
            iHeight = (int) MaxHeight;
          }
        }
        Log.out.debug("Resampled width="+String.valueOf(iWidth)+" height="+String.valueOf(iHeight));
        String sCodec = null;
        if (sFileName.endsWith(".jpg") || sFileName.endsWith(".jpeg") || sFileName.endsWith(".pdf"))
          sCodec = "jpeg";
        else if (sFileName.endsWith(".gif"))
          sCodec = "gif";
        else if (sFileName.endsWith(".tif") || sFileName.endsWith(".tiff"))
          sCodec = "tiff";
        else {
          Log.out.error("ThumbnailCreator.run()  Could not find suitable codec for file "+oItm.name());
          throw new InstantiationException("Could not find suitable codec for file "+oItm.name());
        }
        Log.out.debug("Picture.createThumbBitmap("+sCodec+","+String.valueOf(iWidth)+","+String.valueOf(iHeight)+",80)");
        byte[] byThumb = oPic.createThumbBitmap(aBytes, sCodec, iWidth, iHeight, 80);
       
        Document oThl = oDms.newDocument(oDms.getDocumentType(oDoc.type().name()+"Thumbnail"), oDoc);
        AttributeMultiValue oAtr = oThl.attribute("width");
      oAtr.set((long) iWidth);
      oAtr = oThl.attribute("height");
      oAtr.set((long) iHeight);
      oThl.save("");
        Item oThi = oThl.item();
        String sItemName = "th"+oDoc.id()+".jpg";
        oThi.setName(sItemName);
        oThi.mimeType("image/jpeg");
        OutputStream oOutStrm = oThi.getOutputStream();
        oPipe = new StreamPipe();
        oPipe.between(new ByteArrayInputStream(byThumb), oOutStrm);
        oThl.save("");
        oOutStrm.close();
        Log.out.debug("Thumbnail creation done");
        DAO.log(oSes, oThl, Class.forName("com.zesped.model."+oDoc.type().name()+"Thumbnail"), "INSERT THUMBNAIL", AtrilEvent.Level.INFO, sItemName);
        oSes.disconnect();
        oSes.close();
        oSes=null;
      } catch (Exception e) {
        Log.out.error("ThumbnailCreator.run() "+e.getClass().getName()+" "+e.getMessage(), e);
      } finally {
        if (oSes!=null) {
          if (oSes.isConnected()) oSes.disconnect();
          if (oSes.isOpen()) oSes.close();
        }
      }
    Log.out.debug("End ThumbnailCreator.run()");
    }
View Full Code Here

  public AsyncAccountCreator(User u) {
    oUsr = u;
  }

  public void run() {
    AtrilSession oSes = null;
    try {
      oSes = DAO.getAdminSession("AsyncAccountCreator");
      final String sTemporaryBusinessName = Gadgets.generateUUID();     
      CustomerAccount oCac = CustomerAccount.create(oSes, oUsr, sTemporaryBusinessName);
      oSes.commit();
      TaxPayer oTxp = TaxPayer.create(oSes, oCac, sTemporaryBusinessName, "", oUsr.getFirstName()+" "+oUsr.getLastName(), oUsr.getEmail(), true, DAO.getVolumesMountBase());
      oSes.commit();
      Employee oEmp = new Employee(oSes, oTxp.employees(oSes));
      oEmp.setActive(true);
      oEmp.setUuid(oUsr.getNickName());
      oEmp.setName(oUsr.getFirstName()+" "+oUsr.getLastName());
      oEmp.save(oSes);
      oSes.commit();
      oSes.disconnect();
      oSes.close();
      oSes=null;
    } catch (Exception xcpt) {
      Log.out.error("AsyncAccountCreator.run() "+xcpt.getClass().getName()+" "+xcpt.getMessage(), xcpt);
    } finally {
      if (oSes!=null) {
        if (oSes.isConnected()) oSes.disconnect();
        if (oSes.isOpen()) oSes.close();
      }
    }
  }
View Full Code Here

  public void run() {
    FileSystem oFs = new FileSystem();
    HttpRequest oReq;
   
    try {
      AtrilSession oSes = DAO.getAdminSession("AsyncAccountCache");
      User oUsr = new User(oSes, User.forUuid(sUsrNick));
      oSes.disconnect();
      oSes.close();

      oReq = new HttpRequest(sBaseUrl+"login.jsp", null, "post",
                   new NameValuePair[]{new NameValuePair("email", oUsr.getEmail()),
                                   new NameValuePair("passw", sUsrPwd),
                                   new NameValuePair("format", "session")});
View Full Code Here

 
  @BeforeClass public static void init() throws Exception {
    ModelManager oMan = new ModelManager();   
    oDao = new DAO();
    oDao.init(oMan.getConnectionProperties());
    AtrilSession oSes = DAO.getAdminSession("SmokeTest");
    oSes.autoCommit(true);   
    try {
      USRID = User.forEmail(TEST_USER_EMAIL);
    } catch (ElementNotFoundException notfound) {
      User oUsr = new User();
      oUsr.setEmail(TEST_USER_EMAIL);
      oUsr.setFirstName("Default Test User First Name");
      oUsr.setLastName("Default Test User Last Name");
      oUsr.setPassword("12345678");
      oUsr.create(oSes);
      USRID = oUsr.id();
    }
    try {
      ACCID = CustomerAccount.forBusinessName(TEST_BUSINESSNAME);
    } catch (ElementNotFoundException notfound) {   
      ACCID = CustomerAccount.create(oSes, new User(oSes, USRID), TEST_BUSINESSNAME).id();   
    }
   
    CustomerAccount oAcc = new CustomerAccount(oSes.getDms(), ACCID);
    if (oAcc.taxpayers(oSes).list(oSes).size()==0)
      TaxPayer.create(oSes, oAcc, TEST_BUSINESSNAME+" tax payer", "John Smith", "johnj@junittesting.com", null);

    oSes.disconnect();
    oSes.close();
    }
View Full Code Here

  }

  //-----------------------------------------------------------
 
  protected AtrilSession openTestSession() {
    AtrilSession oSes = DAO.getAdminSession("SmokeTest");
    oSes.autoCommit(true);
    return oSes;
  }
View Full Code Here

  //-----------------------------------------------------------
 
  @Test public void createUser()
    throws IllegalArgumentException,AuthorizationManagerAdminException,DuplicatedElementException,ElementNotFoundException,NotEnoughRightsException {
      AtrilSession oSes = openTestSession();
      User oUsr = new User();
      oUsr.setEmail(generateRandomId(6, null,Character.LOWERCASE_LETTER)+"@"+generateRandomId(6, null,Character.LOWERCASE_LETTER)+".com");
      oUsr.setFirstName("Test First Name "+generateRandomId(6, null,Character.UPPERCASE_LETTER));
      oUsr.setLastName("Test Last Name "+generateRandomId(6, null,Character.UPPERCASE_LETTER));
      oUsr.setPassword("12345678");
View Full Code Here

TOP

Related Classes of es.ipsa.atril.sec.authentication.AtrilSession

Copyright © 2018 www.massapicom. 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.