java attributes用法_Java AttributePrincipal.getAttributes方法代码示例

import org.jasig.cas.client.authentication.AttributePrincipal; //导入方法依赖的package包/类

/**

* Authorization Filter

*

* @param servletResponse object that contains the response the servlet sends to the client

* @param servletRequest object that contains the request the client has made of the servlet.

* @param filterChain object to describe filter chain

*

* @throws IOException the IO exception

* @throws ServletException the servlet exception

*/

@Override

public final void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain)

throws IOException, ServletException {

// Get Request,Response,Session

final HttpServletRequest request = (HttpServletRequest) servletRequest;

final HttpServletResponse response = (HttpServletResponse) servletResponse;

// Get LDAP attributes from request

Principal p = request.getUserPrincipal();

AttributePrincipal principal = (AttributePrincipal) p;

Map attributes = principal.getAttributes();

// boolean isDefaultActionListServicei = false;

// try {

// Load MOTU configuration

MotuConfig conf = BLLManager.getInstance().getConfigManager().getMotuConfig();

// Get the MOTU service parameter (Get default service just in case)

String service = CommonHTTPParameters.getServiceFromRequest(request);

String defService = conf.getDefaultService();

// Get the MOTU action parameter (and the default action)

String action = CommonHTTPParameters.getActionFromRequest(request);

// isDefaultActionListServicei = conf.getDefaultActionIsListServices();

// Authorization (only for service)

boolean authorized = false;

if (service != null) {

authorized = match_ldap_vs_motu(attributes, conf, service); // (1) given service check

} else {

if (action != null) {

if (action.equals(MotuRequestParametersConstant.ACTION_LIST_SERVICES) || action.equals(MotuRequestParametersConstant.ACTION_PING)

|| action.equals(MotuMonitoringParametersConstant.ACTION_DEBUG)

|| action.equals(MotuRequestParametersConstant.ACTION_REFRESH)) {

authorized = true; // (2) public services

} else {

// if (isDefaultActionListServicei)

// authorized = true;

// else

authorized = match_ldap_vs_motu(attributes, conf, defService); // (3) default service

// check

}

} else {

// if (isDefaultActionListServicei)

// authorized = true;

// else

authorized = match_ldap_vs_motu(attributes, conf, defService); // (3) default service

// check

}

}

// Not authorized (unauthorized/forbidden html page)

if (!authorized) {

response.sendError(HttpServletResponse.SC_FORBIDDEN);

return;

}

// Authorized = Everything ok

filterChain.doFilter(request, response);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值