本文整理汇总了Java中org.jasig.cas.client.validation.Assertion.getPrincipal方法的典型用法代码示例。如果您正苦于以下问题:Java Assertion.getPrincipal方法的具体用法?Java Assertion.getPrincipal怎么用?Java Assertion.getPrincipal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jasig.cas.client.validation.Assertion
的用法示例。
在下文中一共展示了Assertion.getPrincipal方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAttributePrincipal
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的package包/类
/**
* Gets the attribute principal.
*
* @param assertion the assertion
*
* @return the attribute principal
*/
public static AttributePrincipal getAttributePrincipal(Assertion assertion) {
if (LOG.isDebugEnabled()) {
LOG.debug("getAttributePrincipal(Assertion) - entering");
}
if (assertion == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("getAttributePrincipal(Assertion) - exiting");
}
return null;
}
AttributePrincipal returnAttributePrincipal = assertion.getPrincipal();
if (LOG.isDebugEnabled()) {
LOG.debug("getAttributePrincipal(Assertion) - exiting");
}
return returnAttributePrincipal;
}
示例2: validateSecurityTokenInAssertion
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的package包/类
private static SecurityToken validateSecurityTokenInAssertion(final Assertion assertion, final HttpServletRequest request,
final HttpServletResponse response) {
LOGGER.debug("Validating security token in CAS assertion...");
final AttributePrincipal principal = assertion.getPrincipal();
if (!principal.getAttributes().containsKey(WSFederationConstants.SECURITY_TOKEN_ATTRIBUTE)) {
throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE);
}
final String token = (String) principal.getAttributes().get(WSFederationConstants.SECURITY_TOKEN_ATTRIBUTE);
final byte[] securityTokenBin = EncodingUtils.decodeBase64(token);
return SerializationUtils.deserialize(securityTokenBin);
}
示例3: validateServiceTicket
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的package包/类
public CasProfile validateServiceTicket(final String serviceURL, final TokenCredentials ticket) {
try {
final Assertion assertion = getCasRestAuthenticator().getTicketValidator()
.validate(ticket.getToken(), serviceURL);
final AttributePrincipal principal = assertion.getPrincipal();
final CasProfile casProfile = new CasProfile();
casProfile.setId(principal.getName());
casProfile.addAttributes(principal.getAttributes());
return casProfile;
} catch (final TicketValidationException e) {
throw new TechnicalException(e);
}
}
示例4: retrievePrincipalFromSessionOrRequest
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的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);
}
}
示例5: doGetPost
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的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);
}
示例6: getProxyTicketFor
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的package包/类
public final static String getProxyTicketFor(Assertion assertion, String targetService) {
String proxyTicket = "";
if (assertion == null) {
return proxyTicket;
}
AttributePrincipal attributePrincipal = assertion.getPrincipal();
if (attributePrincipal == null) {
return proxyTicket;
}
proxyTicket = attributePrincipal.getProxyTicketFor(targetService);
return proxyTicket;
}
示例7: validateTicket
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的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);
}
}
示例8: doTranslation
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的package包/类
@Override
public void doTranslation(final HttpServletRequest request, final HttpServletResponse response,
final Assertion assertion) {
if (assertion == null || assertion.getPrincipal() == null) {
logger.error("No valid assertion or principal could be found to translate");
return;
}
AttributePrincipal casPrincipal = assertion.getPrincipal();
logger.debug("principalName found and being passed on: {}", casPrincipal.getName());
// Pass authenticated principal back to IdP to finish its part of authentication request processing
Collection<IdPAttributePrincipal> assertionAttributes = produceIdpAttributePrincipal(assertion.getAttributes());
Collection<IdPAttributePrincipal> principalAttributes = produceIdpAttributePrincipal(casPrincipal.getAttributes());
if (!assertionAttributes.isEmpty() || !principalAttributes.isEmpty()) {
logger.debug("Found attributes from CAS. Processing...");
Set<Principal> principals = new HashSet<>();
principals.addAll(assertionAttributes);
principals.addAll(principalAttributes);
principals.add(new UsernamePrincipal(casPrincipal.getName()));
request.setAttribute(ExternalAuthentication.SUBJECT_KEY, new Subject(false, principals,
Collections.emptySet(), Collections.emptySet()));
logger.info("Created an IdP subject instance with principals containing attributes for {} ", casPrincipal.getName());
} else {
logger.debug("No attributes released from CAS. Creating an IdP principal for {}", casPrincipal.getName());
request.setAttribute(ExternalAuthentication.PRINCIPAL_NAME_KEY, casPrincipal.getName());
}
}
示例9: getProfile
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的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);
}
示例10: getProfile
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的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();
}
示例11: doFilter
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的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);
}
示例12: retrievePrincipalFromSessionOrRequest
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的package包/类
protected Principal retrievePrincipalFromSessionOrRequest(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));
return assertion == null ? null : assertion.getPrincipal();
}
示例13: debugPGT
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的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();
}
示例14: debugAssertion
import org.jasig.cas.client.validation.Assertion; //导入方法依赖的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");
}
}