List of usage examples for org.apache.shiro.authc.credential DefaultPasswordService getHashService
public HashService getHashService()
From source file:br.com.criativasoft.opendevice.middleware.persistence.dao.jpa.UserJPA.java
License:Open Source License
@Override public User createUser(Account account, String username, String password) { User user = new User(); user.setUsername(username);//from ww w. ja va 2 s. c om user.setPassword(password); //Encrypt DefaultPasswordService service = new DefaultPasswordService(); DefaultHashService hashService = (DefaultHashService) service.getHashService(); hashService.setHashIterations(1); user.setPassword(service.encryptPassword(user.getPassword())); UserAccount userAccount = new UserAccount(); userAccount.setOwner(account); account.getUserAccounts().add(userAccount); if (account.getId() <= 0) userAccount.setType(AccountType.ACCOUNT_MANAGER); else userAccount.setType(AccountType.USER); userAccount.setUser(user); ApiKey key = new ApiKey(); key.setKey(account.getUuid()); key.setAppName("ApplicationID"); key.setAccount(userAccount); userAccount.getKeys().add(key); user.getAccounts().add(userAccount); persist(user); return user; }
From source file:io.opendevice.sonoff.SonOffRest.java
License:Open Source License
private void createDeviceAccount(String odevKey, String deviceID, String deviceApiKey) { Injector injector = GuiceInjectProvider.getInjector(); AccountDao accountDao = injector.getProvider(AccountDao.class).get(); UserDao userDao = injector.getProvider(UserDao.class).get(); Account account = accountDao.getAccountByApiKey(odevKey); if (account == null) { throw new NotFoundException("Account not found !"); }//ww w . j a va 2s. c o m ApiKey key = accountDao.findKey("SonOff", deviceApiKey); if (key == null) { BaseDeviceManager.getInstance().transactionBegin(); log.info("Creating new User/Key for Sonoff : " + deviceID); //Encrypt DefaultPasswordService service = new DefaultPasswordService(); DefaultHashService hashService = (DefaultHashService) service.getHashService(); hashService.setHashIterations(1); key = new ApiKey("SonOff", deviceApiKey); User user = new User("SonOff-" + deviceID, deviceApiKey); user.setPassword(service.encryptPassword(user.getPassword())); UserAccount userAccount = new UserAccount(); userAccount.setType(AccountType.DEVICE); userAccount.setOwner(account); userAccount.setUser(user); userAccount.getKeys().add(key); user.getAccounts().add(userAccount); key.setAccount(userAccount); userDao.persist(user); BaseDeviceManager.getInstance().transactionEnd(); } }
From source file:net.maritimecloud.portal.infrastructure.security.shiro.MaritimeCloudIdentityRealmTest.java
License:Apache License
@Test public void testSomeMethod() { // ApplicationServiceRegistry.identityApplicationService(); String submittedPlaintextPassword = "secret"; DefaultPasswordService passwordService = new DefaultPasswordService(); ((DefaultHashService) passwordService.getHashService()).setHashAlgorithmName("SHA-512"); String encryptedValue = passwordService.encryptPassword(submittedPlaintextPassword); System.out.println("" + encryptedValue); }