/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2015 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.wildfly.elytron.web.undertow.server;

import static org.wildfly.common.Assert.checkNotNullParam;
import io.undertow.security.idm.Account;

import java.security.Principal;
import java.util.Set;

import org.wildfly.security.auth.server.SecurityIdentity;

/**
 * A wrapper around {@link AuthenticatedRealmIdentity} to provide an implementation
 * of {@link Account} as required by Undertow.
 *
 * @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
 */
public class ElytronAccount implements Account {

    private final SecurityIdentity securityIdentity;

    ElytronAccount(final SecurityIdentity securityIdentity) {
        checkNotNullParam("securityIdentity", securityIdentity);
        this.securityIdentity = securityIdentity;
    }

    /**
     * @see io.undertow.security.idm.Account#getPrincipal()
     */
    @Override
    public Principal getPrincipal() {
        return securityIdentity.getPrincipal();
    }

    /**
     * @see io.undertow.security.idm.Account#getRoles()
     */
    @Override
    public Set<String> getRoles() {
        return securityIdentity.getRoles();
    }

    /**
     * Get the {@link SecurityIdentity} wrapped by this {@link Account}.
     *
     * @return the {@link SecurityIdentity} wrapped by this {@link Account}.
     */
    SecurityIdentity getSecurityIdentity() {
        return securityIdentity;
    }

}

@@ -900,18 +900,123 @@
 va.util.
-Se
+Collections;%0Aimport java.util.Set;%0Aimport java.util.stream.Collectors;%0Aimport java.util.stream.StreamSuppor
 t;%0A%0Aimpo
@@ -1390,16 +1390,53 @@
 dentity;
+%0A    private final Set%3CString%3E roles;
 %0A%0A    El
@@ -1602,24 +1602,190 @@
 tyIdentity;%0A
+        this.roles = Collections.unmodifiableSet(%0A                StreamSupport.stream(securityIdentity.getRoles().spliterator(), true).collect(Collectors.toSet()));%0A
     %7D%0A%0A    /
@@ -2103,35 +2103,13 @@
 urn 
-securityIdentity.getR
+r
 oles
-()
 ;%0A  

Switch to the new 'Roles' interface as exposed by SecurityIdentity.