本文整理汇总了Java中org.jasig.cas.client.authentication.AttributePrincipal类的典型用法代码示例。如果您正苦于以下问题:Java AttributePrincipal类的具体用法?Java AttributePrincipal怎么用?Java AttributePrincipal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AttributePrincipal类属于org.jasig.cas.client.authentication包,在下文中一共展示了AttributePrincipal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.jasig.cas.client.authentication.AttributePrincipal; //导入依赖的package包/类
@Override
protected void init() {
super.init();
getRequestCycleListeners().add(new AbstractRequestCycleListener() {
@Override
public void onBeginRequest(RequestCycle cycle) {
super.onBeginRequest(cycle);
if (cycle.getRequest() instanceof ServletWebRequest) {
ServletWebRequest req = (ServletWebRequest) cycle.getRequest();
AttributePrincipal principal = (AttributePrincipal) req.getContainerRequest().getUserPrincipal();
String user = req.getContainerRequest().getRemoteUser();
System.out.println("Principal: " + principal);
System.out.println("Attributes:");
for (Entry<String, Object> e : principal.getAttributes().entrySet()) {
System.out.println(e.getKey() + ":" + e.getValue() + "(" + e.getValue().getClass() + ")");
}
System.out.println("Principal Name: " + principal.getName());
System.out.println("Principal Class: " + principal.getClass());
System.out.println("Remote User: " + user);
}
}
});
}
示例2: 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;
}
示例3: getAttributePrincipal
import org.jasig.cas.client.authentication.AttributePrincipal; //导入依赖的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;
}
示例4: getUserPrincipal
import org.jasig.cas.client.authentication.AttributePrincipal; //导入依赖的package包/类
@Override
public Principal getUserPrincipal() {
return new AttributePrincipal() {
@Override
public String getName() {
return "[email protected]";
}
@Override
public String getProxyTicketFor(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Map<String, Object> getAttributes() {
Map<String, Object> attrs = new HashMap<>();
return Collections.unmodifiableMap(attrs);
}
};
}
示例5: correctlyExtractsNamedAttributeFromAssertionAndConvertsThemToAuthorities
import org.jasig.cas.client.authentication.AttributePrincipal; //导入依赖的package包/类
@Test
public void correctlyExtractsNamedAttributeFromAssertionAndConvertsThemToAuthorities() {
GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService uds
= new GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService();
uds.setConvertToUpperCase(false);
uds.setConvertSpacesToUnderscores(false);
uds.setAttribute("a");
uds.setRolePrefix("");
Assertion assertion = mock(Assertion.class);
AttributePrincipal principal = mock(AttributePrincipal.class);
Map<String, Object> attributes = new HashMap<>();
attributes.put("a", Arrays.asList("CN=role_a1,OU=roles,DC=spring,DC=io", "CN=role_a2,OU=roles,DC=spring,DC=io"));
attributes.put("b", "b");
attributes.put("c", "c");
attributes.put("d", null);
attributes.put("someother", "unused");
when(assertion.getPrincipal()).thenReturn(principal);
when(principal.getAttributes()).thenReturn(attributes);
when(principal.getName()).thenReturn("somebody");
CasAssertionAuthenticationToken token = new CasAssertionAuthenticationToken(assertion, "ticket");
UserDetails user = uds.loadUserDetails(token);
Set<String> roles = AuthorityUtils.authorityListToSet(user.getAuthorities());
assertTrue(roles.size() == 2);
assertTrue(roles.contains("role_a1"));
assertTrue(roles.contains("role_a2"));
}
开发者ID:acu-dev,项目名称:spring-security-cas-memberOf-roles,代码行数:27,代码来源:GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsServiceTest.java
示例6: correctlyExtractsDefaultNamedAttributeFromAssertionAndConvertsThemToAuthorities
import org.jasig.cas.client.authentication.AttributePrincipal; //导入依赖的package包/类
@Test
public void correctlyExtractsDefaultNamedAttributeFromAssertionAndConvertsThemToAuthorities() {
GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService uds
= new GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService();
Assertion assertion = mock(Assertion.class);
AttributePrincipal principal = mock(AttributePrincipal.class);
Map<String, Object> attributes = new HashMap<>();
attributes.put("memberOf", Arrays.asList("CN=a1,ou=other,OU=roles,DC=spring,DC=io", "CN=a2,OU=roles,dc=spring,DC=io", null));
attributes.put("someother", "unused");
when(assertion.getPrincipal()).thenReturn(principal);
when(principal.getAttributes()).thenReturn(attributes);
when(principal.getName()).thenReturn("somebody");
CasAssertionAuthenticationToken token = new CasAssertionAuthenticationToken(assertion, "ticket");
UserDetails user = uds.loadUserDetails(token);
Set<String> roles = AuthorityUtils.authorityListToSet(user.getAuthorities());
assertTrue(roles.size() == 2);
assertTrue(roles.contains("ROLE_A1"));
assertTrue(roles.contains("ROLE_A2"));
}
开发者ID:acu-dev,项目名称:spring-security-cas-memberOf-roles,代码行数:20,代码来源:GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsServiceTest.java
示例7: setUp
import org.jasig.cas.client.authentication.AttributePrincipal; //导入依赖的package包/类
/**
* Set up the objects for the test case
* @throws Exception
*/
@Before
public void setUp() throws Exception
{
proxyValidator = mock(Cas20ProxyTicketValidator.class);
validator = new CASAuthTicketValidator(proxyValidator, SERVICE_URL);
assertion = mock(Assertion.class);
principal = mock(AttributePrincipal.class);
when(proxyValidator.validate(TEST_PROXY_TICKET, SERVICE_URL))
.thenReturn(assertion);
when(assertion.getPrincipal()).thenReturn(principal);
when(principal.getName()).thenReturn(TEST_USERNAME);
}
示例8: buildEcpCasAssertion
import org.jasig.cas.client.authentication.AttributePrincipal; //导入依赖的package包/类
/**
* Build ecp cas assertion assertion.
*
* @param authentication the authentication
* @param service the service
* @param registeredService the registered service
* @return the assertion
*/
protected Assertion buildEcpCasAssertion(final Authentication authentication,
final Service service,
final RegisteredService registeredService) {
final Map attributes = registeredService.getAttributeReleasePolicy()
.getAttributes(authentication.getPrincipal(), service, registeredService);
final AttributePrincipal principal = new AttributePrincipalImpl(
authentication.getPrincipal().getId(), attributes);
return new AssertionImpl(principal, DateTimeUtils.dateOf(authentication.getAuthenticationDate()),
null, DateTimeUtils.dateOf(authentication.getAuthenticationDate()),
authentication.getAttributes());
}
示例9: prepareNameIdAttribute
import org.jasig.cas.client.authentication.AttributePrincipal; //导入依赖的package包/类
/**
* Prepare name id attribute id p attribute.
*
* @param assertion the assertion
* @return the id p attribute
*/
protected IdPAttribute prepareNameIdAttribute(final Assertion assertion) {
final IdPAttribute attribute = new IdPAttribute(AttributePrincipal.class.getName());
final IdPAttributeValue<String> value = new StringAttributeValue(assertion.getPrincipal().getName());
LOGGER.debug("NameID attribute value is set to [{}]", assertion.getPrincipal().getName());
attribute.setValues(Collections.singletonList(value));
return attribute;
}
示例10: validateSecurityTokenInAssertion
import org.jasig.cas.client.authentication.AttributePrincipal; //导入依赖的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);
}
示例11: getProxyGrantingTicket
import org.jasig.cas.client.authentication.AttributePrincipal; //导入依赖的package包/类
/**
* Hacky code please do not use that in production
*/
private Optional<String> getProxyGrantingTicket(Authentication authentication) {
if (!(authentication instanceof CasAuthenticationToken)) {
return Optional.empty();
}
AttributePrincipal principal = ((CasAuthenticationToken) authentication).getAssertion().getPrincipal();
if (!(principal instanceof AttributePrincipalImpl)) {
return Optional.empty();
}
Field field = ReflectionUtils.findField(AttributePrincipalImpl.class, "proxyGrantingTicket");
ReflectionUtils.makeAccessible(field);
return Optional.ofNullable(ReflectionUtils.getField(field, principal)).map(Object::toString);
}
开发者ID:kakawait,项目名称:cas-security-spring-boot-starter,代码行数:16,代码来源:CasSecuritySpringBootSampleApplication.java
示例12: validateServiceTicket
import org.jasig.cas.client.authentication.AttributePrincipal; //导入依赖的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);
}
}
示例13: 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);
}
}
示例14: 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);
}
示例15: getProxyTicketFor
import org.jasig.cas.client.authentication.AttributePrincipal; //导入依赖的package包/类
/**
* Gets the proxy ticket for.
*
* @param assertion the assertion
* @param targetService the target service
*
* @return the proxy ticket for
*/
public static String getProxyTicketFor(Assertion assertion, String targetService) {
if (LOG.isDebugEnabled()) {
LOG.debug("getProxyTicketFor(Assertion, String) - entering");
}
String ticket = "";
if (assertion == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("getProxyTicketFor(Assertion, String) - exiting - assertion is null");
}
return ticket;
}
AttributePrincipal attributePrincipal = AssertionUtils.getAttributePrincipal(assertion);
if (attributePrincipal != null) {
ticket = attributePrincipal.getProxyTicketFor(targetService);
}
if (LOG.isDebugEnabled()) {
LOG.debug("getProxyTicketFor(Assertion, String) - exiting");
}
return ticket;
}