[Yanel-dev] Migrating from Java 8 to Java 9 - Base 64

Michael Wechner michael.wechner at wyona.com
Thu Mar 15 11:47:10 EDT 2018


Dear Balz

I have tested the changes with Java 1.8 and it works very fine. So I
have merged the changes into the master branch and increased the minimal
Java version to 1.8.

Before I did that, I have created a branch called

jdk_1.6_DO_NOT_TOUCH

which should help in case something does not work as expected.

All the best

Michael


Am 05.03.18 um 18:10 schrieb Michael Wechner:
> Dear Balz
>
> I have no committed the Base64 improvements inside the branch
> "base64", whereas I have made the following changes:
>
> git diff master..base64
> diff --git
> a/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java
> b/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java
> index a65c9df..2f1bac5 100644
> --- a/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java
> +++ b/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java
> @@ -2007,7 +2007,7 @@ public class YanelServlet extends HttpServlet {
>          }
>  */
>  
> -        // HTTP BASIC Authentication (For clients such as for
> instance Sunbird, OpenOffice or cadaver)
> +        // HTTP BASIC Authentication (For clients such as for
> instance Thunderbird Lightning, OpenOffice or cadaver)
>          // IMPORT NOTE: BASIC Authentication needs to be checked on
> every request, because clients often do not support session handling
>          String authorizationHeader = request.getHeader("Authorization");
>          if (log.isDebugEnabled()) log.debug("No identity attached to
> session, hence check request authorization header: " +
> authorizationHeader);
> @@ -2015,10 +2015,17 @@ public class YanelServlet extends HttpServlet {
>              if (authorizationHeader.toUpperCase().startsWith("BASIC")) {
>                  // Get encoded user and password, comes after "BASIC "
>                  String userpassEncoded =
> authorizationHeader.substring(6);
> -                // Decode it, using any base 64 decoder
> -                sun.misc.BASE64Decoder dec = new
> sun.misc.BASE64Decoder();
> -                String userpassDecoded = new
> String(dec.decodeBuffer(userpassEncoded));
> -                log.debug("Username and Password Decoded: " +
> userpassDecoded);
> +                // INFO: Decode it, using base 64 decoder
> +  
> +                // DEPRECATED
> +                //sun.misc.BASE64Decoder dec = new
> sun.misc.BASE64Decoder();
> +                //String userpassDecoded = new
> String(dec.decodeBuffer(userpassEncoded));
> +
> +                java.util.Base64.Decoder decoder =
> java.util.Base64.getMimeDecoder();
> +                String userpassDecoded = new
> String(decoder.decode(userpassEncoded));
> +
> +                log.debug("Username and Password decoded: " +
> userpassDecoded);
> +
>                  String[] up = userpassDecoded.split(":");
>                  String username = up[0];
>                  String password = up[1];
>
>
> It works for me locally with Java 8, testing BASIC authentication (for
> example Thuderbird Calendar/Lightning).
>
> Will test it later today on Java 9.
>
> All the best
>
> Michael
>
> Am 05.03.18 um 15:02 schrieb Michael Wechner:
>> Dear Balz
>>
>> Am 05.03.18 um 10:18 schrieb basZero:
>>> Dear Michael,
>>>
>>> sounds good, but can you explain the reason why you upgrade to Java 9?
>>> I think it only makes sense to upgrade, if you also upgrade to
>>> Tomcat 9 (see http://tomcat.apache.org/whichversion.html )
>>
>> Because the laptop of my son is using Java 9 :-)
>>
>>> If somebody runs Yanel on Tomcat 8, Yanel won't work anymore.
>>
>> why not? I am not sure anymore whether you mentioned that before, but
>> if so, can you tell me once again.
>>>
>>> In general, I'd appreciate a lot if Yanel would provide a branch for
>>> each tomcat version.
>>> The master branch will still (as today) contain the very latest code
>>> and yanel users can choose what they want.
>>>
>>> So before you make the upgrade, please create a branch tomcat8 (or
>>> something like that) so that the current tomcat8 version before your
>>> upgrade is still easily available in future
>>
>> The only difference will be the Base64 implementation inside
>> YanelServlet, so I think it will be backwards compatible.
>>
>> I will make a branch first anyway and let you know, such that you can
>> test it as well.
>>
>> All the best
>>
>> Michael
>>>
>>> Cheers
>>> Balz
>>>
>>> On Sun, Mar 4, 2018 at 1:12 PM, Michael Wechner
>>> <michael.wechner at wyona.com> wrote:
>>>
>>>     Hi
>>>
>>>     I noticed that Java 9 on Mac does not provide anymore
>>>     sun.misc.BASE64Decoder and that we have to replace it by
>>>     java.util.Base64
>>>
>>>     -                sun.misc.BASE64Decoder dec = new
>>>     sun.misc.BASE64Decoder();
>>>     -                String userpassDecoded = new
>>>     String(dec.decodeBuffer(userpassEncoded));
>>>     +                //sun.misc.BASE64Decoder dec = new
>>>     sun.misc.BASE64Decoder();
>>>     +                //String userpassDecoded = new
>>>     String(dec.decodeBuffer(userpassEncoded));
>>>     +                // TODO: Migrate to java.util.Base64
>>>     +                java.util.Base64.Decoder decoder =
>>>     java.util.Base64.getMimeDecoder();
>>>     +                String userpassDecoded = new
>>>     String(decoder.decode(userpassEncoded));
>>>
>>>     I am currently testing this and if successful, would like to replace
>>>     it...also see
>>>
>>>     https://stackoverflow.com/questions/35301409/migrating-from-sun-misc-base64-to-java-8-java-util-base64
>>>     <https://stackoverflow.com/questions/35301409/migrating-from-sun-misc-base64-to-java-8-java-util-base64>
>>>
>>>     Any objections?
>>>
>>>     All the best
>>>
>>>     Michael
>>>     --
>>>     Yanel-development mailing list Yanel-development at wyona.com
>>>     http://mx2.wyona.com/cgi-bin/mailman/listinfo/yanel-development
>>>     <http://mx2.wyona.com/cgi-bin/mailman/listinfo/yanel-development>
>>>
>>>
>>>
>>>
>>
>>
>>
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mx2.wyona.com/pipermail/yanel-development/attachments/20180315/99cbfd10/attachment.html>


More information about the Yanel-development mailing list