當前位置: 首頁>>代碼示例>>Java>>正文


Java CasRestProfile類代碼示例

本文整理匯總了Java中org.pac4j.cas.profile.CasRestProfile的典型用法代碼示例。如果您正苦於以下問題:Java CasRestProfile類的具體用法?Java CasRestProfile怎麽用?Java CasRestProfile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CasRestProfile類屬於org.pac4j.cas.profile包,在下文中一共展示了CasRestProfile類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: login

import org.pac4j.cas.profile.CasRestProfile; //導入依賴的package包/類
/**
 * app rest 登錄獲取token
 * eg:http://localhost:8081/user/login?cilent_name=rest&username=hsjhsj&password=hsjhsj
 * 然後獲取資源:http://localhost:8081/user/1?token=eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiZGlyIn0..7usGh1GK3jl5_wPH.QJdYqNp81zRyAs6OHmN4573l67z_UgxQ7WXJ7OUsDw50Dato2X9Tyh5kXBAJF5l9LmmKe8y-kHrhyx9gcEIa6PC97mo5fPbCw9WoOypyTqdWkE1Q9mM44Zn8CZZVH9PTml7_0jwln0W_bzDWjN3f-0Pk2etxU6lXwz5insFVz4nGt5SEmykhvOdKlscLsYbHGQVqze4nlXuAtVXQ08CuphRsZ2FmSaK-LFR8Ivs.DkqbT-PgEjE0ZS6pgNVqGA
 * @Description:TODO
 * @author:hsj qq:2356899074
 * @time:2017年12月11日 下午2:36:30
 * @param request
 * @param response
 * @return
 */
@RequestMapping("/user/login")
public Object login(HttpServletRequest request, HttpServletResponse response) {
    Map<String, Object> model = new HashMap<>();
    J2EContext context = new J2EContext(request, response);
    final ProfileManager<CasRestProfile> manager = new ProfileManager(context);
    final Optional<CasRestProfile> profile = manager.get(true);
    //獲取ticket
    TokenCredentials tokenCredentials = casRestFormClient.requestServiceTicket(serviceUrl, profile.get(), context);
    //根據ticket獲取用戶信息
    final CasProfile casProfile = casRestFormClient.validateServiceTicket(serviceUrl, tokenCredentials, context);
    //生成jwt token
    String token = generator.generate(casProfile);
    model.put("token", token);
    return new HttpEntity<>(model);
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:27,代碼來源:IndexController.java

示例2: login

import org.pac4j.cas.profile.CasRestProfile; //導入依賴的package包/類
@RequestMapping("/user/login")
public Object login(HttpServletRequest request, HttpServletResponse response) {
    Map<String, Object> model = new HashMap<>();
    J2EContext context = new J2EContext(request, response);
    final ProfileManager<CasRestProfile> manager = new ProfileManager(context);
    final Optional<CasRestProfile> profile = manager.get(true);
    //獲取ticket
    TokenCredentials tokenCredentials = casRestFormClient.requestServiceTicket(serviceUrl, profile.get(), context);
    //根據ticket獲取用戶信息
    final CasProfile casProfile = casRestFormClient.validateServiceTicket(serviceUrl, tokenCredentials, context);
    //生成jwt token
    String token = generator.generate(casProfile);
    model.put("token", token);
    return new HttpEntity<>(model);
}
 
開發者ID:kawhii,項目名稱:wolf,代碼行數:16,代碼來源:IndexController.java

示例3: destroyTicketGrantingTicket

import org.pac4j.cas.profile.CasRestProfile; //導入依賴的package包/類
public void destroyTicketGrantingTicket(final CasRestProfile profile) {
    HttpURLConnection connection = null;
    try {
        final URL endpointURL = new URL(getCasRestAuthenticator().getCasRestUrl());
        final URL deleteURL = new URL(endpointURL, endpointURL.getPath() + "/" + profile.getTicketGrantingTicketId());
        connection = HttpUtils.openDeleteConnection(deleteURL);
        final int responseCode = connection.getResponseCode();
        if (responseCode != HttpConstants.OK) {
            throw new TechnicalException("TGT delete request for `" + profile + "` failed: " +
                    HttpUtils.buildHttpErrorMessage(connection));
        }
    } catch (final IOException e) {
        throw new TechnicalException(e);
    } finally {
        HttpUtils.closeConnection(connection);
    }
}
 
開發者ID:yaochi,項目名稱:pac4j-plus,代碼行數:18,代碼來源:AbstractCasRestClient.java

示例4: internalTestRestForm

import org.pac4j.cas.profile.CasRestProfile; //導入依賴的package包/類
private void internalTestRestForm(final Authenticator authenticator) throws HttpAction {
    final CasRestFormClient client = new CasRestFormClient();
    client.setAuthenticator(authenticator);

    final MockWebContext context = MockWebContext.create();
    context.addRequestParameter(client.getUsernameParameter(), USER);
    context.addRequestParameter(client.getPasswordParameter(), USER);

    final UsernamePasswordCredentials credentials = client.getCredentials(context);
    final CasRestProfile profile = client.getUserProfile(credentials, context);
    assertEquals(USER, profile.getId());
    assertNotNull(profile.getTicketGrantingTicketId());

    final TokenCredentials casCreds = client.requestServiceTicket(PAC4J_BASE_URL, profile);
    final CasProfile casProfile = client.validateServiceTicket(PAC4J_BASE_URL, casCreds);
    assertNotNull(casProfile);
    assertEquals(USER, casProfile.getId());
    assertTrue(casProfile.getAttributes().size() > 0);
}
 
開發者ID:yaochi,項目名稱:pac4j-plus,代碼行數:20,代碼來源:CasRestClientIT.java

示例5: internalTestRestBasic

import org.pac4j.cas.profile.CasRestProfile; //導入依賴的package包/類
private void internalTestRestBasic(final CasRestBasicAuthClient client, int nbAttributes) throws HttpAction, UnsupportedEncodingException {
    final MockWebContext context = MockWebContext.create();
    final String token = USER + ":" + USER;
    context.addRequestHeader(VALUE, NAME + Base64.getEncoder().encodeToString(token.getBytes(HttpConstants.UTF8_ENCODING)));

    final UsernamePasswordCredentials credentials = client.getCredentials(context);
    final CasRestProfile profile = client.getUserProfile(credentials, context);
    assertEquals(USER, profile.getId());
    assertNotNull(profile.getTicketGrantingTicketId());

    final TokenCredentials casCreds = client.requestServiceTicket(PAC4J_BASE_URL, profile);
    final CasProfile casProfile = client.validateServiceTicket(PAC4J_BASE_URL, casCreds);
    assertNotNull(casProfile);
    assertEquals(USER, casProfile.getId());
    assertEquals(nbAttributes, casProfile.getAttributes().size());
    client.destroyTicketGrantingTicket(profile);

    TestsHelper.expectException(() -> client.requestServiceTicket(PAC4J_BASE_URL, profile), TechnicalException.class,
            "Service ticket request for `#CasRestProfile# | id: " + USER + " | attributes: {} | roles: [] | permissions: [] | isRemembered: false |` failed: (404) Not Found");
}
 
開發者ID:yaochi,項目名稱:pac4j-plus,代碼行數:21,代碼來源:CasRestClientIT.java

示例6: requestServiceTicket

import org.pac4j.cas.profile.CasRestProfile; //導入依賴的package包/類
public TokenCredentials requestServiceTicket(final String serviceURL, final CasRestProfile profile) {
    HttpURLConnection connection = null;
    try {
        final URL endpointURL = new URL(getCasRestAuthenticator().getCasRestUrl());
        final URL ticketURL = new URL(endpointURL, endpointURL.getPath() + "/" + profile.getTicketGrantingTicketId());

        connection = HttpUtils.openPostConnection(ticketURL);
        final String payload = HttpUtils.encodeQueryParam("service", serviceURL);

        final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream(), HttpConstants.UTF8_ENCODING));
        out.write(payload);
        out.close();

        final int responseCode = connection.getResponseCode();
        if (responseCode == HttpConstants.OK) {
            try (final BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), HttpConstants.UTF8_ENCODING))) {
                return new TokenCredentials(in.readLine(), getClass().getSimpleName());
            }
        }
        throw new TechnicalException("Service ticket request for `" + profile + "` failed: " +
                HttpUtils.buildHttpErrorMessage(connection));
    } catch (final IOException e) {
        throw new TechnicalException(e);
    } finally {
        HttpUtils.closeConnection(connection);
    }
}
 
開發者ID:yaochi,項目名稱:pac4j-plus,代碼行數:28,代碼來源:AbstractCasRestClient.java

示例7: validate

import org.pac4j.cas.profile.CasRestProfile; //導入依賴的package包/類
@Override
public void validate(final UsernamePasswordCredentials credentials, final WebContext context) throws HttpAction {
    init(context);

    if (credentials == null || credentials.getPassword() == null || credentials.getUsername() == null) {
        throw new TechnicalException("Credentials are required");
    }
    final String ticketGrantingTicketId = requestTicketGrantingTicket(credentials.getUsername(), credentials.getPassword());
    final CasRestProfile profile = new CasRestProfile(ticketGrantingTicketId, credentials.getUsername());
    credentials.setUserProfile(profile);
}
 
開發者ID:yaochi,項目名稱:pac4j-plus,代碼行數:12,代碼來源:CasRestAuthenticator.java


注:本文中的org.pac4j.cas.profile.CasRestProfile類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。