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


Java ProfileManager.get方法代码示例

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


在下文中一共展示了ProfileManager.get方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例8: 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

示例9: 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

示例10: redirectToCallbackRedirectUrl

import org.pac4j.core.profile.ProfileManager; //导入方法依赖的package包/类
protected ModelAndView redirectToCallbackRedirectUrl(ProfileManager manager, OAuthRegisteredService registeredService, J2EContext context, String clientId) throws Exception {
	Optional profile = manager.get(true);
	if(profile != null && profile.isPresent()) {
		Service service = this.authenticationBuilder.buildService(registeredService, context, false);
		LOGGER.debug("Created service [{}] based on registered service [{}]", service, registeredService);
		Authentication authentication = this.authenticationBuilder.build((UserProfile)profile.get(), registeredService, context, service);
		LOGGER.debug("Created OAuth authentication [{}] for service [{}]", service, authentication);

		try {
			RegisteredServiceAccessStrategyUtils.ensurePrincipalAccessIsAllowedForService(service, registeredService, authentication);
		} catch (PrincipalException | UnauthorizedServiceException var13) {
			LOGGER.error(var13.getMessage(), var13);
			return OAuth20Utils.produceUnauthorizedErrorView();
		}

		String redirectUri = context.getRequestParameter("redirect_uri");
		LOGGER.debug("Authorize request verification successful for client [{}] with redirect uri [{}]", clientId, redirectUri);
		String responseType = context.getRequestParameter("response_type");
		TicketGrantingTicket ticketGrantingTicket = CookieUtils.getTicketGrantingTicketFromRequest(this.ticketGrantingTicketCookieGenerator, this.ticketRegistry, context.getRequest());
		String callbackUrl;
		if(OAuth20Utils.isResponseType(responseType, OAuth20ResponseTypes.CODE)) {
			callbackUrl = this.buildCallbackUrlForAuthorizationCodeResponseType(authentication, service, redirectUri, ticketGrantingTicket);
		} else if(OAuth20Utils.isResponseType(responseType, OAuth20ResponseTypes.TOKEN)) {
			AccessTokenRequestDataHolder holder = new AccessTokenRequestDataHolder(service, authentication, registeredService, ticketGrantingTicket);
			callbackUrl = this.buildCallbackUrlForImplicitTokenResponseType(holder, redirectUri);
		} else {
			callbackUrl = this.buildCallbackUrlForTokenResponseType(context, authentication, service, redirectUri, responseType, clientId);
		}

		LOGGER.debug("Callback URL to redirect: [{}]", callbackUrl);
		context.getRequest().getSession().invalidate();
		removeCookie(context);
		return StringUtils.isBlank(callbackUrl)?OAuth20Utils.produceUnauthorizedErrorView():OAuth20Utils.redirectTo(callbackUrl);
	} else {
		LOGGER.error("Unexpected null profile from profile manager. Request is not fully authenticated.");
		return OAuth20Utils.produceUnauthorizedErrorView();
	}
}
 
开发者ID:e-gov,项目名称:TARA-Server,代码行数:39,代码来源:OAuth20AuthorizeEndpointController.java

示例11: isRequestAuthenticated

import org.pac4j.core.profile.ProfileManager; //导入方法依赖的package包/类
private static boolean isRequestAuthenticated(final ProfileManager manager, final J2EContext context) {
    final Optional<CommonProfile> opt = manager.get(true);
    return opt.isPresent();
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:5,代码来源:OAuth20AuthorizeEndpointController.java

示例12: redirectToCallbackRedirectUrl

import org.pac4j.core.profile.ProfileManager; //导入方法依赖的package包/类
/**
 * Redirect to callback redirect url model and view.
 *
 * @param manager           the manager
 * @param registeredService the registered service
 * @param context           the context
 * @param clientId          the client id
 * @return the model and view
 * @throws Exception the exception
 */
protected ModelAndView redirectToCallbackRedirectUrl(final ProfileManager manager,
                                                     final OAuthRegisteredService registeredService,
                                                     final J2EContext context,
                                                     final String clientId) throws Exception {
    final Optional<UserProfile> profile = manager.get(true);
    if (profile == null || !profile.isPresent()) {
        LOGGER.error("Unexpected null profile from profile manager. Request is not fully authenticated.");
        return OAuth20Utils.produceUnauthorizedErrorView();
    }

    final Service service = this.authenticationBuilder.buildService(registeredService, context, false);
    LOGGER.debug("Created service [{}] based on registered service [{}]", service, registeredService);

    final Authentication authentication = this.authenticationBuilder.build(profile.get(), registeredService, context, service);
    LOGGER.debug("Created OAuth authentication [{}] for service [{}]", service, authentication);

    try {
        RegisteredServiceAccessStrategyUtils.ensurePrincipalAccessIsAllowedForService(service, registeredService, authentication);
    } catch (final UnauthorizedServiceException | PrincipalException e) {
        LOGGER.error(e.getMessage(), e);
        return OAuth20Utils.produceUnauthorizedErrorView();
    }

    final String redirectUri = context.getRequestParameter(OAuth20Constants.REDIRECT_URI);
    LOGGER.debug("Authorize request verification successful for client [{}] with redirect uri [{}]", clientId, redirectUri);

    final String responseType = context.getRequestParameter(OAuth20Constants.RESPONSE_TYPE);

    final TicketGrantingTicket ticketGrantingTicket = CookieUtils.getTicketGrantingTicketFromRequest(
            ticketGrantingTicketCookieGenerator, this.ticketRegistry, context.getRequest());
    final String callbackUrl;
    if (OAuth20Utils.isResponseType(responseType, OAuth20ResponseTypes.CODE)) {
        callbackUrl = buildCallbackUrlForAuthorizationCodeResponseType(authentication, service, redirectUri, ticketGrantingTicket);
    } else if (OAuth20Utils.isResponseType(responseType, OAuth20ResponseTypes.TOKEN)) {
        final AccessTokenRequestDataHolder holder = new AccessTokenRequestDataHolder(service, authentication, 
                registeredService, ticketGrantingTicket);
        callbackUrl = buildCallbackUrlForImplicitTokenResponseType(holder, redirectUri);
    } else {
        callbackUrl = buildCallbackUrlForTokenResponseType(context, authentication, service, redirectUri, responseType, clientId);
    }

    LOGGER.debug("Callback URL to redirect: [{}]", callbackUrl);
    if (StringUtils.isBlank(callbackUrl)) {
        return OAuth20Utils.produceUnauthorizedErrorView();
    }
    return OAuth20Utils.redirectTo(callbackUrl);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:58,代码来源:OAuth20AuthorizeEndpointController.java

示例13: isRequestAuthenticated

import org.pac4j.core.profile.ProfileManager; //导入方法依赖的package包/类
private static boolean isRequestAuthenticated(ProfileManager manager, J2EContext context) {
	Optional opt = manager.get(true);
	return opt.isPresent();
}
 
开发者ID:e-gov,项目名称:TARA-Server,代码行数:5,代码来源:OAuth20AuthorizeEndpointController.java

示例14: isAuthenticationProfileAvailable

import org.pac4j.core.profile.ProfileManager; //导入方法依赖的package包/类
/**
 * Is authentication profile available?.
 *
 * @param context the context
 * @return the optional user profile
 */
public static Optional<UserProfile> isAuthenticationProfileAvailable(final WebContext context) {
    final ProfileManager manager = WebUtils.getPac4jProfileManager(context);
    return manager.get(true);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:11,代码来源:OidcAuthorizationRequestSupport.java


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