当前位置: 首页>>代码示例>>Java>>正文


Java ProfileManager类代码示例

本文整理汇总了Java中org.pac4j.core.profile.ProfileManager的典型用法代码示例。如果您正苦于以下问题:Java ProfileManager类的具体用法?Java ProfileManager怎么用?Java ProfileManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ProfileManager类属于org.pac4j.core.profile包,在下文中一共展示了ProfileManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAuthenticatedUsername

import org.pac4j.core.profile.ProfileManager; //导入依赖的package包/类
/**
 * Return the username of the authenticated user (based on pac4j security).
 *
 * @return the authenticated username.
 */
public static String getAuthenticatedUsername() {
    final HttpServletRequest request = getHttpServletRequest();
    final HttpServletResponse response = getHttpServletResponse();
    if (request != null && response != null) {
        final J2EContext context = new J2EContext(request, response);
        final ProfileManager manager = new ProfileManager(context);
        final UserProfile profile = manager.get(true);
        if (profile != null) {
            final String id = profile.getId();
            if (id != null) {
                return id;
            }
        }
    }
    return UNKNOWN_USER;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:22,代码来源:WebUtils.java

示例2: login

import org.pac4j.core.profile.ProfileManager; //导入依赖的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

示例3: generate

import org.pac4j.core.profile.ProfileManager; //导入依赖的package包/类
/**
 * Generate string.
 *
 * @param request           the request
 * @param response          the response
 * @param accessTokenId     the access token id
 * @param timeout           the timeout
 * @param responseType      the response type
 * @param registeredService the registered service
 * @return the string
 * @throws Exception the exception
 */
public String generate(final HttpServletRequest request,
                       final HttpServletResponse response,
                       final AccessToken accessTokenId,
                       final long timeout,
                       final OAuth20ResponseTypes responseType,
                       final OAuthRegisteredService registeredService) throws Exception {

    final OidcRegisteredService oidcRegisteredService = (OidcRegisteredService) registeredService;

    final J2EContext context = WebUtils.getPac4jJ2EContext(request, response);
    final ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);
    final Optional<UserProfile> profile = manager.get(true);

    LOGGER.debug("Attempting to produce claims for the id token [{}]", accessTokenId);
    final JwtClaims claims = produceIdTokenClaims(request, accessTokenId, timeout,
            oidcRegisteredService, profile.get(), context, responseType);
    LOGGER.debug("Produce claims for the id token [{}] as [{}]", accessTokenId, claims);

    return this.signingService.encode(oidcRegisteredService, claims);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:33,代码来源:OidcIdTokenGeneratorService.java

示例4: extract

import org.pac4j.core.profile.ProfileManager; //导入依赖的package包/类
@Override
public AccessTokenRequestDataHolder extract() {
    final ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);
    final String grantType = request.getParameter(OAuth20Constants.GRANT_TYPE);
    LOGGER.debug("OAuth grant type is [{}]", grantType);

    final Optional<UserProfile> profile = manager.get(true);
    final String clientId = profile.get().getId();
    final OAuthRegisteredService registeredService = OAuth20Utils.getRegisteredOAuthService(this.servicesManager, clientId);
    LOGGER.debug("Located OAuth registered service [{}]", registeredService);

    // we generate a refresh token if requested by the service but not from a refresh token
    final boolean generateRefreshToken = isAllowedToGenerateRefreshToken(registeredService);
    final OAuthToken token = getOAuthTokenFromRequest();
    if (token == null) {
        throw new InvalidTicketException(getOAuthParameter());
    }
    return new AccessTokenRequestDataHolder(token, generateRefreshToken, registeredService);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:20,代码来源:AccessTokenAuthorizationCodeGrantRequestExtractor.java

示例5: getAuthenticatedUsername

import org.pac4j.core.profile.ProfileManager; //导入依赖的package包/类
/**
 * Return the username of the authenticated user (based on pac4j security).
 *
 * @return the authenticated username.
 */
public static String getAuthenticatedUsername() {
    final HttpServletRequest request = getHttpServletRequestFromRequestAttributes();
    final HttpServletResponse response = getHttpServletResponseFromRequestAttributes();
    if (request != null && response != null) {
        final ProfileManager manager = getPac4jProfileManager(request, response);
        final Optional<UserProfile> profile = manager.get(true);
        if (profile != null && profile.isPresent()) {
            final String id = profile.get().getId();
            if (id != null) {
                return id;
            }
        }
    }
    return PrincipalResolver.UNKNOWN_USER;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:21,代码来源:WebUtils.java

示例6: generate

import org.pac4j.core.profile.ProfileManager; //导入依赖的package包/类
/**
 * Generate string.
 *
 * @param request           the request
 * @param response          the response
 * @param accessTokenId     the access token id
 * @param timeout           the timeout
 * @param responseType      the response type
 * @param registeredService the registered service
 * @return the string
 * @throws Exception the exception
 */
public String generate(final HttpServletRequest request,
                       final HttpServletResponse response,
                       final AccessToken accessTokenId,
                       final long timeout,
                       final OAuth20ResponseTypes responseType,
                       final OAuthRegisteredService registeredService) throws Exception {

    final OidcRegisteredService oidcRegisteredService = (OidcRegisteredService) registeredService;

    final J2EContext context = WebUtils.getPac4jJ2EContext(request, response);
    final ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);
    final Optional<UserProfile> profile = manager.get(true);

    LOGGER.debug("Attempting to produce claims for the id token [{}]", accessTokenId);
    final JwtClaims claims = produceIdTokenClaims(request, accessTokenId, timeout,
        oidcRegisteredService, profile.get(), context, responseType);
    LOGGER.debug("Produce claims for the id token [{}] as [{}]", accessTokenId, claims);

    return this.signingService.encode(oidcRegisteredService, claims);
}
 
开发者ID:e-gov,项目名称:TARA-Server,代码行数:33,代码来源:OidcIdTokenGeneratorService.java

示例7: handleRequest

import org.pac4j.core.profile.ProfileManager; //导入依赖的package包/类
@GetMapping(
		path = {"/oauth2.0/authorize"}
)
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
	J2EContext context = WebUtils.getPac4jJ2EContext(request, response);
	ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);
	if(this.verifyAuthorizeRequest(request) && isRequestAuthenticated(manager, context)) {
		String clientId = context.getRequestParameter("client_id");
		OAuthRegisteredService registeredService = this.getRegisteredServiceByClientId(clientId);
		try {
			RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(clientId, registeredService);
		} catch (Exception var8) {
			LOGGER.error(var8.getMessage(), var8);
			return OAuth20Utils.produceUnauthorizedErrorView();
		}
		ModelAndView mv = this.consentApprovalViewResolver.resolve(context, registeredService);
		return !mv.isEmpty() && mv.hasView()?mv:this.redirectToCallbackRedirectUrl(manager, registeredService, context, clientId);
	} else {
		LOGGER.error("Authorize request verification failed");
		return OAuth20Utils.produceUnauthorizedErrorView();
	}
}
 
开发者ID:e-gov,项目名称:TARA-Server,代码行数:23,代码来源:OAuth20AuthorizeEndpointController.java

示例8: login

import org.pac4j.core.profile.ProfileManager; //导入依赖的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

示例9: shouldAllowAccess

import org.pac4j.core.profile.ProfileManager; //导入依赖的package包/类
@Test
public void shouldAllowAccess() throws Exception {
  new MockUnit(Request.class, Response.class, Route.Chain.class, ProfileManager.class,
      WebContext.class, Session.class, CommonProfile.class)
      .expect(unit -> {
        CommonProfile profile = unit.get(CommonProfile.class);

        ProfileManager pm = unit.get(ProfileManager.class);
        expect(pm.getAll(true)).andReturn(ImmutableList.of(profile));

        Request req = unit.get(Request.class);
        expect(req.require(ProfileManager.class)).andReturn(pm);
        expect(req.ifSession()).andReturn(Optional.of(unit.get(Session.class)));

        Pac4jClientType.profileTypes(profile.getClass(),
            type -> expect(req.set(type, profile)).andReturn(req));

        Response rsp = unit.get(Response.class);
        unit.get(Route.Chain.class).next(req, rsp);
      })
      .run(unit -> {
        new Pac4jGrantAccessAdapter(unit.get(Request.class), unit.get(Response.class),
            unit.get(Route.Chain.class))
            .adapt(unit.get(WebContext.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:27,代码来源:Pac4jGrantAccessAdapterTest.java

示例10: shouldCreateProfileManager

import org.pac4j.core.profile.ProfileManager; //导入依赖的package包/类
@Test
public void shouldCreateProfileManager() throws Exception {
  new MockUnit(WebContext.class, Config.class, ProfileManager.class)
      .expect(unit -> {
        Function<WebContext, ProfileManager> pmf = unit.mock(Function.class);
        expect(pmf.apply(unit.get(WebContext.class))).andReturn(unit.get(ProfileManager.class));

        Config config = unit.get(Config.class);
        expect(config.getProfileManagerFactory()).andReturn(pmf);
      })
      .run(unit -> {
        Pac4jProfileManager pmp = new Pac4jProfileManager(unit.get(Config.class),
            unit.get(WebContext.class));
        assertEquals(unit.get(ProfileManager.class), pmp.get());
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:17,代码来源:Pac4jProfileManagerTest.java

示例11: resolve

import org.pac4j.core.profile.ProfileManager; //导入依赖的package包/类
@Override
public ModelAndView resolve(final J2EContext ctx, final ProfileManager manager, final String url) {
    final Set<String> prompt = authorizationRequestSupport.getOidcPromptFromAuthorizationRequest(url);
    if (prompt.contains(OidcConstants.PROMPT_NONE)) {
        if (manager.get(true) != null) {
            return new ModelAndView(url);
        }
        final Map<String, String> model = new HashMap<>();
        model.put(OAuth20Constants.ERROR, OidcConstants.LOGIN_REQUIRED);
        return new ModelAndView(new MappingJackson2JsonView(), model);
    }
    return new ModelAndView(new RedirectView(url));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:14,代码来源:OidcCallbackAuthorizeViewResolver.java

示例12: preHandle

import org.pac4j.core.profile.ProfileManager; //导入依赖的package包/类
@Override
public boolean preHandle(final HttpServletRequest request,
                         final HttpServletResponse response,
                         final Object handler) throws Exception {
    final J2EContext ctx = WebUtils.getPac4jJ2EContext(request, response);
    final ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);


    boolean clearCreds = false;
    final Optional<UserProfile> auth = authorizationRequestSupport.isAuthenticationProfileAvailable(ctx);

    if (auth.isPresent()) {
        final Optional<Long> maxAge = authorizationRequestSupport.getOidcMaxAgeFromAuthorizationRequest(ctx);
        if (maxAge.isPresent()) {
            clearCreds = authorizationRequestSupport.isCasAuthenticationOldForMaxAgeAuthorizationRequest(ctx, auth.get());
        }
    }

    final Set<String> prompts = authorizationRequestSupport.getOidcPromptFromAuthorizationRequest(ctx);
    if (!clearCreds) {
        clearCreds = prompts.contains(OidcConstants.PROMPT_LOGIN);
    }

    if (clearCreds) {
        clearCreds = !prompts.contains(OidcConstants.PROMPT_NONE);
    }

    if (clearCreds) {
        manager.remove(true);
    }
    return super.preHandle(request, response, handler);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:33,代码来源:OidcSecurityInterceptor.java

示例13: destroyApplicationSession

import org.pac4j.core.profile.ProfileManager; //导入依赖的package包/类
/**
 * Destroy application session.
 * Also kills all delegated authn profiles via pac4j.
 *
 * @param request  the request
 * @param response the response
 */
protected void destroyApplicationSession(final HttpServletRequest request, final HttpServletResponse response) {
    LOGGER.debug("Destroying application session");
    final ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);
    manager.logout();

    final HttpSession session = request.getSession();
    if (session != null) {
        session.invalidate();
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:18,代码来源:TerminateSessionAction.java

示例14: extract

import org.pac4j.core.profile.ProfileManager; //导入依赖的package包/类
@Override
public AccessTokenRequestDataHolder extract() {
    final String clientId = request.getParameter(OAuth20Constants.CLIENT_ID);
    LOGGER.debug("Locating OAuth registered service by client id [{}]", clientId);

    final OAuthRegisteredService registeredService = OAuth20Utils.getRegisteredOAuthService(this.servicesManager, clientId);
    LOGGER.debug("Located OAuth registered service [{}]", registeredService);

    final J2EContext context = WebUtils.getPac4jJ2EContext(request, response);
    final ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);
    final Optional<OAuthUserProfile> profile = manager.get(true);
    if (!profile.isPresent()) {
        throw new UnauthorizedServiceException("OAuth user profile cannot be determined");
    }
    LOGGER.debug("Creating matching service request based on [{}]", registeredService);
    final boolean requireServiceHeader = oAuthProperties.getGrants().getResourceOwner().isRequireServiceHeader();
    if (requireServiceHeader) {
        LOGGER.debug("Using request headers to identify and build the target service url");
    }
    final Service service = this.authenticationBuilder.buildService(registeredService, context, requireServiceHeader);

    LOGGER.debug("Authenticating the OAuth request indicated by [{}]", service);
    final Authentication authentication = this.authenticationBuilder.build(profile.get(), registeredService, context, service);
    RegisteredServiceAccessStrategyUtils.ensurePrincipalAccessIsAllowedForService(service, registeredService, authentication);

    final AuthenticationResult result = new DefaultAuthenticationResult(authentication, requireServiceHeader ? service : null);
    final TicketGrantingTicket ticketGrantingTicket = this.centralAuthenticationService.createTicketGrantingTicket(result);
    return new AccessTokenRequestDataHolder(service, authentication, registeredService, ticketGrantingTicket);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:30,代码来源:AccessTokenPasswordGrantRequestExtractor.java

示例15: handleRequest

import org.pac4j.core.profile.ProfileManager; //导入依赖的package包/类
/**
 * Handle request internal model and view.
 *
 * @param request  the request
 * @param response the response
 * @return the model and view
 * @throws Exception the exception
 */
@GetMapping(path = OAuth20Constants.BASE_OAUTH20_URL + '/' + OAuth20Constants.AUTHORIZE_URL)
public ModelAndView handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final J2EContext context = WebUtils.getPac4jJ2EContext(request, response);
    final ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);

    if (!verifyAuthorizeRequest(request) || !isRequestAuthenticated(manager, context)) {
        LOGGER.error("Authorize request verification failed");
        return OAuth20Utils.produceUnauthorizedErrorView();
    }

    final String clientId = context.getRequestParameter(OAuth20Constants.CLIENT_ID);
    final OAuthRegisteredService registeredService = getRegisteredServiceByClientId(clientId);
    try {
        RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(clientId, registeredService);
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        return OAuth20Utils.produceUnauthorizedErrorView();
    }

    final ModelAndView mv = this.consentApprovalViewResolver.resolve(context, registeredService);
    if (!mv.isEmpty() && mv.hasView()) {
        return mv;
    }

    return redirectToCallbackRedirectUrl(manager, registeredService, context, clientId);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:35,代码来源:OAuth20AuthorizeEndpointController.java


注:本文中的org.pac4j.core.profile.ProfileManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。