Package org.apache.shiro.crypto.hash

Examples of org.apache.shiro.crypto.hash.Sha256Hash


    public void updateUser(User user) {
        Assert.isTrue( userId.equals( user.getId() ), "User ID of command must match the user being updated." );
        user.setUsername( getUsername() );
        user.setEmail( getEmail() );
        if( StringUtils.hasText(getPassword()) ) {
            user.setPassword( new Sha256Hash(getPassword()).toHex() );
        }
    }
View Full Code Here


        JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);

        jdbcTemplate.execute("insert into roles values (1, 'user', 'The default role given to all users.')");
        jdbcTemplate.execute("insert into roles values (2, 'admin', 'The administrator role only given to site admins')");
        jdbcTemplate.execute("insert into roles_permissions values (2, 'user:*')");
        jdbcTemplate.execute("insert into users(id,username,email,password) values (1, 'admin', 'sample@shiro.apache.org', '" + new Sha256Hash("admin").toHex() + "')");
        jdbcTemplate.execute("insert into users_roles values (1, 2)");


    }
View Full Code Here

        //password is 'user1' SHA hashed and base64 encoded:
        //The first argument to the hash constructor is the actual value to be hased.  The 2nd is the
        //salt.  In this simple demo scenario, the username and the password are the same, but to clarify the
        //distinction, you would see this in practice:
        //new Sha256Hash( <password>, <username> )
        String query = "insert into users values ('user1', '" + new Sha256Hash("user1", "user1").toBase64() + "' )";
        jdbcTemplate.execute(query);
        log.debug("Created user1.");

        //password is 'user2' SHA hashed and base64 encoded:
        query = "insert into users values ( 'user2', '" + new Sha256Hash("user2", "user2").toBase64() + "' )";
        jdbcTemplate.execute(query);
        log.debug("Created user2.");

        query = "insert into roles values ( 'role1' )";
        jdbcTemplate.execute(query);
View Full Code Here

     * Creates a new <em>uninitialized</em> {@link Sha256Hash Sha256Hash} instance, without it's byte array set.
     *
     * @return a new <em>uninitialized</em> {@link org.apache.shiro.crypto.hash.Sha256Hash Sha256Hash} instance, without it's byte array set.
     */
    protected AbstractHash newHashInstance() {
        return new Sha256Hash();
    }
View Full Code Here

    /**
     * This implementation merely returns
     * <code>new {@link Sha256Hash#Sha256Hash(Object, Object, int) Sha256Hash(credentials,salt,hashIterations)}</code>.
     */
    protected Hash hashProvidedCredentials(Object credentials, Object salt, int hashIterations) {
        return new Sha256Hash(credentials, salt, hashIterations);
    }
View Full Code Here

    public Class<? extends HashedCredentialsMatcher> getMatcherClass() {
        return Sha256CredentialsMatcher.class;
    }

    public AbstractHash hash(Object credentials) {
        return new Sha256Hash(credentials);
    }
View Full Code Here

        main.put("credentialsMatcher", "org.apache.shiro.authc.credential.Sha256CredentialsMatcher");
        main.put("iniRealm.credentialsMatcher", "$credentialsMatcher");

        //create a users section - user 'admin', with a Sha256-hashed 'admin' password (hex encoded):
        Ini.Section users = ini.addSection(IniRealm.USERS_SECTION_NAME);
        users.put("admin", new Sha256Hash("secret").toString());

        IniSecurityManagerFactory factory = new IniSecurityManagerFactory(ini);
        SecurityManager sm = factory.getInstance();

        //go ahead and try to log in with the admin user, ensuring the
View Full Code Here

        passwords.put(""username_here, encrypt("password_here"));
        roles.put("username_here", "role_here");
    }
  private static String encrypt(String password) {
        return new Sha256Hash(password).toString();
    }
View Full Code Here

    Assert.isTrue(userId.equals(user.getId()),
        "User ID of command must match the user being updated.");
    user.setUsername(getUsername());
    user.setEmail(getEmail());
    if (StringUtils.hasText(getPassword())) {
      user.setPassword(new Sha256Hash(getPassword()).toHex());
    }
  }
View Full Code Here

    public void createUser(String username, String email, String password) {
        User user = new User();
        user.setUsername(username);
        user.setEmail(email);
        user.setPassword( new Sha256Hash(password).toHex() );
        userDAO.createUser( user );
    }
View Full Code Here

TOP

Related Classes of org.apache.shiro.crypto.hash.Sha256Hash

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.