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();
}
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();
}
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);
}
};
}
Aggregations