Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- */
- public String login() {
- UserAuth userAuth = new UserAuth();
- userAuth.setUserName(username);
- userAuth.setPassword(password);
- try {
- EntryValue loginRes = wsClient.login(userAuth, Class.class.getName(), new NameValueList());
- return loginRes.getId();
- } catch (Exception e) {
- throw new RuntimeException(e.getMessage());
- }
- // if (!loginRes.getError().getNumber().equals("0")) {
- // throw new RuntimeException("Error login to SugarCRM:" + " " + loginRes.getError().getNumber() + " " + loginRes.getError().getName() + " " + loginRes.getError().getDescription());
- // }
- }
- /**
- * @param data
- * @return
- * @throws Exception
- */
- private String getHexString(byte[] data) throws Exception {
- StringBuffer buf = new StringBuffer();
- for (int i = 0; i < data.length; i++) {
- int halfbyte = (data[i] >>> 4) & 0x0F;
- int two_halfs = 0;
- do {
- if ((0 <= halfbyte) && (halfbyte <= 9))
- buf.append((char) ('0' + halfbyte));
- else
- buf.append((char) ('a' + (halfbyte - 10)));
- halfbyte = data[i] & 0x0F;
- } while (two_halfs++ < 1);
- }
- return buf.toString();
- }
- /**
- * @param password
- * @throws Exception
- */
- public void setPassword(String password) throws Exception {
- MessageDigest md = MessageDigest.getInstance("MD5");
- this.password = getHexString(md.digest(password.getBytes()));
- }
- /**
- * @param username
- */
- public void setUsername(String username) {
- this.username = username;
- }
- /**
- * @param wsClient
- */
- public void setWsClient(SugarsoapPortType wsClient) {
- this.wsClient = wsClient;
- }
Add Comment
Please, Sign In to add comment