List of usage examples for org.apache.commons.codec Decoder decode
Object decode(Object source) throws DecoderException;
From source file:com.github.jinahya.codec.commons.RareDecoderProxyTest.java
@Test public void testAsDecoder() throws DecoderException { final Decoder decoder = (Decoder) RareDecoderProxy.newInstance(); try {//from ww w. ja va 2 s . c om decoder.decode(null); Assert.fail("passed: <Object>decode(null)"); } catch (final NullPointerException npe) { // expected } final Object expected = new Object(); final Object actual = decoder.decode(expected); Assert.assertEquals(actual, expected); }
From source file:com.github.jinahya.codec.commons.RareBinaryDecoderProxyTest.java
@Test public void testAsDecoder() throws DecoderException { final Decoder decoder = (Decoder) RareBinaryDecoderProxy.newInstance(); try {// w w w .j a v a 2s . co m decoder.decode(null); Assert.fail("passed.<Object>decode(null)"); } catch (final NullPointerException npe) { // expected } final Object expected = new byte[0]; final Object actual = decoder.decode(expected); Assert.assertEquals(actual, expected); }
From source file:com.github.jinahya.codec.HexBinaryDecoderProxyTest.java
@Test public void testAsDecoder() throws DecoderException { final Decoder decoder = (Decoder) HexBinaryDecoderProxy.newInstance(); try {/*from w w w . j a va 2 s. com*/ decoder.decode(null); Assert.fail("decode(null)"); } catch (final NullPointerException npe) { // expected } final Object encoded = Tests.encodedBytes(); final Object decoded = decoder.decode(encoded); }
From source file:com.github.jinahya.codec.commons.RareStringDecoderProxyTest.java
@Test public void testAsDecoder() throws DecoderException { final Decoder decoder = (Decoder) RareStringDecoderProxy.newInstance(); try {// ww w . j a va 2 s.c om decoder.decode((Object) null); Assert.fail("passed: decode((Object) null)"); } catch (final NullPointerException npe) { // expected } try { decoder.decode(new Object()); Assert.fail("passed: decode(new Object())"); } catch (final DecoderException de) { // expected; } final Object expected = ""; final Object actual = decoder.decode(expected); Assert.assertEquals(actual, expected); }
From source file:com.github.jinahya.codec.PercentBinaryDecoderProxyTest.java
@Test public void testAsDecoder() throws Exception { final Decoder decoder = (Decoder) PercentBinaryDecoderProxy.newInstance(); try {/*from w w w .j av a2 s. c o m*/ decoder.decode((Object) null); Assert.fail("passed: decode((Object) null)"); } catch (NullPointerException npe) { // ok } final Object input = PercentCodecTestHelper.encodedBytes(1024); final Object output = decoder.decode(input); }
From source file:org.apache.archiva.web.rss.RssFeedServlet.java
/** * Basic authentication.//from ww w. jav a 2 s . co m * * @param req * @param repositoryId TODO * @param groupId TODO * @param artifactId TODO * @return */ private boolean isAllowed(HttpServletRequest req, String repositoryId, String groupId, String artifactId) throws UserNotFoundException, AccountLockedException, AuthenticationException, MustChangePasswordException, UnauthorizedException { String auth = req.getHeader("Authorization"); List<String> repoIds = new ArrayList<>(); if (repositoryId != null) { repoIds.add(repositoryId); } else if (artifactId != null && groupId != null) { if (auth != null) { if (!auth.toUpperCase().startsWith("BASIC ")) { return false; } Decoder dec = new Base64(); String usernamePassword = ""; try { usernamePassword = new String((byte[]) dec.decode(auth.substring(6).getBytes())); } catch (DecoderException ie) { log.warn("Error decoding username and password: {}", ie.getMessage()); } if (usernamePassword == null || usernamePassword.trim().equals("")) { repoIds = getObservableRepos(UserManager.GUEST_USERNAME); } else { String[] userCredentials = usernamePassword.split(":"); repoIds = getObservableRepos(userCredentials[0]); } } else { repoIds = getObservableRepos(UserManager.GUEST_USERNAME); } } else { return false; } for (String repoId : repoIds) { try { AuthenticationResult result = httpAuth.getAuthenticationResult(req, null); SecuritySession securitySession = httpAuth.getSecuritySession(req.getSession(true)); if (servletAuth.isAuthenticated(req, result) // && servletAuth.isAuthorized(req, // securitySession, // repoId, // ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS)) { return true; } } catch (AuthorizationException e) { log.debug("AuthorizationException for repoId: {}", repoId); } catch (UnauthorizedException e) { log.debug("UnauthorizedException for repoId: {}", repoId); } } throw new UnauthorizedException("Access denied."); }
From source file:org.apache.maven.archiva.web.ras.RasSearchByKeyword.java
/** * Basic authentication./*ww w. ja v a 2 s .c o m*/ * * @param req * @param repositoryId TODO * @param groupId TODO * @param artifactId TODO * @return */ private boolean isAllowed(HttpServletRequest req, String repositoryId, String groupId, String artifactId) throws UserNotFoundException, AccountLockedException, AuthenticationException, MustChangePasswordException, UnauthorizedException { String auth = req.getHeader("Authorization"); List<String> repoIds = new ArrayList<String>(); if (repositoryId != null) { repoIds.add(repositoryId); } else if (artifactId != null && groupId != null) { if (auth != null) { if (!auth.toUpperCase().startsWith("BASIC ")) { return false; } Decoder dec = new Base64(); String usernamePassword = ""; try { usernamePassword = new String((byte[]) dec.decode(auth.substring(6).getBytes())); } catch (DecoderException ie) { log.warn("Error decoding username and password.", ie.getMessage()); } if (usernamePassword == null || usernamePassword.trim().equals("")) { repoIds = getObservableRepos(archivaXworkUser.getGuest()); } else { String[] userCredentials = usernamePassword.split(":"); repoIds = getObservableRepos(userCredentials[0]); } } else { repoIds = getObservableRepos(archivaXworkUser.getGuest()); } } else { return false; } for (String repoId : repoIds) { try { AuthenticationResult result = httpAuth.getAuthenticationResult(req, null); SecuritySession securitySession = httpAuth.getSecuritySession(); if (servletAuth.isAuthenticated(req, result) && servletAuth.isAuthorized(req, securitySession, repoId, false)) { return true; } } catch (AuthorizationException e) { } catch (UnauthorizedException e) { } } throw new UnauthorizedException("Access denied."); }