/*
 * JBoss, Home of Professional Open Source
 * Copyright 2013 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.security.auth.permission;

import java.security.Permission;

public final class SecurityDomainPermission extends Permission {

    private static final long serialVersionUID = 8533735187740371169L;

    private final int actions;

    public SecurityDomainPermission(final String name, final Action... actions) {
        super(name);
        int i = 0;
        for (Action action : actions) {
            i |= action.i;
        }
        this.actions = i;
    }

    public boolean implies(final Permission permission) {
        // xxx blah blah
        return false;
    }

    public boolean equals(final Object obj) {
        return false;
    }

    public int hashCode() {
        return 0;
    }

    public String getActions() {
        return null;
    }

    enum Action {
        CREATE(1),
        ACCESS(2),
        ;

        private final int i;
        Action(final int i) {
            this.i = i;
        }
    }
}

@@ -763,185 +763,582 @@
 ava.
-security.Permission;%0A%0Apublic final class SecurityDomainPermission extends Permission %7B%0A%0A    private static final long serialVersionUID = 8533735187740371169L;%0A%0A    private final
+io.IOException;%0Aimport java.io.ObjectInputStream;%0Aimport java.io.ObjectOutputStream;%0Aimport java.io.ObjectStreamField;%0Aimport java.security.Permission;%0A%0Aimport org.wildfly.security.permission.PermissionActions;%0A%0Apublic final class SecurityDomainPermission extends Permission %7B%0A%0A    private static final long serialVersionUID = 8533735187740371169L;%0A%0A    private static final ObjectStreamField%5B%5D serialPersistentFields = new ObjectStreamField%5B%5D %7B%0A        new ObjectStreamField(%22actions%22, String.class),%0A    %7D;%0A%0A    private transient String actionString;%0A    private transient
  int
@@ -1405,33 +1405,8 @@
 name
-, final Action... actions
 ) %7B%0A
@@ -1434,21 +1434,23 @@
         
-int i
+actions
  = 0;%0A  
@@ -1455,105 +1455,375 @@
     
+%7D%0A%0A
     
-for (Action action : actions) %7B%0A            i %7C= action.i
+public SecurityDomainPermission(final String name, final String actions) %7B%0A        super(name);%0A        this.actions = PermissionActions.parseActionStringToInt(Action.class, actions)
 ;%0A    
+%7D%0A%0A
     
-%7D%0A        this.actions = i
+public boolean implies(final Permission permission) %7B%0A        return permission instanceof SecurityDomainPermission && implies((SecurityDomainPermission) permission)
 ;%0A  
@@ -1852,32 +1852,46 @@
 n implies(final 
+SecurityDomain
 Permission permi
@@ -1911,120 +1911,426 @@
     
-// xxx blah blah%0A        return false;%0A    %7D%0A%0A    public boolean equals(final Object obj) %7B%0A        return false
+return (actions & permission.actions) == permission.actions && getName().equals(permission.getName());%0A    %7D%0A%0A    public boolean equals(final Object obj) %7B%0A        return obj instanceof SecurityDomainPermission && equals((SecurityDomainPermission) obj);%0A    %7D%0A%0A    public boolean equals(final SecurityDomainPermission permission) %7B%0A        return actions == permission.actions && getName().equals(permission.getName())
 ;%0A  
@@ -2377,17 +2377,50 @@
  return 
-0
+getName().hashCode() * 4 + actions
 ;%0A    %7D%0A
@@ -2465,63 +2465,310 @@
     
-return null;%0A    %7D%0A%0A    enum Action %7B%0A        CREATE(1)
+String actionString = this.actionString;%0A        if (actionString == null) %7B%0A            actionString = this.actionString = PermissionActions.getCanonicalActionString(Action.class, actions);%0A        %7D%0A        return actionString;%0A    %7D%0A%0A    enum Action %7B%0A        // Do not re-order, ever%0A        create
 ,%0A  
@@ -2777,17 +2777,14 @@
     
-ACCESS(2)
+access
 ,%0A  
@@ -2791,21 +2791,23 @@
       ;%0A
-%0A
     
+%7D%0A%0A
     priv
@@ -2814,84 +2814,503 @@
 ate 
-final int i;%0A        Action(final int i) %7B%0A            this.i = i;%0A        %7D
+void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException %7B%0A        final ObjectInputStream.GetField getField = ois.readFields();%0A        this.actions = PermissionActions.parseActionStringToInt(Action.class, (String) getField.get(%22actions%22, %22%22));%0A    %7D%0A%0A    private void writeObject(ObjectOutputStream oos) throws IOException %7B%0A        final ObjectOutputStream.PutField putField = oos.putFields();%0A        putField.put(%22actions%22, getActions());%0A        oos.writeFields();
 %0A   

Improve SecurityDomainPermission using security manager facilities