List of usage examples for java.text DateFormat MEDIUM
int MEDIUM
To view the source code for java.text DateFormat MEDIUM.
Click Source Link
From source file:org.openehealth.pors.core.PorsCoreBean.java
/** * @see IPorsCore#assembleLoggingEntryDTO(UserHistory) *//*from w w w . jav a2s . com*/ public LoggingEntryDTO assembleLoggingEntryDTO(UserHistory loggingEntry) { LoggingEntryDTO loggingEntryDto = new LoggingEntryDTO(); loggingEntryDto.setPorsUserId(loggingEntry.getEditingUserId()); loggingEntryDto.setUserName(loggingEntry.getEditingUserName()); loggingEntryDto.setLogTime(loggingEntry.getLogTime()); loggingEntryDto .setLogDateString(DateFormat.getDateInstance(DateFormat.MEDIUM).format(loggingEntry.getLogTime())); DateFormat dfmt = new SimpleDateFormat("HH:mm:ss:SS"); loggingEntryDto.setLogTimeString(dfmt.format(loggingEntry.getLogTime())); loggingEntryDto.setDomain(loggingEntry.getDomain()); loggingEntryDto.setAction(loggingEntry.getAction()); loggingEntryDto.setLogEntryId(loggingEntry.getDomainId()); return loggingEntryDto; }
From source file:org.hoteia.qalingo.core.service.WebBackofficeService.java
/** * /*w ww . j a v a 2 s . c om*/ */ public void buildAndSaveNewOrderConfirmationMail(final RequestData requestData, final User user, final OrderPurchase order) throws Exception { final MarketArea marketArea = requestData.getMarketArea(); final String contextNameValue = requestData.getContextNameValue(); final String velocityPath = requestData.getVelocityEmailPrefix(); final Locale locale = requestData.getLocale(); final String localizationCode = requestData.getMarketAreaLocalization().getCode(); final OrderConfirmationEmailBean orderConfirmationEmailBean = new OrderConfirmationEmailBean(); orderConfirmationEmailBean.setFromAddress(getEmailFromAddress(requestData, marketArea, contextNameValue, Email.EMAIl_TYPE_ORDER_CONFIRMATION)); orderConfirmationEmailBean .setFromName(marketArea.getEmailFromName(contextNameValue, Email.EMAIl_TYPE_ORDER_CONFIRMATION)); orderConfirmationEmailBean.setReplyToEmail(getEmailFromAddress(requestData, marketArea, contextNameValue, Email.EMAIl_TYPE_ORDER_CONFIRMATION)); orderConfirmationEmailBean.setToEmail(user.getEmail()); if (order != null) { orderConfirmationEmailBean.setOrderNumber(order.getOrderNum()); DateFormat dateFormat = requestUtil.getCommonFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM); if (order.getExpectedDeliveryDate() != null) { orderConfirmationEmailBean .setExpectedDeliveryDate(dateFormat.format(order.getExpectedDeliveryDate())); } else { orderConfirmationEmailBean.setExpectedDeliveryDate("NA"); } if (Hibernate.isInitialized(order.getShippingAddress()) && order.getShippingAddress() != null) { orderConfirmationEmailBean.setCompanyName(order.getShippingAddress().getCompanyName()); orderConfirmationEmailBean.setTitleCode(order.getShippingAddress().getTitle()); String titleLabel = referentialDataService.getTitleByLocale(order.getShippingAddress().getTitle(), locale); orderConfirmationEmailBean.setTitleLabel(titleLabel); orderConfirmationEmailBean.setLastname(order.getShippingAddress().getLastname()); orderConfirmationEmailBean.setFirstname(order.getShippingAddress().getFirstname()); orderConfirmationEmailBean.setAddress1(order.getShippingAddress().getAddress1()); orderConfirmationEmailBean.setAddress2(order.getShippingAddress().getAddress2()); orderConfirmationEmailBean.setAddressAdditionalInformation( order.getShippingAddress().getAddressAdditionalInformation()); orderConfirmationEmailBean.setPostalCode(order.getShippingAddress().getPostalCode()); orderConfirmationEmailBean.setCity(order.getShippingAddress().getCity()); orderConfirmationEmailBean.setStateCode(order.getShippingAddress().getStateCode()); orderConfirmationEmailBean.setAreaCode(order.getShippingAddress().getAreaCode()); orderConfirmationEmailBean.setCountryCode(order.getShippingAddress().getCountryCode()); String coutryLabel = referentialDataService .getCountryByLocale(order.getShippingAddress().getCountryCode(), locale); orderConfirmationEmailBean.setCountry(coutryLabel); } if (Hibernate.isInitialized(order.getOrderItems()) && order.getOrderItems() != null) { for (OrderItem orderItem : order.getOrderItems()) { OrderItemEmailBean orderItemEmailBean = new OrderItemEmailBean(); orderItemEmailBean.setSkuCode(orderItem.getProductSkuCode()); if (StringUtils.isNotEmpty(orderItem.getProductSkuCode())) { ProductSku productSku = productService.getProductSkuByCode(orderItem.getProductSkuCode()); orderItemEmailBean.setEan(productSku.getEan()); orderItemEmailBean.setI18nName(productSku.getI18nName(localizationCode)); orderItemEmailBean.setI18nDescription(productSku.getI18nDescription(localizationCode)); if (Hibernate.isInitialized(productSku.getAssets()) && productSku.getAssets() != null) { for (Asset asset : productSku.getAssets()) { final String path = engineSettingService .getProductSkuImageWebPath(productSku.getCode(), asset); orderItemEmailBean.setDefaultAssetFullPath( backofficeUrlService.buildAbsoluteUrl(requestData, path)); } } } if (orderItem.getStoreId() != null) { Store store = retailerService.getStoreById(orderItem.getStoreId()); orderItemEmailBean.setStoreCode(store.getCode()); orderItemEmailBean.setStoreName(store.getName()); } orderItemEmailBean.setPrice(orderItem.getOrderItemPriceWithStandardCurrencySign()); orderItemEmailBean .setPriceWithTaxes(orderItem.getOrderItemPriceWithTaxesWithStandardCurrencySign()); orderItemEmailBean.setQuantity(orderItem.getQuantity()); orderItemEmailBean .setAmount(orderItem.getOrderItemTotalPriceWithTaxesWithStandardCurrencySign()); orderConfirmationEmailBean.getOrderItems().add(orderItemEmailBean); } } orderConfirmationEmailBean .setOrderItemsTotalWithCurrencySign(order.getOrderItemTotalWithTaxesWithStandardCurrencySign()); orderConfirmationEmailBean .setOrderShippingTotalWithCurrencySign(order.getDeliveryMethodTotalWithStandardCurrencySign()); if (BigDecimal.ZERO.compareTo(order.getDeliveryMethodTotal()) == 0) { orderConfirmationEmailBean.setOrderShippingTotalWithCurrencySign(coreMessageSource .getCommonMessage(ScopeWebMessage.LABEL.getPropertyKey(), "free", requestData.getLocale())); } orderConfirmationEmailBean .setOrderTaxesTotalWithCurrencySign(order.getTaxTotalWithStandardCurrencySign()); orderConfirmationEmailBean.setOrderTotalWithCurrencySign(order.getOrderTotalWithStandardCurrencySign()); } emailService.buildAndSaveNewOrderB2BConfirmationMail(requestData, user, velocityPath, orderConfirmationEmailBean); }
From source file:org.ejbca.core.model.ra.raadmin.UserFullfillEndEntityProfileTest.java
/** * Test the profile fulfilling rutines/*from w w w. j a v a 2 s .c o m*/ * * @throws Exception error */ @Test public void testfulfillEndEntityProfiles() throws Exception { log.trace(">test01fulfillEndEntityProfiles()"); // Dummy caids final int testca2 = 3; int currentSubTest = 1; { final EndEntityProfile profile = new EndEntityProfile(); // Set so CN=modifyable required, OU0={DEP1_1,DEP1_2} required, OU1={DEP2_1,DEP2_2} required, C=OU1={SE,DK} not required profile.addField(DnComponents.ORGANIZATIONALUNIT); profile.addField(DnComponents.ORGANIZATIONALUNIT); profile.addField(DnComponents.COUNTRY); profile.setRequired(DnComponents.ORGANIZATIONALUNIT, 0, true); profile.setRequired(DnComponents.ORGANIZATIONALUNIT, 1, true); profile.setModifyable(DnComponents.ORGANIZATIONALUNIT, 0, false); profile.setModifyable(DnComponents.ORGANIZATIONALUNIT, 1, false); profile.setModifyable(DnComponents.COUNTRY, 0, false); profile.setValue(DnComponents.ORGANIZATIONALUNIT, 0, "DEP1_1;DEP1_2"); profile.setValue(DnComponents.ORGANIZATIONALUNIT, 1, "DEP2_1;DEP2_2"); profile.setValue(DnComponents.COUNTRY, 0, "SE;DK"); profile.setValue(EndEntityProfile.AVAILCAS, 0, "" + TEST_CA_1); // Test completly erronious DN try { profile.doesUserFullfillEndEntityProfile("username", "password", "blabla", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Profile does not check DN at all."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + " = OK"); } // Test correct DN try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Profile Fulfill Test " + (currentSubTest++) + " " + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail(e.getMessage()); } // Test no username even though is required try { profile.doesUserFullfillEndEntityProfile("", "password", STANDARD_DN, "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("UserName is not checked even though it's required"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Profile Fulfill Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Test no password even though is required try { profile.doesUserFullfillEndEntityProfile("username", "", STANDARD_DN, "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Password is not checked even though it's required"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Profile Test Fulfill " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Test with no CN (required) try { profile.doesUserFullfillEndEntityProfile("username", "password", "OU=DEP1_1,OU=DEP2_1,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error Required CN field wasn't checked"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Test with only one OU (2 required) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=DEP2_1,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error Required OU field wasn't checked"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Test were second OU have the wrong value (Dep2_1 or Dep2_2) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=DEP1_1,OU=DEP2_3,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error value of second OU field wasn't checked"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Test without C (not required) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=DEP1_1,OU=DEP2_2", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail(e.getMessage()); } // Test illegal value of C (SE or DK) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=DEP1_1,OU=DEP2_2, C=NO", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Inproper check of C value."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Add some subject altname fields profile.addField(DnComponents.RFC822NAME); profile.addField(DnComponents.DNSNAME); profile.addField(DnComponents.UPN); profile.addField(DnComponents.IPADDRESS); profile.setRequired(DnComponents.RFC822NAME, 0, true); profile.setRequired(DnComponents.DNSNAME, 0, true); profile.setRequired(DnComponents.UPN, 0, true); profile.setRequired(DnComponents.IPADDRESS, 0, true); profile.setModifyable(DnComponents.RFC822NAME, 0, false); profile.setModifyable(DnComponents.DNSNAME, 0, false); profile.setModifyable(DnComponents.UPN, 0, false); profile.setModifyable(DnComponents.IPADDRESS, 0, true); profile.setValue(DnComponents.RFC822NAME, 0, "test.com"); profile.setValue(DnComponents.DNSNAME, 0, "test.primekey.se"); profile.setValue(DnComponents.UPN, 0, "test.com;primekey.se"); profile.setValue(DnComponents.IPADDRESS, 0, "11.11.1.1"); profile.setRequired(EndEntityProfile.EMAIL, 0, true); profile.setModifyable(EndEntityProfile.EMAIL, 0, false); profile.setValue(EndEntityProfile.EMAIL, 0, "test.com;primekey.se"); // Test completly erronious Alt Name try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "blabla", "", "test@test.com", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Profile does not check altname at all."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + " = OK"); } // Test correct Alt Name try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "RFC822NAME=test@test.com, dnsname=test.primekey.se, Upn=test@primekey.se, ipaddress=11.11.1.2", "", "test@test.com", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Profile Fulfill Test " + (currentSubTest++) + " " + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail(e.getMessage()); } // Test with no RFC822NAME (required) try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "dnsname=test.primekey.se, Upn=test@primekey.se, ipaddress=11.11.1.2", "", "test@test.com", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error Required RFC822NAME field wasn't checked"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Test with one RFC822NAME to many try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test@test.com, rfc822name=test@primekey.se, dnsname=test.primekey.se, Upn=test@primekey.se, ipaddress=11.11.1.2", "", "test@test.com", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("To many RFC822 names fields wasn't checked"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Test that only domain is checked for RFC822name and UPN try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test@test.com, dnsname=test.primekey.se, Upn=test12@primekey.se, ipaddress=11.11.1.2", "", "test@test.com", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Not only domains of RFC822NAME and UPN where checked: " + e.getMessage()); } // Test were DNS have illegal value try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test@test.com, dnsname=test2.primekey.se, Upn=test12@primekey.se, ipaddress=11.11.1.2", "", "test@test.com", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error value of DNS not checked."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Test without IPADDRESS (required) try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test@test.com, dnsname=test.primekey.se, Upn=test12@primekey.se", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error not checking number of IPADDRESS properly."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + " = OK"); } // Test without email field (required) 1 try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test@test.com, dnsname=test.primekey.se, Upn=test12@primekey.se, ipaddress=11.11.1.1", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Inproper check of email field."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Test without email field (required) 2 try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test@test.com, dnsname=test.primekey.se, Upn=test12@primekey.se, ipaddress=11.11.1.1", "", "null", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Inproper check of email field."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Test without email field (required) 3 try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test@test.com, dnsname=test.primekey.se, Upn=test12@primekey.se,ipaddress=11.11.1.1", "", null, CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Inproper check of email field."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Test illegal value of email field (test.com or primekey.se) 1 try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test11@test1.com, dnsname=test.primekey.se, Upn=test12@primekey.se,ipaddress=11.11.1.1", "", "test11@test1.com", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Inproper check of email field values."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } profile.setValue(EndEntityProfile.AVAILCERTPROFILES, 0, CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER + ";" + CertificateProfileConstants.CERTPROFILE_FIXED_SUBCA); // Test illegal value of Certificate Profile try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test11@test.com, dnsname=test.primekey.se, Upn=test12@primekey.se,ipaddress=11.11.1.1", "", "test11@test.com", CertificateProfileConstants.CERTPROFILE_FIXED_ROOTCA, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Inproper check of certificate profile values."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Test Wrong CA try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test11@test.com, dnsname=test.primekey.se, Upn=test12@primekey.se,ipaddress=11.11.1.1", "", "test11@test.com", CertificateProfileConstants.CERTPROFILE_FIXED_SUBCA, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, testca2, null); fail("Inproper check of available ca's."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " " + e.getMessage() + " = OK"); } // Test with a mix of several rfc822name fields //profile.addField(DnComponents.RFC822NAME); already set profile.addField(DnComponents.RFC822NAME); profile.addField(DnComponents.RFC822NAME); profile.addField(DnComponents.RFC822NAME); //profile.setRequired(DnComponents.RFC822NAME,0,true); already set profile.setRequired(DnComponents.RFC822NAME, 1, false); profile.setRequired(DnComponents.RFC822NAME, 2, true); profile.setRequired(DnComponents.RFC822NAME, 3, true); //profile.setUse(DnComponents.RFC822NAME, 0, true); already set profile.setUse(DnComponents.RFC822NAME, 1, false); profile.setUse(DnComponents.RFC822NAME, 2, false); profile.setUse(DnComponents.RFC822NAME, 3, false); //profile.setModifyable(DnComponents.RFC822NAME,0,false); already set profile.setModifyable(DnComponents.RFC822NAME, 1, true); profile.setModifyable(DnComponents.RFC822NAME, 2, false); profile.setModifyable(DnComponents.RFC822NAME, 3, true); //profile.setValue(DnComponents.RFC822NAME,0,"test.com"); not used profile.setValue(DnComponents.RFC822NAME, 1, "foobar.com"); profile.setValue(DnComponents.RFC822NAME, 2, "test@somefoo.com"); profile.setValue(DnComponents.RFC822NAME, 3, "somebar.com"); // Make sure normal usage works /* * Normal usage test moved down to testProfileWithRfc822Name() */ // Test missing required rfc822name field try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test@test.com, rfc822name=test@somefoo.com, " + "dnsname=test.primekey.se, Upn=test12@primekey.se, ipaddress=11.11.1.2", "", "test@test.com", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Did not notice missing RFC822Name."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK (" + e.getMessage() + ")"); } // Try non-existing required "use end entity e-mail" try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test@nodomain.com, rfc822name=test@anything.com, rfc822name=test@somefoo.com, " + "dnsname=test.primekey.se, Upn=test12@primekey.se, ipaddress=11.11.1.2", "", "test@test.com", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Did not check RFC822Name against e-mail field."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK (" + e.getMessage() + ")"); } // Try to ignore a required non-modifyable domain try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test@test.com, rfc822name=test@anything.com, rfc822name=test@somebar.com, " + "dnsname=test.primekey.se, Upn=test12@primekey.se, ipaddress=11.11.1.2", "", "test@test.com", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Did not check RFC822Name against profile."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK (" + e.getMessage() + ")"); } // Use same as required non-mod field in non-req field try { profile.doesUserFullfillEndEntityProfile("username", "password", STANDARD_DN, "rfc822name=test@test.com, rfc822name=test@anything.com, rfc822name=test@somefoo.com, rfc822name=test@somefoo.com, " + "dnsname=test.primekey.se, Upn=test12@primekey.se, ipaddress=11.11.1.2", "", "test@test.com", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Did not check RFC822Name against profile." + e.getMessage()); } } {// New profile final EndEntityProfile profile = new EndEntityProfile(); // Set so CN=modifyable required, OU0={DEP1_1,DEP1_2} required, OU1={DEP2_1,DEP2_2} required, OU3=Optional, C=O{SE,DK} not required profile.addField(DnComponents.ORGANIZATIONALUNIT); profile.addField(DnComponents.ORGANIZATIONALUNIT); profile.addField(DnComponents.ORGANIZATIONALUNIT); profile.addField(DnComponents.ORGANIZATIONALUNIT); profile.addField(DnComponents.ORGANIZATIONALUNIT); profile.addField(DnComponents.COUNTRY); profile.setRequired(DnComponents.ORGANIZATIONALUNIT, 0, false); profile.setRequired(DnComponents.ORGANIZATIONALUNIT, 1, true); profile.setRequired(DnComponents.ORGANIZATIONALUNIT, 2, false); profile.setRequired(DnComponents.ORGANIZATIONALUNIT, 3, true); profile.setRequired(DnComponents.ORGANIZATIONALUNIT, 4, false); profile.setModifyable(DnComponents.ORGANIZATIONALUNIT, 1, false); profile.setModifyable(DnComponents.ORGANIZATIONALUNIT, 3, false); profile.setModifyable(DnComponents.ORGANIZATIONALUNIT, 4, true); profile.setModifyable(DnComponents.COUNTRY, 0, false); profile.setValue(DnComponents.ORGANIZATIONALUNIT, 1, "DEP1_1;DEP1_2"); profile.setValue(DnComponents.ORGANIZATIONALUNIT, 3, "DEP2_1;DEP2_2"); profile.setValue(DnComponents.ORGANIZATIONALUNIT, 4, "DEP3_1;DEP3_2"); profile.setValue(DnComponents.COUNTRY, 0, "SE;DK"); profile.setValue(EndEntityProfile.AVAILCAS, 0, "" + TEST_CA_1); // Test with two OU (2 required) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=,OU=DEP1_1,OU=,OU=DEP2_2,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error Required OU fields wasn't checked propertly: " + e.getMessage()); } // Test with tree OU (2 required) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=,OU=DEP1_1,OU=,OU=DEP2_2,OU=DEP3_3,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error Required OU fields wasn't checked propertly: " + e.getMessage()); } profile.setModifyable(DnComponents.ORGANIZATIONALUNIT, 4, false); // Test with tree OU (2 required) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=,OU=DEP1_1,OU=,OU=DEP2_2,OU=DEP3_1,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error Required OU fields wasn't checked propertly: " + e.getMessage()); } // Test with tree OU (2 required) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=,OU=DEP1_1,OU=,OU=DEP2_2,OU=DEP3_3,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error Required OU fields wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } } { // Test Reverse Checks // New profile final EndEntityProfile profile = new EndEntityProfile(); profile.setReverseFieldChecks(true); // Set so CN=modifyable required, OU0=Modifyable not required, OU1=Modifyable not required, OU3=required {hard,soft}, C=O{SE,DK} not required profile.addField(DnComponents.ORGANIZATIONALUNIT); profile.addField(DnComponents.ORGANIZATIONALUNIT); profile.addField(DnComponents.ORGANIZATIONALUNIT); profile.addField(DnComponents.COUNTRY); profile.setRequired(DnComponents.ORGANIZATIONALUNIT, 0, false); profile.setRequired(DnComponents.ORGANIZATIONALUNIT, 1, false); profile.setRequired(DnComponents.ORGANIZATIONALUNIT, 2, true); profile.setModifyable(DnComponents.ORGANIZATIONALUNIT, 0, true); profile.setModifyable(DnComponents.ORGANIZATIONALUNIT, 1, true); profile.setModifyable(DnComponents.ORGANIZATIONALUNIT, 2, false); profile.setModifyable(DnComponents.COUNTRY, 0, false); profile.setValue(DnComponents.ORGANIZATIONALUNIT, 0, ""); profile.setValue(DnComponents.ORGANIZATIONALUNIT, 1, ""); profile.setValue(DnComponents.ORGANIZATIONALUNIT, 2, "HARD;SOFT"); profile.setValue(DnComponents.COUNTRY, 0, "SE;DK"); profile.setValue(EndEntityProfile.AVAILCAS, 0, "" + TEST_CA_1); // Test with one OU (1 required) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=HARD,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error Reverse OU fields wasn't checked propertly: " + e.getMessage()); } // Test with two OU (1 required) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=DEP2_1,OU=HARD,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error Reverse OU fields wasn't checked propertly: " + e.getMessage()); } // Test with three OU (1 required) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=DEP1_1,OU=DEP2_1,OU=HARD,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error Reverse OU fields wasn't checked propertly: " + e.getMessage()); } // Test with four OU (3 allowed) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=DEP0_1,OU=DEP1_1,OU=DEP2_1,OU=HARD,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error Reverse OU fields wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Test with wrong data in nonmodifiable field try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=DEP1_1,OU=DEP2_1,OU=HARD2,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error Reverse OU fields wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Test that the right data is checked when a lesser number of field is used try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=HARD,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error Reverse OU fields wasn't checked propertly: " + e.getMessage()); } // Test with wrong data in nonmodifiable field when having only one ou try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=HARD2,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error Reverse OU fields wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Test with no ou try { profile.doesUserFullfillEndEntityProfile("username", "passworCerd", "CN=John Smith,C=SE", "null", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error Reverse OU fields wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Test Reverse checks of subject alt names // Set so CN=modifyable required, OU=Modifyable not required, OU1=Modifyable not required, OU3=required {hard,soft}, C=O{SE,DK} not required profile.addField(DnComponents.IPADDRESS); profile.addField(DnComponents.IPADDRESS); profile.addField(DnComponents.IPADDRESS); profile.addField(DnComponents.DNSNAME); profile.setRequired(DnComponents.IPADDRESS, 0, false); profile.setRequired(DnComponents.IPADDRESS, 1, false); profile.setRequired(DnComponents.IPADDRESS, 2, true); profile.setModifyable(DnComponents.IPADDRESS, 0, true); profile.setModifyable(DnComponents.IPADDRESS, 1, true); profile.setModifyable(DnComponents.IPADDRESS, 2, false); profile.setModifyable(DnComponents.DNSNAME, 0, false); profile.setValue(DnComponents.IPADDRESS, 0, ""); profile.setValue(DnComponents.IPADDRESS, 1, ""); profile.setValue(DnComponents.IPADDRESS, 2, "10.1.1.1;10.2.2.2"); profile.setValue(DnComponents.DNSNAME, 0, "test1.se;test2.se"); // Test with one IPAddress (1 required) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=HARD,C=SE", "dnsname=test1.se,ipaddress=10.1.1.1", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error Reverse IPADDRESS fields wasn't checked propertly: " + e.getMessage()); } // Test with two IPAddress (1 required) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=DEP2_1,OU=HARD,C=SE", "dnsname=test1.se,ipaddress=11.1.1.1,ipaddress=10.1.1.1", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error Reverse IPADDRESS fields wasn't checked propertly: " + e.getMessage()); } // Test with three IPAddress (1 required) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=DEP1_1,OU=DEP2_1,OU=HARD,C=SE", "dnsname=test1.se,ipaddress=12.1.1.1,ipaddress=11.1.1.1,ipaddress=10.1.1.1", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error Reverse IPADDRESS fields wasn't checked propertly: " + e.getMessage()); } // Test with four IPAddress (3 allowed) try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=DEP0_1,OU=DEP1_1,OU=DEP2_1,OU=HARD,C=SE", "dnsname=test1.se,ipaddress=12.1.1.1,ipaddress=12.1.1.1,ipaddress=11.1.1.1,ipaddress=10.1.1.1", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error Reverse IPADDRESS fields wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Test with wrong data in nonmodifiable field try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=DEP1_1,OU=DEP2_1,OU=HARD2,C=SE", "dnsname=test1.se,ipaddress=12.1.1.1,ipaddress=11.1.1.1,ipaddress=10.1.1.2", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error Reverse IPADDRESS fields wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Test that the right data is checked when a lesser number of field is used try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=HARD,C=SE", "dnsname=test1.se,ipaddress=10.1.1.1", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error Reverse IPADDRESS fields wasn't checked propertly: " + e.getMessage()); } // Test with wrong data in nonmodifiable field when having only one ou try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=HARD2,C=SE", "dnsname=test1.se,ipaddress=11.1.1.1", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error Reverse IPADDRESS fields wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Test with no ou try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,C=SE", "dnsname=test1.se", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error Reverse IPADDRESS fields wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Test adding required fields for Subject Directory Attributes // Set so CN=modifyable required, OU=Modifyable not required, OU1=Modifyable not required, OU3=required {hard,soft}, C=O{SE,DK} not required profile.addField(DnComponents.DATEOFBIRTH); profile.addField(DnComponents.PLACEOFBIRTH); profile.addField(DnComponents.GENDER); profile.addField(DnComponents.COUNTRYOFCITIZENSHIP); profile.addField(DnComponents.COUNTRYOFRESIDENCE); profile.setRequired(DnComponents.DATEOFBIRTH, 0, false); profile.setRequired(DnComponents.PLACEOFBIRTH, 0, false); profile.setRequired(DnComponents.GENDER, 0, false); profile.setRequired(DnComponents.COUNTRYOFCITIZENSHIP, 0, false); profile.setRequired(DnComponents.COUNTRYOFRESIDENCE, 0, false); profile.setModifyable(DnComponents.DATEOFBIRTH, 0, true); profile.setModifyable(DnComponents.PLACEOFBIRTH, 0, true); profile.setModifyable(DnComponents.GENDER, 0, true); profile.setModifyable(DnComponents.COUNTRYOFCITIZENSHIP, 0, true); profile.setModifyable(DnComponents.COUNTRYOFRESIDENCE, 0, false); profile.setValue(DnComponents.DATEOFBIRTH, 0, ""); profile.setValue(DnComponents.PLACEOFBIRTH, 0, ""); profile.setValue(DnComponents.GENDER, 0, ""); profile.setValue(DnComponents.COUNTRYOFCITIZENSHIP, 0, ""); profile.setValue(DnComponents.COUNTRYOFRESIDENCE, 0, "SE"); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=HARD,C=SE", "dnsname=test1.se,ipaddress=10.1.1.1", "CountryOfCitizenship=FOO", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error CountryOfCitizenship wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { assertEquals("Invalid COUNTRYOFCITIZENSHIP. Must be of length two.", e.getMessage()); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=HARD,C=SE", "dnsname=test1.se,ipaddress=10.1.1.1", "CountryOfCitizenship=SE, CountryOfResidence=Foo", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error CountryOfCitizenship wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { assertEquals("Invalid COUNTRYOFRESIDENCE. Must be of length two.", e.getMessage()); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=HARD,C=SE", "dnsname=test1.se,ipaddress=10.1.1.1", "CountryOfCitizenship=SE, CountryOfResidence=TR", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error CountryOfCitizenship wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { assertEquals("Field COUNTRYOFRESIDENCE data didn't match requirement of end entity profile.", e.getMessage()); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=HARD,C=SE", "dnsname=test1.se,ipaddress=10.1.1.1", "CountryOfCitizenship=SE, CountryOfResidence=SE, Gender=M, PlaceOfBirth=Stockholm", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error Subject Dir Attributes wasn't checked propertly"); } try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=HARD,C=SE", "dnsname=test1.se,ipaddress=10.1.1.1", "DateOfBirth=189901, CountryOfCitizenship=SE, CountryOfResidence=SE", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error DateOfBirth wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { assertEquals("Invalid DATEOFBIRTH. Must be of length eight.", e.getMessage()); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=HARD,C=SE", "dnsname=test1.se,ipaddress=10.1.1.1", "DateOfBirth=189901AA, CountryOfCitizenship=SE, CountryOfResidence=SE", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); fail("Error DateOfBirth wasn't checked propertly"); } catch (UserDoesntFullfillEndEntityProfile e) { assertEquals("Invalid DATEOFBIRTH. Must be only numbers.", e.getMessage()); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith,OU=HARD,C=SE", "dnsname=test1.se,ipaddress=10.1.1.1", "DateOfBirth=18990101, CountryOfCitizenship=SE, CountryOfResidence=SE", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, null); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error DateOfBirth wasn't checked propertly"); } } { // Test time constraints final EndEntityProfile profile = new EndEntityProfile(); Date now = new Date(); Date endOfTime = new Date(Long.MAX_VALUE); FastDateFormat sm = FastDateFormat.getInstance("yyyy-MM-dd HH:mm"); String staticNow = sm.format(now); String relativeNow = "0:00:00"; String staticEndOfTime = sm.format(endOfTime); String relativeEndOfTime = "33000:00:00"; // ~100 years String staticInvalid = "XXXX-XX-XX XX:XX PM"; String relativeInvalid = "XXXXX:XXX:XXX"; String relativeNegative = "-10:00:00"; ExtendedInformation ei = new ExtendedInformation(); // Use empty, should fail profile.setValue(EndEntityProfile.AVAILCAS, 0, "" + TEST_CA_1); profile.setUse(EndEntityProfile.STARTTIME, 0, true); profile.setUse(EndEntityProfile.ENDTIME, 0, false); profile.setValue(EndEntityProfile.STARTTIME, 0, ""); profile.setValue(EndEntityProfile.ENDTIME, 0, ""); ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, ""); try { // Custom starttime can be empty or null profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error: Empty start time was not checked correctly."); } profile.setUse(EndEntityProfile.STARTTIME, 0, false); profile.setUse(EndEntityProfile.ENDTIME, 0, true); ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, ""); try { // Custom endtime can be empty or null profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error: Empty end time was not checked correctly."); } // Static times work? profile.setUse(EndEntityProfile.STARTTIME, 0, true); profile.setUse(EndEntityProfile.ENDTIME, 0, true); ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, staticNow); ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, staticEndOfTime); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error: Static times does not work. (" + e.getMessage() + ")"); } // Relative times work? ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, relativeNow); ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, relativeEndOfTime); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error: Relative times does not work."); } // Static start, rel end work? ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, staticNow); ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, relativeEndOfTime); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error: Static start time w relative end time does not work."); } // Rel start, static end work? ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, relativeNow); ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, staticEndOfTime); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error: Relative start time w static end time does not work."); } // Negative relative start times work? ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, relativeNegative); ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, staticEndOfTime); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); fail("Error: Possible to use negative start time."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Negative relative end times work? ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, staticNow); ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, relativeNegative); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); fail("Error: Possible to use negative end time."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Static end before start ok? ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, staticEndOfTime); ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, staticNow); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); fail("Error: Static end time before static start time allowed."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Relative end before start ok? ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, relativeEndOfTime); ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, relativeNow); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); fail("Error: Relative end time before relative start time allowed."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Invalid static start ok? ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, staticInvalid); ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, staticEndOfTime); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); fail("Error: Invalid static start time allowed."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Invalid static end ok? ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, staticNow); ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, staticInvalid); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); fail("Error: Invalid static start time allowed."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Invalid relative start ok? ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, relativeInvalid); ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, staticEndOfTime); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); fail("Error: Invalid relative start time allowed."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Invalid relative end ok? ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, relativeNow); ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, staticInvalid); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); fail("Error: Invalid relative start time allowed."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } // Is this Java-version parsing dates correctly? long magicDateTime = 1181040300000L; // "12:45 PM" in US Locale String value1 = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US) .format(new Date(magicDateTime)); String value2 = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.US).format( DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US).parse(value1)); long magicDateTime2 = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.US) .parse(value2).getTime(); if (magicDateTime != magicDateTime2) { fail("Error: Java does not parse dates correctly. " + magicDateTime + " " + magicDateTime2 + " " + value1 + " " + value2); } } { // Test allow multiple requests final EndEntityProfile profile = new EndEntityProfile(); final ExtendedInformation ei = new ExtendedInformation(); // Use empty, should fail profile.setValue(EndEntityProfile.AVAILCAS, 0, "" + TEST_CA_1); profile.setUse(EndEntityProfile.ALLOWEDREQUESTS, 0, false); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error: Allowedrequests not checked correctly, should be allowed."); } ei.setCustomData(ExtendedInformationFields.CUSTOM_REQUESTCOUNTER, "2"); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); fail("Error: Allowed requests was not checked correctly, should not be allowed."); } catch (UserDoesntFullfillEndEntityProfile e) { log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } profile.setUse(EndEntityProfile.ALLOWEDREQUESTS, 0, true); try { profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); log.debug("End Entity Fulfill Profile Test " + (currentSubTest++) + " = OK"); } catch (UserDoesntFullfillEndEntityProfile e) { fail("Error: Allowedrequests not checked correctly, should be allowed."); } } { // New profile final EndEntityProfile profile = new EndEntityProfile(); // Set so maxFailedLogins=non-modifyable required profile.addField(EndEntityProfile.MAXFAILEDLOGINS); profile.setUse(EndEntityProfile.MAXFAILEDLOGINS, 0, true); profile.setRequired(EndEntityProfile.MAXFAILEDLOGINS, 0, true); profile.setModifyable(EndEntityProfile.MAXFAILEDLOGINS, 0, false); profile.setValue(EndEntityProfile.MAXFAILEDLOGINS, 0, "7"); profile.setValue(EndEntityProfile.AVAILCAS, 0, "" + TEST_CA_1); try { final ExtendedInformation ei = new ExtendedInformation(); ei.setMaxLoginAttempts(1234); profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); fail("Error: maxFailedLogins was not checked correctly, should not be allowed."); } catch (UserDoesntFullfillEndEntityProfile e) { // OK } try { final ExtendedInformation ei = new ExtendedInformation(); ei.setMaxLoginAttempts(7); profile.doesUserFullfillEndEntityProfile("username", "password", "CN=John Smith", "", "", "", CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER, false, false, false, SecConst.TOKEN_SOFT_BROWSERGEN, 0, TEST_CA_1, ei); } catch (UserDoesntFullfillEndEntityProfile e) { log.error(e.getMessage(), e); fail("Error: maxFailedLogins was not checked correctly, should be allowed."); } log.trace("<test01fulfillEndEntityProfiles()"); } }
From source file:org.methodize.nntprss.admin.AdminServlet.java
private void cmdShowCurrentChannels(HttpServletResponse response) throws ServletException, IOException { DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); Writer writer = response.getWriter(); writeHeader(writer, TAB_VIEW_CHANNELS); writeCheckboxSelector(writer, "checkAllChannels", "chl", "channels"); writer.write("<form name='channels' action='/?action=channelaction' method='POST'>"); writer.write("<table class='tableborder' border='0'>"); writer.write("<tr><th colspan='5' class='tableHead'>Channels</td></th>"); // writer.write("<tr><th class='subHead'><input type='checkbox' name='change' onClick='checkAllChannels(this);'></th><th class='subHead'>Newsgroup Name</th><th class='subHead'>RSS URL</th><th class='subHead'>Last Polled</th></tr>"); writer.write(/*from w w w .ja v a2s. c o m*/ "<tr><th class='subHead'><input type='checkbox' name='change' onClick='checkAllChannels(this);'></th><th class='subHead'>Newsgroup Name</th><th class='subHead'> </th><th class='subHead'>Feed URL</th><th class='subHead'>Last Polled</th></tr>"); ChannelManager channelManager = (ChannelManager) getServletContext() .getAttribute(AdminServer.SERVLET_CTX_RSS_MANAGER); NNTPServer nntpServer = (NNTPServer) getServletContext().getAttribute(AdminServer.SERVLET_CTX_NNTP_SERVER); Iterator channelIter = channelManager.channels(); String newsPrefix = getNewsURLPrefix(nntpServer); while (channelIter.hasNext()) { Channel channel = (Channel) channelIter.next(); writer.write("<tr><td class='row1'><input type='checkbox' name='chl" + HTMLHelper.escapeString(channel.getName()) + "'></td>"); // Truncate displayed URL... String url = channel.getUrl(); if (url.length() > 32) { url = url.substring(0, 32) + "..."; } String lastPolled; if (channel.getLastPolled() != null) { lastPolled = df.format(channel.getLastPolled()); } else { lastPolled = "Awaiting poll"; } String parser = (channel.isParseAtAllCost() ? "*" : ""); switch (channel.getStatus()) { case Channel.STATUS_INVALID_CONTENT: case Channel.STATUS_NOT_FOUND: case Channel.STATUS_UNKNOWN_HOST: case Channel.STATUS_NO_ROUTE_TO_HOST: case Channel.STATUS_PROXY_AUTHENTICATION_REQUIRED: case Channel.STATUS_USER_AUTHENTICATION_REQUIRED: writer.write("<td class='chlerror' bgcolor='#FF0000'>" + parser + "<a class='row' title='Channel configuration' href='/?action=show&name=" + URLEncoder.encode(channel.getName()) + "'><font color='#FFFFFF'>" + channel.getName() + "</font></a></td>"); writer.write( "<td class='chlerror' bgcolor='#FF0000'><a class='row' title='Read this channel in your default newsreader' href='" + newsPrefix + HTMLHelper.escapeString(channel.getName()) + "'><font color='#FFFFFF'>[Read]</font></a></td>"); writer.write( "<td class='chlerror' bgcolor='#FF0000'><font color='#FFFFFF'>" + url + "</font></td>"); writer.write("<td class='chlerror' bgcolor='#FF0000'><font color='#FFFFFF'>" + lastPolled + "</font></td></tr>"); break; case Channel.STATUS_SOCKET_EXCEPTION: case Channel.STATUS_CONNECTION_TIMEOUT: writer.write("<td class='chlwarning' bgcolor='#FFFF00'>" + parser + "<a class='row' title='Channel configuration' href='/?action=show&name=" + URLEncoder.encode(channel.getName()) + "'><font color='#000000'>" + channel.getName() + "</font></a></td>"); writer.write( "<td class='chlwarning' bgcolor='#FFFF00'><a class='row' title='Read this channel in your default newsreader' href='" + newsPrefix + HTMLHelper.escapeString(channel.getName()) + "'>[Read]</a></td>"); writer.write( "<td class='chlwarning' bgcolor='#FFFF00'><font color='#000000'>" + url + "</font></td>"); writer.write("<td class='chlwarning' bgcolor='#FFFF00'><font color='#000000'>" + lastPolled + "</font></td></tr>"); break; default: if (channel.isEnabled()) { writer.write("<td class='row1'>" + parser + "<a class='row' title='Channel configuration' href='/?action=show&name=" + URLEncoder.encode(channel.getName()) + "'>" + channel.getName() + "</a></td>"); writer.write( "<td class='row1'><a class='row' title='Read this channel in your default newsreader' href='" + newsPrefix + HTMLHelper.escapeString(channel.getName()) + "'>[Read]</a></td>"); writer.write("<td class='row1'>" + url + "</td>"); writer.write("<td class='row1'>" + lastPolled + "</td></tr>"); } else { writer.write("<td class='chldisabled' bgcolor='#CCCCCC'>" + parser + "<a class='row' title='Channel configuration' href='/?action=show&name=" + URLEncoder.encode(channel.getName()) + "'>" + channel.getName() + "</a></td>"); writer.write( "<td class='chldisabled'><a class='row' title='Read this channel in your default newsreader' href='" + newsPrefix + HTMLHelper.escapeString(channel.getName()) + "'>[Read]</a></td>"); writer.write("<td class='chldisabled' bgcolor='#CCCCCC'>" + url + "</td>"); writer.write("<td class='chldisabled' bgcolor='#CCCCCC'>" + lastPolled + "</td></tr>"); } } } writer.write("<tr><td class='row2' colspan='5'>"); writer.write( "<input type='submit' onClick='return confirm(\"Are you sure you want to delete these channels?\");' name='delete' value='Delete Selected Channels'> " + "<input type='submit' onClick='return confirm(\"Are you sure you want to repoll these channels?\");' name='repoll' value='Repoll Selected Channels'>" + "</td></tr>"); writer.write("</table><font size='-1'>[* = Channel configured for Parse-At-All-Cost parser]</font><p>"); writer.write("</form><p>"); writeFooter(writer); writer.flush(); }
From source file:org.hoteia.qalingo.core.web.mvc.factory.BackofficeViewBeanFactory.java
/** * /* w w w. j a va 2 s . c om*/ */ public WarehouseViewBean buildViewBeanWarehouse(final RequestData requestData, final Warehouse warehouse) throws Exception { final WarehouseViewBean warehouseViewBean = new WarehouseViewBean(); if (warehouse != null) { warehouseViewBean.setCode(warehouse.getCode()); warehouseViewBean.setName(warehouse.getName()); warehouseViewBean.setDescription(warehouse.getDescription()); warehouseViewBean.setAddress1(warehouse.getAddress1()); warehouseViewBean.setAddress2(warehouse.getAddress2()); warehouseViewBean.setAddressAdditionalInformation(warehouse.getAddressAdditionalInformation()); warehouseViewBean.setPostalCode(warehouse.getPostalCode()); // I18n values warehouseViewBean.setCity(warehouse.getCity()); warehouseViewBean.setStateCode(warehouse.getStateCode()); warehouseViewBean.setCountry(warehouse.getCountryCode()); warehouseViewBean.setCountryCode(warehouse.getCountryCode()); warehouseViewBean.setLongitude(warehouse.getLongitude()); warehouseViewBean.setLatitude(warehouse.getLatitude()); DateFormat dateFormat = requestUtil.getCommonFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM); Date dateCreate = warehouse.getDateCreate(); if (dateCreate != null) { warehouseViewBean.setDateCreate(dateFormat.format(dateCreate)); } else { warehouseViewBean.setDateCreate(Constants.NOT_AVAILABLE); } Date dateUpdate = warehouse.getDateUpdate(); if (dateUpdate != null) { warehouseViewBean.setDateUpdate(dateFormat.format(dateUpdate)); } else { warehouseViewBean.setDateUpdate(Constants.NOT_AVAILABLE); } warehouseViewBean.setDetailsUrl( backofficeUrlService.generateUrl(BoUrls.WAREHOUSE_DETAILS, requestData, warehouse)); warehouseViewBean .setEditUrl(backofficeUrlService.generateUrl(BoUrls.WAREHOUSE_EDIT, requestData, warehouse)); } return warehouseViewBean; }
From source file:mitm.common.security.certificate.GenerateTestCertificates.java
/** * Generates a certificate without S/MIME extended key usage extension and ext key usage non critical * /*w w w. jav a 2s .co m*/ * @throws Exception */ private void generateCertificateNoSMIMEExtKeyUsageNonCritical() throws Exception { X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder(); String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d0030818902818100b3" + "98c84b2a2649ab19bf1c38d057b1f43429291b4f9d6bbc6172da71b1dd82" + "a253f31e4e295db6e6025f3bd09adbfd741557198b17e3f8a4ab9e13b617" + "b3e560e16f8f8d72fb95ad3a82c2c9e2baf7efa6e93b5a9bd1e6a9d39277" + "c0c9fae99ce7b66d1bbf238a4749a45f40ef5ce02106664ecff54cd64d99" + "03f2e8f949d2f70203010001"; String encodedPrivateKey = "30820275020100300d06092a864886f70d01010105000482025f3082025b" + "02010002818100b398c84b2a2649ab19bf1c38d057b1f43429291b4f9d6b" + "bc6172da71b1dd82a253f31e4e295db6e6025f3bd09adbfd741557198b17" + "e3f8a4ab9e13b617b3e560e16f8f8d72fb95ad3a82c2c9e2baf7efa6e93b" + "5a9bd1e6a9d39277c0c9fae99ce7b66d1bbf238a4749a45f40ef5ce02106" + "664ecff54cd64d9903f2e8f949d2f7020301000102818041056c66822110" + "84c8b27f16369fb946af67c38126c6d88d803e63c5cbde65803da2847349" + "d8aaf20523d37507cbe3ac1659cd5ea54c9ce5895896cc533287357b390d" + "0390da3b02ddae5dcd13527526664a127a2f3104ced7d6114020dd527d81" + "79a07e36705b29fb4256036e4c6912ca769bada9eb6083134c5f99ada34c" + "41024100e94021d2682b169f4aef370060793f28dafcbd375b92dc420368" + "402469952a9563df82001b910ceb38441e5d57790392aef97bf0e57c0203" + "06daa47850e53b97024100c51d0232655f3dd219e690b3cc99c79d0ef6c9" + "cfcf315952164ec81428c06d608723c0018d09af36bb64517146bbe4c3bb" + "80d362e415fc112157b3afec9a8fa1024012940d1d99367562d2b1230c60" + "a2c7a91568341a08ad35e5fc277d9468e47cb3d174a802222ff77b74cbd8" + "2f4f1c50708a874c9bef6b652da08a21b78399fe990240757619ef0a35bd" + "534c97f7370dffbdd23c2e9888bbc17ea6ca205c5e970244abb71c78b8f3" + "e10786a818d9e794ed371fe4c69a315e1633c5c986c7cf5841aac1024013" + "f17fd383e24562c322d2ef1780b93a4452c07dcda48db73f0e9aac9d42a5" + "ddfa9e1ffdbe4e8ba33891246e3f153f135bbd7da646dc04cb6b7755b92f" + "9dfe6b"; PrivateKey privateKey = decodePrivateKey(encodedPrivateKey); PublicKey publicKey = decodePublicKey(encodedPublicKey); X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder(); String email = "test@example.com"; subjectBuilder.setCommonName("No S/MIME extended key usage non critical"); subjectBuilder.setEmail(email); subjectBuilder.setCountryCode("NL"); subjectBuilder.setLocality("Amsterdam"); subjectBuilder.setState("NH"); AltNamesBuilder altNamesBuider = new AltNamesBuilder(); altNamesBuider.setRFC822Names(email); X500Principal subject = subjectBuilder.buildPrincipal(); GeneralNames altNames = altNamesBuider.buildAltNames(); Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>(); keyUsage.add(KeyUsageType.DIGITALSIGNATURE); keyUsage.add(KeyUsageType.KEYENCIPHERMENT); keyUsage.add(KeyUsageType.NONREPUDIATION); Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>(); extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH); BigInteger serialNumber = new BigInteger("1178c30016df6384363585b394c6ca6", 16); Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK) .parse("21-November-2007 11:46:35"); certificateBuilder.setSubject(subject); certificateBuilder.setAltNames(altNames, true); certificateBuilder.setKeyUsage(keyUsage, true); // make extended key usage critical certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false); certificateBuilder.setNotBefore(DateUtils.addDays(now, -20)); certificateBuilder.setNotAfter(DateUtils.addYears(now, 20)); certificateBuilder.setPublicKey(publicKey); certificateBuilder.setSerialNumber(serialNumber); certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption"); X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate); assertNotNull(certificate); certificates.add(certificate); Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate }; keyStore.setKeyEntry("NoSMIMEExtKeyUsageNonCritical", privateKey, null, chain); }
From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java
@TargetApi(Build.VERSION_CODES.M) private void loadSecurityPatch() { Preference securityPatchPreference = findPreference(SECURITY_PATCH_KEY); if (!securityPatchPreference.isEnabled()) { return;/*from w w w. j a v a 2 s .co m*/ } String buildSecurityPatch = Build.VERSION.SECURITY_PATCH; final Date date; try { date = new SimpleDateFormat(SECURITY_PATCH_FORMAT).parse(buildSecurityPatch); } catch (ParseException e) { securityPatchPreference.setSummary(getString(R.string.invalid_security_patch, buildSecurityPatch)); return; } String display = DateFormat.getDateInstance(DateFormat.MEDIUM).format(date); securityPatchPreference.setSummary(display); }
From source file:org.hoteia.qalingo.core.web.mvc.factory.BackofficeViewBeanFactory.java
/** * //from w w w . j ava 2 s.c o m */ public PaymentGatewayViewBean buildViewBeanPaymentGateway(final RequestData requestData, final AbstractPaymentGateway paymentGateway) throws Exception { final MarketArea marketArea = requestData.getMarketArea(); final PaymentGatewayViewBean paymentGatewayViewBean = new PaymentGatewayViewBean(); if (paymentGateway != null) { paymentGatewayViewBean.setCode(paymentGateway.getCode()); paymentGatewayViewBean.setName(paymentGateway.getName()); paymentGatewayViewBean.setDescription(paymentGateway.getDescription()); if (Hibernate.isInitialized(paymentGateway.getMarketAreas()) && paymentGateway.getMarketAreas() != null) { paymentGatewayViewBean.setActive(paymentGateway.getMarketAreas().contains(marketArea)); } List<PaymentGatewayAttribute> globalAttributes = paymentGateway.getGlobalAttributes(); if (globalAttributes != null) { for (Iterator<PaymentGatewayAttribute> iterator = globalAttributes.iterator(); iterator .hasNext();) { PaymentGatewayAttribute attribute = (PaymentGatewayAttribute) iterator.next(); paymentGatewayViewBean.getGlobalAttributes().put(attribute.getAttributeDefinition().getCode(), attribute.getValueAsString()); } } List<PaymentGatewayAttribute> marketAreaAttributes = paymentGateway .getMarketAreaAttributes(marketArea.getId()); if (marketAreaAttributes != null) { for (Iterator<PaymentGatewayAttribute> iterator = marketAreaAttributes.iterator(); iterator .hasNext();) { PaymentGatewayAttribute attribute = (PaymentGatewayAttribute) iterator.next(); paymentGatewayViewBean.getMarketAreaAttributes() .put(attribute.getAttributeDefinition().getCode(), attribute.getValueAsString()); } } Set<PaymentGatewayOption> options = paymentGateway.getOptions(); if (options != null) { for (Iterator<PaymentGatewayOption> iterator = options.iterator(); iterator.hasNext();) { PaymentGatewayOption option = (PaymentGatewayOption) iterator.next(); paymentGatewayViewBean.getOptions().put(option.getCode(), option.getOptionValue()); } } DateFormat dateFormat = requestUtil.getCommonFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM); Date dateCreate = paymentGateway.getDateCreate(); if (dateCreate != null) { paymentGatewayViewBean.setDateCreate(dateFormat.format(dateCreate)); } else { paymentGatewayViewBean.setDateCreate(Constants.NOT_AVAILABLE); } Date dateUpdate = paymentGateway.getDateUpdate(); if (dateUpdate != null) { paymentGatewayViewBean.setDateUpdate(dateFormat.format(dateUpdate)); } else { paymentGatewayViewBean.setDateUpdate(Constants.NOT_AVAILABLE); } paymentGatewayViewBean.setDetailsUrl( backofficeUrlService.generateUrl(BoUrls.PAYMENT_GATEWAY_DETAILS, requestData, paymentGateway)); paymentGatewayViewBean.setEditUrl( backofficeUrlService.generateUrl(BoUrls.PAYMENT_GATEWAY_EDIT, requestData, paymentGateway)); } return paymentGatewayViewBean; }
From source file:org.opencms.ade.galleries.CmsGalleryService.java
/** * Builds a single search result list item for the client from a server-side search result.<p> * * @param cms the current CMS context// ww w .ja v a 2s.c o m * @param sResult the server-side search result * @param presetResult the preselected result * * @return the client side search result item * * @throws CmsException if something goes wrong * @throws ParseException if date parsing fails */ private CmsResultItemBean buildSingleSearchResultItem(CmsObject cms, CmsGallerySearchResult sResult, CmsGallerySearchResult presetResult) throws CmsException, ParseException { Locale wpLocale = getWorkplaceLocale(); CmsResultItemBean bean = new CmsResultItemBean(); if (sResult == presetResult) { bean.setPreset(true); } bean.setReleasedAndNotExpired(sResult.isReleaseAndNotExpired(cms)); String path = sResult.getPath(); path = cms.getRequestContext().removeSiteRoot(path); // resource path as id bean.setPath(path); // title String rawTitle = CmsStringUtil.isEmptyOrWhitespaceOnly(sResult.getTitle()) ? CmsResource.getName(sResult.getPath()) : sResult.getTitle(); bean.setTitle(rawTitle); bean.setRawTitle(rawTitle); // resource type bean.setType(sResult.getResourceType()); CmsResource resultResource = cms.readResource(new CmsUUID(sResult.getStructureId()), CmsResourceFilter.ONLY_VISIBLE_NO_DELETED); bean.setDetailResourceType(CmsResourceIcon.getDefaultFileOrDetailType(cms, resultResource)); // structured id bean.setClientId(sResult.getStructureId()); CmsVfsService.addLockInfo(cms, resultResource, bean); String permalinkId = sResult.getStructureId().toString(); String permalink = CmsStringUtil.joinPaths(OpenCms.getSystemInfo().getOpenCmsContext(), CmsPermalinkResourceHandler.PERMALINK_HANDLER, permalinkId); bean.setViewLink(permalink); // set nice resource type name as subtitle I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(sResult.getResourceType()); String resourceTypeDisplayName = CmsWorkplaceMessages.getResourceTypeName(wpLocale, type.getTypeName()); String description = sResult.getDescription(); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(description)) { bean.setDescription(description); bean.addAdditionalInfo( Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_DESCRIPTION_0), description); } else { bean.setDescription(resourceTypeDisplayName); } bean.setUserLastModified(sResult.getUserLastModified()); Date lastModDate = sResult.getDateLastModified(); String formattedDate = lastModDate != null ? CmsDateUtil.getDateTime(lastModDate, DateFormat.MEDIUM, wpLocale) : ""; bean.setDateLastModified(formattedDate); if (!type.getTypeName().equals(CmsResourceTypeImage.getStaticTypeName())) { bean.addAdditionalInfo( Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_RESOURCE_TYPE_0), resourceTypeDisplayName); } if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(sResult.getExcerpt())) { bean.addAdditionalInfo( Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_EXCERPT_0), sResult.getExcerpt(), CmsListInfoBean.CSS_CLASS_MULTI_LINE); } if (type instanceof CmsResourceTypeImage) { CmsProperty copyrightProp = cms.readPropertyObject(resultResource, CmsPropertyDefinition.PROPERTY_COPYRIGHT, false); if (!copyrightProp.isNullProperty()) { bean.addAdditionalInfo( Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_COPYRIGHT_0), copyrightProp.getValue()); } CmsProperty imageDimensionProp = cms.readPropertyObject(resultResource, CmsPropertyDefinition.PROPERTY_IMAGE_SIZE, false); if (!imageDimensionProp.isNullProperty()) { String dimensions = imageDimensionProp.getValue(); dimensions = dimensions.substring(2).replace(",h:", " x "); bean.setDimension(dimensions); bean.addAdditionalInfo( Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_DIMENSION_0), dimensions); } } if (type instanceof CmsResourceTypeXmlContent) { CmsProperty elementModelProperty = cms.readPropertyObject(resultResource, CmsPropertyDefinition.PROPERTY_ELEMENT_MODEL, true); if (!elementModelProperty.isNullProperty()) { if (Boolean.valueOf(elementModelProperty.getValue()).booleanValue()) { bean.setIsCopyModel(true); } } } if (CmsResourceTypeXmlContainerPage.isModelReuseGroup(cms, resultResource)) { bean.setPseudoType(CmsGwtConstants.TYPE_MODELGROUP_REUSE); } bean.setResourceState(resultResource.getState()); bean.addAdditionalInfo(Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_SIZE_0), (sResult.getLength() / 1000) + " kb"); if (lastModDate != null) { bean.addAdditionalInfo( Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_DATE_CHANGED_0), CmsDateUtil.getDate(lastModDate, DateFormat.SHORT, getWorkplaceLocale())); } if ((sResult.getDateExpired().getTime() != CmsResource.DATE_EXPIRED_DEFAULT) && !sResult.getDateExpired().equals(CmsSearchFieldMapping.getDefaultDateExpired())) { bean.addAdditionalInfo( Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_RESULT_LABEL_DATE_EXPIRED_0), CmsDateUtil.getDate(sResult.getDateExpired(), DateFormat.SHORT, getWorkplaceLocale())); } bean.setNoEditReson(new CmsResourceUtil(cms, resultResource) .getNoEditReason(OpenCms.getWorkplaceManager().getWorkplaceLocale(cms))); bean.setMarkChangedState(true); return bean; }
From source file:mitm.common.security.certificate.GenerateTestCertificates.java
/** * Generates a certificate that is valid after 2027 * /*from ww w .jav a2s. c om*/ * @throws Exception */ private void generateCertificateNoYetValid() throws Exception { X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder(); String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d00308189028181009f" + "b353317a507e1ce39272bc304111f8558ee76c16200464a98c6737c74059" + "5bfc72f5647799641da2bc7a629c1ac00da10f26da0f8a83c84e09eb68cc" + "d666e92f04f953722956c5f0cc2263c1d8c78c792aa91d53ad5df8616372" + "5db07065eb043fd4587dafdab1aff5bb21854525b49ece5eda2bb7c37d8b" + "b06c4e559efb230203010001"; String encodedPrivateKey = "30820277020100300d06092a864886f70d0101010500048202613082025d" + "020100028181009fb353317a507e1ce39272bc304111f8558ee76c162004" + "64a98c6737c740595bfc72f5647799641da2bc7a629c1ac00da10f26da0f" + "8a83c84e09eb68ccd666e92f04f953722956c5f0cc2263c1d8c78c792aa9" + "1d53ad5df86163725db07065eb043fd4587dafdab1aff5bb21854525b49e" + "ce5eda2bb7c37d8bb06c4e559efb2302030100010281806c96b090ca0c85" + "53fb618ee66b2133a8d9f44b63713fdffcda547fb2aba7139bba72286d61" + "ed48e7e5c9a6a5fa632e0796660912e8d2547d14a32610a2877e7d28925c" + "5f36025ef20c920ea380fe07fc44ffa3648991e511b6185a4105c229cde1" + "2be13929826bf4c55600dff4ce9a57df7422d0849f8c99ebd208dff3ce52" + "41024100d438b326a633789279d133fe742c91973879d652804ba1bbbd95" + "aa72beef2082a109e5ee4426cece04ae0d9091e36e0afbe02489f98d86f5" + "b39d4fcaea795491024100c0a5052b52e885e6a5e4444b686f4697def8dc" + "6b6913d211c3f38e87de4f7d395adedf4cd4827458947509aacaec6fb643" + "c31820bf41cb6b210ba0adac651e73024003a0746f54a7cc87b44d3ef63a" + "4608b6ece0282980c7ca1bcb41a388127b43b2f7cd93805ee9cadefa757f" + "05d97869890684ee1aed88dda5954c3af0dcd0f601024100be1e9df961bb" + "44da9a01ab3cd876692edcc8b18ff785ae1e064ac9f160ff05d0a2d3ad80" + "bf81779d2bf64d72170e3c399eaa5d9783e944fe1700c8b45d9cf5ed0241" + "00a1152fdcaa1f14bdd0c26c14feeb9e3e3627db371a4bb00afceb8ccebd" + "21a6e27f45fce087da5c029e1be352bbdd7ffbec8e511ea254df76a7ff19" + "4e262c16c0"; PrivateKey privateKey = decodePrivateKey(encodedPrivateKey); PublicKey publicKey = decodePublicKey(encodedPublicKey); X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder(); String email = "test@example.com"; subjectBuilder.setCommonName("Not yet valid"); subjectBuilder.setEmail(email); subjectBuilder.setCountryCode("NL"); subjectBuilder.setLocality("Amsterdam"); subjectBuilder.setState("NH"); AltNamesBuilder altNamesBuider = new AltNamesBuilder(); altNamesBuider.setRFC822Names(email); X500Principal subject = subjectBuilder.buildPrincipal(); GeneralNames altNames = altNamesBuider.buildAltNames(); Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>(); keyUsage.add(KeyUsageType.DIGITALSIGNATURE); keyUsage.add(KeyUsageType.KEYENCIPHERMENT); keyUsage.add(KeyUsageType.NONREPUDIATION); Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>(); extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH); extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION); BigInteger serialNumber = new BigInteger("115fd064f8eac4ed5dd5e8728b36fd6", 16); Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK) .parse("21-Nov-2007 11:49:35"); certificateBuilder.setSubject(subject); certificateBuilder.setAltNames(altNames, true); certificateBuilder.setKeyUsage(keyUsage, true); certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false); certificateBuilder.setNotBefore(DateUtils.addYears(now, 20)); certificateBuilder.setNotAfter(DateUtils.addYears(now, 30)); certificateBuilder.setPublicKey(publicKey); certificateBuilder.setSerialNumber(serialNumber); certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption"); X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate); assertNotNull(certificate); certificates.add(certificate); Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate }; keyStore.setKeyEntry("NotYetValid", privateKey, null, chain); }