Search in sources :

Example 1 with RealNameAuthenticationExample

use of com.itrus.portal.db.RealNameAuthenticationExample in project portal by ixinportal.

the class RealNameAuthenticationSerivceImpl method getRealNameAuthenticationByTwo.

/**
 * 获取密码服务配置
 * @return
 * @throws Exception
 */
public RealNameAuthentication getRealNameAuthenticationByTwo() throws Exception {
    RealNameAuthenticationExample re = new RealNameAuthenticationExample();
    RealNameAuthenticationExample.Criteria rec = re.createCriteria();
    rec.andTypeEqualTo(2);
    RealNameAuthentication realname = this.getRealNameAuthenticationExample(re);
    return realname;
}
Also used : RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) RealNameAuthenticationExample(com.itrus.portal.db.RealNameAuthenticationExample)

Example 2 with RealNameAuthenticationExample

use of com.itrus.portal.db.RealNameAuthenticationExample in project portal by ixinportal.

the class RealNameAuthenticationSerivceImpl method getRealNameAuthenticationByThree.

/**
 * 获取时间戳服务配置
 * @return
 * @throws Exception
 */
public RealNameAuthentication getRealNameAuthenticationByThree() throws Exception {
    RealNameAuthenticationExample re = new RealNameAuthenticationExample();
    RealNameAuthenticationExample.Criteria rec = re.createCriteria();
    rec.andTypeEqualTo(3);
    RealNameAuthentication realname = this.getRealNameAuthenticationExample(re);
    return realname;
}
Also used : RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) RealNameAuthenticationExample(com.itrus.portal.db.RealNameAuthenticationExample)

Example 3 with RealNameAuthenticationExample

use of com.itrus.portal.db.RealNameAuthenticationExample in project portal by ixinportal.

the class RealNameAuthenticationSerivceImpl method getRealNameAuthenticationByOne.

/**
 * 获取原子服务配置
 * @return
 * @throws Exception
 */
public RealNameAuthentication getRealNameAuthenticationByOne() throws Exception {
    RealNameAuthenticationExample re = new RealNameAuthenticationExample();
    RealNameAuthenticationExample.Criteria rec = re.createCriteria();
    rec.andTypeEqualTo(1);
    RealNameAuthentication realname = this.getRealNameAuthenticationExample(re);
    return realname;
}
Also used : RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) RealNameAuthenticationExample(com.itrus.portal.db.RealNameAuthenticationExample)

Example 4 with RealNameAuthenticationExample

use of com.itrus.portal.db.RealNameAuthenticationExample in project portal by ixinportal.

the class AuthService method getToken.

// @Autowired
// private static RealNameAuthenticationSerivceImpl authenticationSerivceImpl = new RealNameAuthenticationSerivceImpl();
/**
 * 获得token
 * 访问其他接口的时候 在头信息增加 Authorization :bear+token bear和token之间加个空格
 */
private static String getToken() {
    // client_secret:43b484748d3a936330bc50da70d6ce69e1dfef90
    try {
        // RealNameAuthentication realNameAuthentication =  authenticationSerivceImpl.getRealNameAuthenticationExample(new RealNameAuthenticationExample());
        long nowDate = System.currentTimeMillis();
        if (ACCESS_TOKEN != null && new Date(nowDate + inDateTime).before(inDate)) {
            return ACCESS_TOKEN;
        }
        RealNameAuthentication realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
        if (realNameAuthentication == null) {
            List<RealNameAuthentication> list = SpringContextHolder.getBean(SqlSession.class).selectList("com.itrus.portal.db.RealNameAuthenticationMapper.selectByExample", new RealNameAuthenticationExample());
            if (list == null || list.isEmpty()) {
                return null;
            }
            for (RealNameAuthentication nameAuthentication : list) {
                if (nameAuthentication.getType() == 2)
                    realNameAuthentication = nameAuthentication;
            }
            if (realNameAuthentication == null) {
                return null;
            }
        }
        Map params = new HashMap();
        params.put("grant_type", "client_credentials");
        params.put("client_id", realNameAuthentication.getIdCode());
        params.put("client_secret", realNameAuthentication.getKeyCode());
        String rep = HttpClientUtil.postForm(realNameAuthentication.getAccessTokenaddress() + TOKEN, null, params);
        // System.out.println("AuthService getToken()_rep : " + rep);
        JSONObject data = JSON.parseObject(rep);
        ACCESS_TOKEN = data.getString("access_token");
        inDate = new Date(nowDate + data.getLongValue("expires_in"));
        return ACCESS_TOKEN;
    } catch (RestClientException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) HashMap(java.util.HashMap) IOException(java.io.IOException) RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Date(java.util.Date) RestClientException(org.springframework.web.client.RestClientException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) RealNameAuthenticationExample(com.itrus.portal.db.RealNameAuthenticationExample) JSONObject(com.alibaba.fastjson.JSONObject) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) RestClientException(org.springframework.web.client.RestClientException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with RealNameAuthenticationExample

use of com.itrus.portal.db.RealNameAuthenticationExample in project portal by ixinportal.

the class AuthService method getToken.

// @Autowired
// private static RealNameAuthenticationSerivceImpl authenticationSerivceImpl = new RealNameAuthenticationSerivceImpl();
/**
 * 获得token
 * 访问其他接口的时候 在头信息增加 Authorization :bear+token bear和token之间加个空格
 */
private static String getToken() {
    // client_secret:43b484748d3a936330bc50da70d6ce69e1dfef90
    try {
        // RealNameAuthentication realNameAuthentication =  authenticationSerivceImpl.getRealNameAuthenticationExample(new RealNameAuthenticationExample());
        Long nowDate = System.currentTimeMillis();
        if (ACCESS_TOKEN != null && new Date(nowDate + inDateTime).before(inDate)) {
            return ACCESS_TOKEN;
        }
        List<RealNameAuthentication> list = sqlSession.selectList("com.itrus.portal.db.RealNameAuthenticationMapper.selectByExample", new RealNameAuthenticationExample());
        if (list == null || list.isEmpty()) {
            return null;
        }
        RealNameAuthentication realNameAuthentication = null;
        for (RealNameAuthentication nameAuthentication : list) {
            if (nameAuthentication.getType() == 1)
                realNameAuthentication = nameAuthentication;
        }
        if (realNameAuthentication == null) {
            return null;
        }
        Map params = new HashMap();
        params.put("grant_type", "client_credentials");
        params.put("client_id", realNameAuthentication.getIdCode());
        params.put("client_secret", realNameAuthentication.getKeyCode());
        String rep = HttpClientUtil.postForm(realNameAuthentication.getAccessTokenaddress() + TOKEN, null, params);
        JSONObject data = JSON.parseObject(rep);
        ACCESS_TOKEN = data.getString("access_token");
        inDate = new Date(nowDate + data.getInteger("expires_in") * 1000);
        return ACCESS_TOKEN;
    } catch (RestClientException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : IOException(java.io.IOException) RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) RestClientException(org.springframework.web.client.RestClientException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) RealNameAuthenticationExample(com.itrus.portal.db.RealNameAuthenticationExample) JSONObject(com.alibaba.fastjson.JSONObject) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) RestClientException(org.springframework.web.client.RestClientException)

Aggregations

RealNameAuthentication (com.itrus.portal.db.RealNameAuthentication)6 RealNameAuthenticationExample (com.itrus.portal.db.RealNameAuthenticationExample)6 JSONObject (com.alibaba.fastjson.JSONObject)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 IOException (java.io.IOException)2 RestClientException (org.springframework.web.client.RestClientException)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SqlSession (org.apache.ibatis.session.SqlSession)1