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


Java AttributePrincipal.getName方法代码示例

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


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

示例1: getAttributePrincipalName

import org.jasig.cas.client.authentication.AttributePrincipal; //导入方法依赖的package包/类
/**
 * Gets the attribute principal name.
 * 
 * @param assertion the assertion
 * 
 * @return the attribute principal name
 */
public static String getAttributePrincipalName(Assertion assertion) {

    AttributePrincipal attributePrincipal = AssertionUtils.getAttributePrincipal(assertion);

    String name = "";

    if (attributePrincipal != null) {
        name = attributePrincipal.getName();
    }
    return name;
}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:19,代码来源:AssertionUtils.java

示例2: retrievePrincipalFromSessionOrRequest

import org.jasig.cas.client.authentication.AttributePrincipal; //导入方法依赖的package包/类
/**
 * Crea principal a traves de la request
 */
protected CasPrincipal retrievePrincipalFromSessionOrRequest(final ServletRequest servletRequest) {
    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    final HttpSession session = request.getSession(false);
    final Assertion assertion = (Assertion) (session == null ? request.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION) : session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION));
    
    if (assertion == null){
    	return null;
    }else{
    	List<String> roles = new ArrayList<String>();
    	String apellidosNombre,nif,listaRoles;
    	char metodoAutenticacion;
    	
    	// Recuperamos info de CAS
    	AttributePrincipal ap = assertion.getPrincipal();
    	apellidosNombre = (String) ap.getAttributes().get(this.nombreAttribute);
    	nif = (String) ap.getAttributes().get(this.nifAttribute);
    	metodoAutenticacion = ((String) ap.getAttributes().get(this.metodoAutenticacionAttribute)).charAt(0);
    	
    	// Obtenemos lista de roles
    	if (this.rolesAttribute.equals("INTERNAL")){
    		// Roles no est�n centralizados en CAS. Los obtenemos del autenticador.
    		roles = autenticador.obtenerRoles(props,ap.getName());
    		
    	}else{
    		// Roles centralizados en CAS
    		listaRoles = (String) ap.getAttributes().get(this.rolesAttribute);
        	if (listaRoles != null && listaRoles.length() > 0){
	        	String[] rs = listaRoles.split(":");        	
	        	for (int i=0;i<rs.length;i++){
	        		roles.add(rs[i]);
	        	}
        	}
    	}
    	
    	return new CasPrincipal(ap.getName(),apellidosNombre,nif,metodoAutenticacion,roles);
    	
    }
    
}
 
开发者ID:GovernIB,项目名称:sistra,代码行数:43,代码来源:CasAuthenticationFilter.java

示例3: doGetPost

import org.jasig.cas.client.authentication.AttributePrincipal; //导入方法依赖的package包/类
public void doGetPost(MCRServletJob job) throws Exception {
    HttpServletRequest req = job.getRequest();
    HttpServletResponse res = job.getResponse();

    String ticket = req.getParameter("ticket");
    if ((ticket == null) || (ticket.trim().length() == 0)) {
        res.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }

    // Validate ticket at CAS server
    Cas20ProxyTicketValidator sv = new Cas20ProxyTicketValidator(serverURL);
    sv.setAcceptAnyProxy(true);
    Assertion a = sv.validate(ticket, clientURL);
    AttributePrincipal principal = a.getPrincipal();

    // Get user name logged in
    String userName = principal.getName();
    LOGGER.info("Login {}", userName);

    MCRUser user;
    boolean userExists = MCRUserManager.exists(userName, realmID);
    if (userExists)
        user = MCRUserManager.getUser(userName, realmID);
    else
        user = new MCRUser(userName, realmID);

    // Get user properties from LDAP server
    boolean userChanged = MCRLDAPClient.instance().updateUserProperties(user);
    if (userChanged && userExists) {
        MCRUserManager.updateUser(user);
    }

    // Store login user in session and redirect browser to target url
    MCRSessionMgr.getCurrentSession().setUserInformation(user);
    // MCR-1154
    req.changeSessionId();
    MCRLoginServlet.redirect(res);
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:40,代码来源:MCRCASServlet.java

示例4: validateTicket

import org.jasig.cas.client.authentication.AttributePrincipal; //导入方法依赖的package包/类
/**
 * Validates and parses the given ID ticket, returning the username
 * provided by the CAS server in the ticket.  If the
 * ticket is invalid an exception is thrown.
 *
 * @param ticket
 *     The ID ticket to validate and parse.
 *
 * @param credentials
 *     The Credentials object to store retrieved username and
 *     password values in.
 *
 * @return
 *     The username derived from the ticket.
 *
 * @throws GuacamoleException
 *     If the ID ticket is not valid or guacamole.properties could
 *     not be parsed.
 */
public String validateTicket(String ticket, Credentials credentials) throws GuacamoleException {

    // Retrieve the configured CAS URL, establish a ticket validator,
    // and then attempt to validate the supplied ticket.  If that succeeds,
    // grab the principal returned by the validator.
    String casServerUrl = confService.getAuthorizationEndpoint();
    Cas20ProxyTicketValidator validator = new Cas20ProxyTicketValidator(casServerUrl);
    validator.setAcceptAnyProxy(true);
    validator.setEncoding("UTF-8");
    try {
        String confRedirectURI = confService.getRedirectURI();
        Assertion a = validator.validate(ticket, confRedirectURI);
        AttributePrincipal principal =  a.getPrincipal();

        // Retrieve username and set the credentials.
        String username = principal.getName();
        if (username != null)
            credentials.setUsername(username);

        // Retrieve password, attempt decryption, and set credentials.
        Object credObj = principal.getAttributes().get("credential");
        if (credObj != null) {
            String clearPass = decryptPassword(credObj.toString());
            if (clearPass != null && !clearPass.isEmpty())
                credentials.setPassword(clearPass);
        }

        return username;

    } 
    catch (TicketValidationException e) {
        throw new GuacamoleException("Ticket validation failed.", e);
    }
    catch (Throwable t) {
        logger.error("Error validating ticket with CAS server: {}", t.getMessage());
        throw new GuacamoleInvalidCredentialsException("CAS login failed.", CredentialsInfo.USERNAME_PASSWORD);
    }

}
 
开发者ID:apache,项目名称:guacamole-client,代码行数:59,代码来源:TicketValidationService.java

示例5: getProfile

import org.jasig.cas.client.authentication.AttributePrincipal; //导入方法依赖的package包/类
@Override
protected UserProfile getProfile(OAuthProvider provider, UserSession session, String callbackUrl) {
    Assertion assertion = CasHelper.getProfile(callbackUrl);
    AttributePrincipal principal = assertion.getPrincipal();
    String id = principal.getName();
    Map<String, Object> attributes = principal.getAttributes();
    return new UserProfile(id, attributes);
}
 
开发者ID:ameizi,项目名称:cas-oauth-example-3.5.x,代码行数:9,代码来源:TestCasWrapperProvider20.java

示例6: getProfile

import org.jasig.cas.client.authentication.AttributePrincipal; //导入方法依赖的package包/类
public static UserProfile getProfile(String callbackUrl, Class<? extends UserProfile> clazz) {
    Assertion assertion = getProfile(callbackUrl);
    if (assertion != null) {
        try {
            AttributePrincipal principal = assertion.getPrincipal();
            String id = principal.getName();
            Map<String, Object> attributes = principal.getAttributes();
            Constructor<? extends UserProfile> constructor = clazz.getDeclaredConstructor(Object.class, Map.class);
            return constructor.newInstance(id, attributes);
        } catch (Exception e) {
            logger.error("Exception : ", e);
        }
    }
    return new UserProfile();
}
 
开发者ID:ameizi,项目名称:cas-oauth-example-3.5.x,代码行数:16,代码来源:CasHelper.java

示例7: doFilter

import org.jasig.cas.client.authentication.AttributePrincipal; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response,FilterChain filterChain) throws IOException, ServletException {
	HttpSession session = ((HttpServletRequest) request).getSession();
	Boolean isSessionLoaded = (Boolean) session.getAttribute(WebSSOConstants.IS_SESSION_ATTRIBUTES_LOADED);
	if (null == isSessionLoaded || isSessionLoaded == Boolean.FALSE) {
		Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
		AttributePrincipal attributePrincipal = assertion.getPrincipal();
		String attributesString = attributePrincipal.getName();
		log.debug("User Principal retrived from WebSSO-server:  "+attributesString);
		loadSessionAttributes(attributesString,session);
		session.setAttribute(WebSSOConstants.IS_SESSION_ATTRIBUTES_LOADED, Boolean.TRUE);			
	}
	filterChain.doFilter(request, response);
}
 
开发者ID:NCIP,项目名称:cagrid-core,代码行数:14,代码来源:CaGridWebSSOAttributeLoaderFilter.java

示例8: debugPGT

import org.jasig.cas.client.authentication.AttributePrincipal; //导入方法依赖的package包/类
/**
 * Debug pgt.
 * 
 * @param assertion the assertion
 * 
 * @return the string
 */
public static String debugPGT(Assertion assertion) {
    StringBuffer stringBuffer = new StringBuffer();
    if (assertion == null) {
        stringBuffer.append("\n Assertion is null \n");
        return stringBuffer.toString();
    }

    AttributePrincipal attributePrincipal = assertion.getPrincipal();
    if (attributePrincipal == null) {
        stringBuffer.append("\n AttributePrincipal is null \n");
        return stringBuffer.toString();
    }

    Date validFromDate = assertion.getValidFromDate();
    Date validUntilDate = assertion.getValidUntilDate();

    String principal = attributePrincipal.getName();
    stringBuffer.append("\n Principal: \n");

    if (principal == null) {
        stringBuffer.append("null");
    } else {
        stringBuffer.append(principal);
    }

    stringBuffer.append("\n Valid from: \n");

    if (validFromDate == null) {
        stringBuffer.append("null");
    } else {
        stringBuffer.append(validFromDate.toString());
    }

    stringBuffer.append("\n Valid until: \n");

    if (validUntilDate == null) {
        stringBuffer.append("null");
    } else {
        stringBuffer.append(validUntilDate.toString());
    }

    stringBuffer.append("\n Attributes: \n");
    Iterator<?> it = assertion.getAttributes().entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        stringBuffer.append("\n ");
        stringBuffer.append(entry.getKey());
        stringBuffer.append("=");
        stringBuffer.append(entry.getValue());
        stringBuffer.append(" \n");
    }
    return stringBuffer.toString();

}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:62,代码来源:AssertionUtils.java

示例9: debugAssertion

import org.jasig.cas.client.authentication.AttributePrincipal; //导入方法依赖的package包/类
public static void debugAssertion(StringBuffer stringBuffer, Assertion assertion) {
    if (assertion == null) {
        stringBuffer.append("\nAssertion is null\n");
        return;
    }

    AttributePrincipal attributePrincipal = assertion.getPrincipal();
    if (attributePrincipal == null) {
        stringBuffer.append("\nAttributePrincipal is null\n");
        return;
    }

    Date validFromDate = assertion.getValidFromDate();
    Date validUntilDate = assertion.getValidUntilDate();

    String principal = attributePrincipal.getName();
    stringBuffer.append("\nPrincipal:\n");

    if (principal == null) {
        stringBuffer.append("null");
    } else {
        stringBuffer.append(principal);
    }

    stringBuffer.append("\nValid from:\n");

    if (validFromDate == null) {
        stringBuffer.append("null");
    } else {
        stringBuffer.append(validFromDate.toString());
    }

    stringBuffer.append("\nValid until:\n");

    if (validUntilDate == null) {
        stringBuffer.append("null");
    } else {
        stringBuffer.append(validUntilDate.toString());
    }
    stringBuffer.append("\nAttributes:\n");
    Iterator<?> it = assertion.getAttributes().entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        stringBuffer.append("\n");
        stringBuffer.append(entry.getKey());
        stringBuffer.append("=");
        stringBuffer.append(entry.getValue());
        stringBuffer.append("\n");
    }

}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:52,代码来源:TestCASRest.java

示例10: doGetAuthenticationInfo

import org.jasig.cas.client.authentication.AttributePrincipal; //导入方法依赖的package包/类
/**
 * Authenticates a user and retrieves its information.
 *
 * @param token the authentication token
 * @throws org.apache.shiro.authc.AuthenticationException if there is an error during authentication.
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
  CasToken casToken = (CasToken) token;
  if (token == null) {
    return null;
  }

  String ticket = (String) casToken.getCredentials();
  if (!StringUtils.hasText(ticket)) {
    return null;
  }

  TicketValidator ticketValidator = ensureTicketValidator();

  try {
    // contact CAS server to validate service ticket
    Assertion casAssertion = ticketValidator.validate(ticket, getCasService());
    // get principal, user id and attributes
    AttributePrincipal casPrincipal = casAssertion.getPrincipal();
    String userId = casPrincipal.getName();
    Map<String, Object> attributes = casPrincipal.getAttributes();
    LOG.info("Validate ticket : {} in CAS server : {} to retrieve user : {}, attributes: {}", ticket, getCasServerUrlPrefix(), userId, attributes);
    // refresh authentication token (user id + remember me)
    casToken.setUserId(userId);
    String rememberMeAttributeName = getRememberMeAttributeName();
    String rememberMeStringValue = (String) attributes.get(rememberMeAttributeName);
    boolean isRemembered = rememberMeStringValue != null && Boolean.parseBoolean(rememberMeStringValue);
    if (isRemembered) {
      casToken.setRememberMe(true);
    }
    // create simple authentication info
    ShiroUser user = new ShiroUser((String) attributes.get("username"));
    List<Object> principals = CollectionUtils.asList(user, attributes);
    PrincipalCollection principalCollection = new SimplePrincipalCollection(principals, getName());
    LOG.info("principal: {}", principalCollection);
    return new SimpleAuthenticationInfo(principalCollection, ticket);
  } catch (TicketValidationException e) {
    LOG.error("{}", ticket, e);
    throw new CasAuthenticationException("Unable to validate ticket [" + ticket + "]", e);
  }
}
 
开发者ID:colin-lee,项目名称:shiro-spring-support,代码行数:48,代码来源:ShiroCasRealm.java

示例11: getUser

import org.jasig.cas.client.authentication.AttributePrincipal; //导入方法依赖的package包/类
/**
 * Returns the user object, or if there isn't one, throws an exception.
 * 
 * @param servletRequest the HTTP servlet request.
 * @return the user object.
 * 
 * @throws HttpStatusException if the logged-in user isn't in the user
 * table, which means the user is not authorized to use 
 * eureka-protempa-etl.
 */
public AuthorizedUserEntity getUser(HttpServletRequest servletRequest) {
	AttributePrincipal principal = getUserPrincipal(servletRequest);
	AuthorizedUserEntity result = this.userDao.getByPrincipal(principal);
	if (result == null) {
		throw new HttpStatusException(Status.FORBIDDEN, "User " + principal.getName() + " is unauthorized to use this resource");
	}
	return result;
}
 
开发者ID:eurekaclinical,项目名称:eureka,代码行数:19,代码来源:AuthorizedUserSupport.java


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