Search in sources :

Example 1 with ApiKey

use of com.walmartlabs.concord.server.security.apikey.ApiKey in project concord by walmartlabs.

the class ConcordRememberMeManager method rememberIdentity.

@Override
protected void rememberIdentity(Subject subject, PrincipalCollection src) {
    SimplePrincipalCollection dst = new SimplePrincipalCollection();
    // keep only the specific types of principals to keep the cookie small
    for (String realmName : src.getRealmNames()) {
        Collection<?> principals = src.fromRealm(realmName);
        for (Object p : principals) {
            if (p instanceof UsernamePasswordToken || p instanceof ApiKey) {
                dst.add(p, realmName);
            }
        }
    }
    super.rememberIdentity(subject, dst);
}
Also used : ApiKey(com.walmartlabs.concord.server.security.apikey.ApiKey) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Example 2 with ApiKey

use of com.walmartlabs.concord.server.security.apikey.ApiKey in project concord by walmartlabs.

the class ConcordAuthenticationHandler method createFromAuthHeader.

private AuthenticationToken createFromAuthHeader(HttpServletRequest req) {
    // check the 'remember me' status
    boolean rememberMe = Boolean.parseBoolean(req.getHeader(REMEMBER_ME_HEADER));
    String h = req.getHeader(HttpHeaders.AUTHORIZATION);
    if (h.startsWith(BASIC_AUTH_PREFIX)) {
        // enable sessions
        req.setAttribute(DefaultSubjectContext.SESSION_CREATION_ENABLED, Boolean.TRUE);
        return parseBasicAuth(h, rememberMe);
    } else {
        boolean enableSessions = Boolean.parseBoolean(req.getHeader(ENABLE_HTTP_SESSION));
        req.setAttribute(DefaultSubjectContext.SESSION_CREATION_ENABLED, enableSessions);
        if (h.startsWith(BEARER_AUTH_PREFIX)) {
            h = h.substring(BEARER_AUTH_PREFIX.length());
        }
        validateApiKey(h);
        ApiKeyEntry apiKey = apiKeyDao.find(h);
        if (apiKey == null) {
            return new UsernamePasswordToken();
        }
        return new ApiKey(apiKey.getId(), apiKey.getUserId(), h, rememberMe);
    }
}
Also used : ApiKeyEntry(com.walmartlabs.concord.server.security.apikey.ApiKeyEntry) ApiKey(com.walmartlabs.concord.server.security.apikey.ApiKey) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Aggregations

ApiKey (com.walmartlabs.concord.server.security.apikey.ApiKey)2 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)2 ApiKeyEntry (com.walmartlabs.concord.server.security.apikey.ApiKeyEntry)1 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)1