Example usage for org.springframework.security.cas.authentication CasAuthenticationToken getKeyHash

List of usage examples for org.springframework.security.cas.authentication CasAuthenticationToken getKeyHash

Introduction

In this page you can find the example usage for org.springframework.security.cas.authentication CasAuthenticationToken getKeyHash.

Prototype

public int getKeyHash() 

Source Link

Usage

From source file:com.vnomicscorp.spring.security.cas.authentication.redis.DefaultCasAuthenticationTokenSerializerTest.java

private void assertTokenEquals(CasAuthenticationToken expected, CasAuthenticationToken got) {
    assertEquals(expected.getName(), got.getName());
    assertEquals(expected.isAuthenticated(), got.isAuthenticated());
    assertEquals(expected.getAuthorities(), got.getAuthorities());
    assertEquals(expected.getCredentials(), got.getCredentials());
    assertEquals(expected.getDetails(), got.getDetails());
    assertEquals(expected.getKeyHash(), got.getKeyHash());
    assertEquals(expected.getPrincipal(), got.getPrincipal());
    assertEquals(expected.getUserDetails(), got.getUserDetails());
}

From source file:com.gdn.iam.spring.security.FortressDecisionVoter.java

@Override
@SuppressWarnings("static-access")
public int vote(Authentication authentication, FilterInvocation fi, Collection<ConfigAttribute> attributes) {
    Authentication securityContextAuthentication = SecurityContextHolder.getContext().getAuthentication();
    int result = super.vote(securityContextAuthentication, fi, attributes);
    if (System.getenv(IAM_SECURITY_PARAMETER) != null) {
        LOG.warn("iam security is disable, enable all access mode is enable");
        return result;
    } else {//from  w  ww  .  j a  va2s  .com
        LOG.debug("authentication = {}", ToStringBuilder.reflectionToString(securityContextAuthentication));
        LOG.debug("super vote for : {}", result);
        if (super.ACCESS_GRANTED == result) {
            String requestMethod = fi.getRequest().getMethod().toLowerCase();
            String filterUrl = getFilterUrl(fi.getHttpRequest());
            if (filterUrl == null) {
                return result;
            }
            try {
                CasAuthenticationToken casAuthenticationToken = ((CasAuthenticationToken) securityContextAuthentication);
                LOG.debug("assertion : {}",
                        ToStringBuilder.reflectionToString(casAuthenticationToken.getAssertion()));
                String iamSessionXml = (String) casAuthenticationToken.getAssertion().getAttributes()
                        .get(IAM_SESSION_ATTRIBUTE_KEY);
                LOG.debug("iam session xml == {}", iamSessionXml);
                Session iamSession = sessionCache.getIfPresent(casAuthenticationToken.getKeyHash());
                if (iamSession == null) {
                    Unmarshaller unmarshaller = null;
                    try {
                        unmarshaller = context.createUnmarshaller();
                    } catch (JAXBException ex) {
                        LOG.warn("cannot create unmarshaller : ", ex);
                    }
                    iamSession = (Session) unmarshaller.unmarshal(new StringReader(iamSessionXml));
                    sessionCache.put(casAuthenticationToken.getKeyHash(), iamSession);
                }
                StringBuilder sessionPermissionKeyBuilder = new StringBuilder(iamSession.getSessionId())
                        .append(filterUrl).append(requestMethod);
                Boolean isAllowed = accessCache.getIfPresent(sessionPermissionKeyBuilder.toString());
                if (isAllowed == null) {
                    isAllowed = accessManager.checkAccess(iamSession, new Permission(filterUrl, requestMethod));
                    accessCache.put(sessionPermissionKeyBuilder.toString(), isAllowed);
                }
                LOG.debug("{} is {} to access {} with method {}",
                        new Object[] { securityContextAuthentication.getName(),
                                isAllowed ? "granted" : "denied", filterUrl, requestMethod });
                if (isAllowed) {
                    return super.ACCESS_GRANTED;
                }
            } catch (Exception e) {
                LOG.error("catch exception when communicate with iam server", e);
            }
        }
        return super.ACCESS_DENIED;
    }
}