Github user svarnau commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/911#discussion_r95625541
  
    --- Diff: core/rest/src/main/java/org/trafodion/rest/util/Token.java ---
    @@ -0,0 +1,194 @@
    +package org.trafodion.rest.util;
    +
    +import java.util.Date;
    +
    +import java.security.Key;
    +
    +import javax.crypto.Cipher;
    +
    +public class Token {
    +
    +    public static String error_invalid_request = "invalid_request";
    +    public static String error_invalid_client = "invalid_client";
    +    public static String error_invalid_grant = "invalid_grant";
    +    public static String error_unauthorized_client = "unauthorized_client";
    +    public static String error_unsupported_grant_type = 
"unsupported_grant_type";
    +    public static String error_invalid_scope = "invalid_scope";
    +
    +    public static String error = "error";
    +    public static String error_description = "error_description";
    +    public static String error_uri = "error_uri";
    +
    +    public static String access_token = "access_token";
    +    public static String token_type = "token_type";
    +    public static String expires_in = "expires_in";
    +
    +    public static String error_invalid_token = "error_invalid_token";
    +
    +    private String passwd = "fuck-trafodion!";
    +    private String token = "";
    +    private String interval = "7200000";
    +
    +    public String getInterval() {
    +        return interval;
    +    }
    +
    +    public void setInterval(String interval) {
    +        this.interval = interval;
    +    }
    +
    +    public String getPasswd() {
    +        return passwd;
    +    }
    +
    +    public void setPasswd(String passwd) {
    +        this.passwd = passwd;
    +    }
    +
    +    public String getToken() {
    +        this.token = encode();
    +        return this.token;
    +    }
    +
    +    public void setToken(String token) {
    +        this.token = token;
    +    }
    +
    +    public boolean isTimeOut() {
    +        if (token == null)
    +            return true;
    +        long timeout = Long.parseLong(getTimeOut(token));
    +        Date date = new Date();
    +        long timenow = date.getTime();
    +        return (timenow > timeout);
    +    }
    +
    +    private String deconde(String t) {
    +
    +        byte[] decryptFrom = parseHexStr2Byte(t);
    +
    +        if (decryptFrom == null)
    +            return null;
    +        byte[] decryptResult = decrypt(decryptFrom, passwd);
    +
    +        return new String(decryptResult);
    +    }
    +
    +    private String encode() {
    +
    +        Date date = new Date();
    +        long timeout = date.getTime() + Long.parseLong(interval);
    +
    +        String content = String.valueOf(timeout) + "=" + "continue";
    +
    +        byte[] encryptResult = encrypt(content, passwd);
    +        String encryptResultStr = parseByte2HexStr(encryptResult);
    +        return encryptResultStr;
    +    }
    +
    +    private String getTimeOut(String t) {
    +        String d = deconde(t);
    +        if (d == null)
    +            return "0";
    +        return d.split("=")[0];
    +    }
    +
    +    public static void main(String[] args) {
    +        // TODO Auto-generated method stub
    +        Token t = new Token();
    +        // t.setPasswd("12345678");
    +        String content = "test";
    +        // String password = "12345678";
    +
    +        System.out.println("before:" + content);
    +        byte[] encryptResult = t.encrypt(content, "fuck-trafodion!");
    --- End diff --
    
    That is not appropriate language, even in test code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to