当前位置: 首页>>代码示例>>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;未经允许,请勿转载。