1 /* 2 * Copyright (c) 2007, Fraunhofer-Gesellschaft 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * (1) Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the disclaimer at the end. 11 * Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * (2) Neither the name of Fraunhofer nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * DISCLAIMER 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 */ 35 package org.ogf.graap.wsag.security.core.keystore; 36 37 import java.net.URL; 38 import java.net.URLDecoder; 39 40 import javax.security.auth.Subject; 41 import javax.security.auth.login.LoginContext; 42 import javax.security.auth.login.LoginException; 43 44 import org.apache.log4j.Logger; 45 import org.ogf.graap.wsag.api.WsagConstants; 46 import org.ogf.graap.wsag.security.core.KeystoreProperties; 47 import org.ogf.graap.wsag4j.types.configuration.WSRFEngineConfigurationType; 48 49 /** 50 * KeystoreLoginContext 51 * 52 * @author Oliver Waeldrich 53 * 54 */ 55 public class KeystoreLoginContext extends LoginContext 56 { 57 58 private static final Logger LOG = Logger.getLogger( KeystoreLoginContext.class ); 59 60 static 61 { 62 try 63 { 64 URL authconf = KeystoreLoginContext.class.getResource( WsagConstants.WSAG4J_JAAS_CONFIG_FILE ); 65 String p = URLDecoder.decode( authconf.toExternalForm(), "UTF-8" ); 66 System.setProperty( "java.security.auth.login.config", p ); 67 } 68 catch ( Exception e ) 69 { 70 LOG.equals( "Could not read JAAS configuration." ); 71 } 72 } 73 74 /** 75 * Creates a new login context using the specified keystore properties. 76 * 77 * @param properties 78 * the keystore properties to use 79 * 80 * @throws LoginException 81 * failed to login 82 */ 83 public KeystoreLoginContext( KeystoreProperties properties ) 84 throws LoginException 85 { 86 this( new KeystoreCallbackHandler( properties ), new KeystoreConfiguration( properties ) ); 87 } 88 89 /** 90 * Creates a new login context using the specified WSRF engine configuration. 91 * 92 * @param configuration 93 * the WSRF engine configuration to use 94 * 95 * @throws LoginException 96 * failed to login 97 */ 98 public KeystoreLoginContext( WSRFEngineConfigurationType configuration ) 99 throws LoginException 100 { 101 this( new KeystoreProperties( configuration ) ); 102 } 103 104 private KeystoreLoginContext( KeystoreCallbackHandler cbHandler, KeystoreConfiguration configuration ) 105 throws LoginException 106 { 107 super( "KEYSTORE_CLIENT", new Subject(), cbHandler, configuration ); 108 } 109 110 }