001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq.security;
018
019import javax.annotation.PostConstruct;
020
021import org.springframework.beans.factory.InitializingBean;
022
023/**
024 * Represents an entry in a {@link DefaultAuthorizationMap} for assigning
025 * different operations (read, write, admin) of user roles to a specific
026 * destination or a hierarchical wildcard area of destinations.
027 *
028 * @org.apache.xbean.XBean element="authorizationEntry"
029 *
030 */
031public class XBeanAuthorizationEntry extends AuthorizationEntry implements InitializingBean {
032
033    @Override
034    public void setAdmin(String roles) throws Exception {
035        adminRoles = roles;
036    }
037
038    @Override
039    public void setRead(String roles) throws Exception {
040        readRoles = roles;
041    }
042
043    @Override
044    public void setWrite(String roles) throws Exception {
045        writeRoles = roles;
046    }
047
048    /**
049     * JSR-250 callback wrapper; converts checked exceptions to runtime exceptions
050     *
051     * delegates to afterPropertiesSet, done to prevent backwards incompatible signature change.
052     */
053    @PostConstruct
054    private void postConstruct() {
055        try {
056            afterPropertiesSet();
057        } catch (Exception ex) {
058            throw new RuntimeException(ex);
059        }
060    }
061
062    /**
063     *
064     * @org.apache.xbean.InitMethod
065     */
066    @Override
067    public void afterPropertiesSet() throws Exception {
068
069        if (adminRoles != null) {
070            setAdminACLs(parseACLs(adminRoles));
071        }
072
073        if (writeRoles != null) {
074            setWriteACLs(parseACLs(writeRoles));
075        }
076
077        if (readRoles != null) {
078            setReadACLs(parseACLs(readRoles));
079        }
080    }
081
082    @Override
083    public String toString() {
084        return "XBeanAuthEntry:" + adminRoles + "," + writeRoles + "," + readRoles;
085    }
086}