/** * Searches for a user with the given userId. If no user is found we throw an {@link InvalidParameterValueException}. */ protected UserVO retrieveAndValidateUser(UpdateUserCmd updateUserCmd) { Long userId = updateUserCmd.getId(); UserVO user = _userDao.getUser(userId); if (user == null) { throw new InvalidParameterValueException("Unable to find user with id: " + userId); } return user; }
domainUser = userDAO.getUser(login);
@Override public boolean isUserAuthorized(Long userId, String entityId) { UserVO user = _userDao.getUser(userId); if (user != null) { if (user.getSource().equals(User.Source.SAML2) && user.getExternalEntity().equalsIgnoreCase(entityId)) { return true; } } return false; }
private void enableAdminUser(final String password) { String encodedPassword = null; final UserVO adminUser = _userDao.getUser(2); if (adminUser == null) { final String msg = "CANNOT find admin user"; s_logger.error(msg); throw new CloudRuntimeException(msg); } if (adminUser.getState() == Account.State.disabled) { // This means its a new account, set the password using the // authenticator for (final UserAuthenticator authenticator : _userPasswordEncoders) { encodedPassword = authenticator.encode(password); if (encodedPassword != null) { break; } } adminUser.setPassword(encodedPassword); adminUser.setState(Account.State.enabled); _userDao.persist(adminUser); s_logger.info("Admin user enabled"); } }
@Override public Pair<Boolean, ActionOnFailedAuthentication> authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters) { if (s_logger.isDebugEnabled()) { s_logger.debug("Trying SAML2 auth for user: " + username); } if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { s_logger.debug("Username or Password cannot be empty"); return new Pair<Boolean, ActionOnFailedAuthentication>(false, null); } final UserAccount userAccount = _userAccountDao.getUserAccount(username, domainId); if (userAccount == null || userAccount.getSource() != User.Source.SAML2) { s_logger.debug("Unable to find user with " + username + " in domain " + domainId + ", or user source is not SAML2"); return new Pair<Boolean, ActionOnFailedAuthentication>(false, null); } else { User user = _userDao.getUser(userAccount.getId()); if (user != null && user.getSource() == User.Source.SAML2 && user.getExternalEntity() != null) { return new Pair<Boolean, ActionOnFailedAuthentication>(true, null); } } // Deny all by default return new Pair<Boolean, ActionOnFailedAuthentication>(false, ActionOnFailedAuthentication.INCREMENT_INCORRECT_LOGIN_ATTEMPT_COUNT); }
User creditorUser = _userDao.getUser(updatedBy); if (creditorUser != null) { creditor = creditorUser.getUsername();
@Override public boolean authorizeUser(Long userId, String entityId, boolean enable) { UserVO user = _userDao.getUser(userId); if (user != null) { if (enable) { user.setExternalEntity(entityId); user.setSource(User.Source.SAML2); } else { if (user.getSource().equals(User.Source.SAML2)) { user.setSource(User.Source.SAML2DISABLED); } else { return false; } } _userDao.update(user.getId(), user); return true; } return false; }
@Service @Transactional public class UserServiceImpl implements UserService { @Autowired private UserDao userDao; @Override public User getUser(final String username) { return userDao.getUser(username); } }
@Override public void execute() { List<UserVO> users = new ArrayList<UserVO>(); if (getUserId() != null) { UserVO user = _userDao.getUser(getUserId()); if (user != null) { Account account = _accountService.getAccount(user.getAccountId()); _accountService.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.ListEntry, true, account); users.add(user); } } else if (CallContext.current().getCallingAccount().getType() == Account.ACCOUNT_TYPE_ADMIN) { users = _userDao.listAll(); } ListResponse<SamlAuthorizationResponse> response = new ListResponse<SamlAuthorizationResponse>(); List<SamlAuthorizationResponse> authorizationResponses = new ArrayList<SamlAuthorizationResponse>(); for (User user: users) { SamlAuthorizationResponse authorizationResponse = new SamlAuthorizationResponse(user.getUuid(), user.getSource().equals(User.Source.SAML2), user.getExternalEntity()); authorizationResponse.setObjectName("samlauthorization"); authorizationResponses.add(authorizationResponse); } response.setResponses(authorizationResponses); response.setResponseName(getCommandName()); setResponseObject(response); } }
@Autowired private UserDao userDao; @RequestMapping(method = RequestMethod.GET, value="/{userId}", produces = {MediaType.APPLICATION_JSON_VALUE}) ResponseEntity<User> getUser(@PathVariable int userId){ User u = userDao.getUser(userId); return new ResponseEntity<User>(u, HttpStatus.OK); }
@Controller @RequestMapping("/authenticate") public class LoginController { @Resource UserDao userDao; @RequestMapping("/index") public String index() { System.out.println(userDao.getUser(1).getPassword()); return "Login"; } }
List<SamlUserAccountResponse> accountResponses = new ArrayList<SamlUserAccountResponse>(); for (UserAccountVO userAccount: switchableAccounts) { User user = _userDao.getUser(userAccount.getId()); Domain domain = _domainService.getDomain(userAccount.getDomainId()); SamlUserAccountResponse accountResponse = new SamlUserAccountResponse();
User user = _userDao.getUser(userVm.getUserId()); if (user != null) { userVmResponse.setUserId(user.getUuid());