You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shiro.apache.org by "Harry Metske (JIRA)" <ji...@apache.org> on 2016/05/04 10:10:12 UTC

[jira] [Commented] (SHIRO-545) JavaEnvironment version getter

    [ https://issues.apache.org/jira/browse/SHIRO-545?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15270294#comment-15270294 ] 

Harry Metske commented on SHIRO-545:
------------------------------------

This also breaks the shiro tools hasher:

{noformat}
java -jar ~/shiro-tools-hasher-1.2.4-cli.jar -p

Error: Password hashing (prompt without echo) uses the java.io.Console to read passwords safely.  This is only available on Java 1.6 platforms and later.

Specify -d or --debug for more information.
{noformat}


> JavaEnvironment version getter
> ------------------------------
>
>                 Key: SHIRO-545
>                 URL: https://issues.apache.org/jira/browse/SHIRO-545
>             Project: Shiro
>          Issue Type: Bug
>          Components: Cryptography & Hashing
>    Affects Versions: 1.2.4
>         Environment: Java 8
>            Reporter: Ariel Isaac
>            Priority: Minor
>              Labels: easyfix, newbie, patch
>             Fix For: 1.3.0, 2.0.0, 1.2.5
>
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> If Shiro is running in Java 8 it assumes that the major version is 1.3, because this case it's not included in the if blocks and goes to the default version which is 1.3, also the " if (version.indexOf("1.7.") != -1) {" should be contains, instead of indexOf, contains is highly more readable, so the code should be something like 
> ..*/
> {code:title=JavaEnvironment.java|borderStyle=solid}
> /**
>      * Constant identifying the 1.8 JVM.
>      */
>     public static final int JAVA_18 = 5;
>     /** The virtual machine version, i.e. <code>System.getProperty("java.version");</code>. */
>     private static final String version;
>     /**
>      * The virtual machine <em>major</em> version.  For example, with a <code>version</code> of
>      * <code>1.5.6_10</code>, this would be <code>1.5</code>
>      */
>     private static final int majorVersion;
>     /**
>      * Static code initialization block that sets the
>      * <code>version</code> and <code>majorVersion</code> Class constants
>      * upon initialization.
>      */
>     static {
>         version = System.getProperty("java.version");
>         // version String should look like "1.4.2_10"
>         if (version.contains("1.8.")) {
>             majorVersion = JAVA_18;
>         } else if (version.contains("1.7")){
>             majorVersion = JAVA_17;
>         } else if (version.contains("1.6.")) {
>             majorVersion = JAVA_16;
>         } else if (version.contains("1.5.")) {
>             majorVersion = JAVA_15;
>         } else if (version.contains("1.4.")) {
>             majorVersion = JAVA_14;
>         } else {
>             // else leave 1.3 as default (it's either 1.3 or unknown)
>             majorVersion = JAVA_13;
>         }
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)