Search in sources :

Example 1 with Attributes

use of org.wildfly.security.authz.Attributes in project wildfly by wildfly.

the class AttributePrintingServlet method doGet.

/**
 * Writes plain-text response with all of the current identities attributes.
 */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/plain");
    final PrintWriter writer = resp.getWriter();
    SecurityDomain securityDomain = SecurityDomain.getCurrent();
    SecurityIdentity securityIdentity = securityDomain.getCurrentSecurityIdentity();
    Attributes attributes = securityIdentity.getAttributes();
    for (Entry currentAttribute : attributes.entries()) {
        writer.print(currentAttribute.getKey());
        writer.print("=");
        for (int i = 0; i < currentAttribute.size(); i++) {
            writer.print(currentAttribute.get(i));
            if (i < currentAttribute.size()) {
                writer.print(",");
            }
        }
        writer.println();
    }
    writer.close();
}
Also used : SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) Entry(org.wildfly.security.authz.Attributes.Entry) Attributes(org.wildfly.security.authz.Attributes) HttpConstraint(javax.servlet.annotation.HttpConstraint) PrintWriter(java.io.PrintWriter) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain)

Example 2 with Attributes

use of org.wildfly.security.authz.Attributes in project wildfly by wildfly.

the class JdbcTestServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/plain");
    final PrintWriter writer = resp.getWriter();
    Map<String, String[]> parameters = req.getParameterMap();
    SecurityDomain securityDomain = SecurityDomain.getCurrent();
    SecurityIdentity securityIdentity = securityDomain.getCurrentSecurityIdentity();
    Attributes attributes = securityIdentity.getAttributes();
    for (Entry<String, String[]> entry : parameters.entrySet()) {
        for (String value : entry.getValue()) {
            if (attributes.containsValue(entry.getKey(), value) == false) {
                writer.write(String.format("Attribute %s with value %s missing from the Attributes associated with the current SecurityIdentity.", entry.getKey(), value));
                writer.close();
                return;
            }
        }
    }
    writer.write(RESPONSE_BODY);
    writer.close();
}
Also used : SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) Attributes(org.wildfly.security.authz.Attributes) PrintWriter(java.io.PrintWriter) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain)

Example 3 with Attributes

use of org.wildfly.security.authz.Attributes in project keycloak by keycloak.

the class KeycloakSecurityRealm method createRealmIdentity.

private RealmIdentity createRealmIdentity(KeycloakPrincipal principal) {
    return new RealmIdentity() {

        @Override
        public Principal getRealmIdentityPrincipal() {
            return principal;
        }

        @Override
        public SupportLevel getCredentialAcquireSupport(Class<? extends Credential> credentialType, String algorithmName, AlgorithmParameterSpec parameterSpec) throws RealmUnavailableException {
            return SupportLevel.UNSUPPORTED;
        }

        @Override
        public <C extends Credential> C getCredential(Class<C> credentialType) throws RealmUnavailableException {
            return null;
        }

        @Override
        public SupportLevel getEvidenceVerifySupport(Class<? extends Evidence> evidenceType, String algorithmName) throws RealmUnavailableException {
            return SupportLevel.SUPPORTED;
        }

        @Override
        public boolean verifyEvidence(Evidence evidence) throws RealmUnavailableException {
            return principal != null;
        }

        @Override
        public boolean exists() throws RealmUnavailableException {
            return principal != null;
        }

        @Override
        public AuthorizationIdentity getAuthorizationIdentity() throws RealmUnavailableException {
            RefreshableKeycloakSecurityContext securityContext = (RefreshableKeycloakSecurityContext) principal.getKeycloakSecurityContext();
            Attributes attributes = new MapAttributes();
            Set<String> roles = AdapterUtils.getRolesFromSecurityContext(securityContext);
            attributes.addAll(RoleDecoder.KEY_ROLES, roles);
            return AuthorizationIdentity.basicIdentity(attributes);
        }
    };
}
Also used : Credential(org.wildfly.security.credential.Credential) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) MapAttributes(org.wildfly.security.authz.MapAttributes) MapAttributes(org.wildfly.security.authz.MapAttributes) Attributes(org.wildfly.security.authz.Attributes) Evidence(org.wildfly.security.evidence.Evidence) RealmIdentity(org.wildfly.security.auth.server.RealmIdentity) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Aggregations

Attributes (org.wildfly.security.authz.Attributes)3 PrintWriter (java.io.PrintWriter)2 SecurityDomain (org.wildfly.security.auth.server.SecurityDomain)2 SecurityIdentity (org.wildfly.security.auth.server.SecurityIdentity)2 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)1 HttpConstraint (javax.servlet.annotation.HttpConstraint)1 RefreshableKeycloakSecurityContext (org.keycloak.adapters.RefreshableKeycloakSecurityContext)1 RealmIdentity (org.wildfly.security.auth.server.RealmIdentity)1 Entry (org.wildfly.security.authz.Attributes.Entry)1 MapAttributes (org.wildfly.security.authz.MapAttributes)1 Credential (org.wildfly.security.credential.Credential)1 Evidence (org.wildfly.security.evidence.Evidence)1